Skip to content

Commit 5792c27

Browse files
committed
test: add more cases for VerifyCallback and persistent type of pfop
1 parent 1d70c2e commit 5792c27

File tree

2 files changed

+126
-44
lines changed

2 files changed

+126
-44
lines changed

tests/Qiniu/Tests/AuthTest.php

+32-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function testDisableQiniuTimestampSignatureEnvBeIgnored()
236236
$this->assertArrayHasKey("X-Qiniu-Date", $authedHeaders);
237237
putenv('DISABLE_QINIU_TIMESTAMP_SIGNATURE');
238238
}
239-
public function testQboxVerifyCallback()
239+
public function testQboxVerifyCallbackShouldOkWithRequiredOptions()
240240
{
241241
$auth = new Auth('abcdefghklmnopq', '1234567890');
242242
$ok = $auth->verifyCallback(
@@ -247,7 +247,22 @@ public function testQboxVerifyCallback()
247247
);
248248
$this->assertTrue($ok);
249249
}
250-
public function testQiniuVerifyCallback()
250+
public function testQboxVerifyCallbackShouldOkWithOmitOptions()
251+
{
252+
$auth = new Auth('abcdefghklmnopq', '1234567890');
253+
$ok = $auth->verifyCallback(
254+
'application/x-www-form-urlencoded',
255+
'QBox abcdefghklmnopq:T7F-SjxX7X2zI4Fc1vANiNt1AUE=',
256+
'https://test.qiniu.com/callback',
257+
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123',
258+
'POST', // this should be omit
259+
array(
260+
'X-Qiniu-Bbb' => 'BBB'
261+
) // this should be omit
262+
);
263+
$this->assertTrue($ok);
264+
}
265+
public function testQiniuVerifyCallbackShouldOk()
251266
{
252267
$auth = new Auth('abcdefghklmnopq', '1234567890');
253268
$ok = $auth->verifyCallback(
@@ -262,5 +277,20 @@ public function testQiniuVerifyCallback()
262277
);
263278
$this->assertTrue($ok);
264279
}
280+
public function testQiniuVerifyCallbackShouldFailed()
281+
{
282+
$auth = new Auth('abcdefghklmnopq', '1234567890');
283+
$ok = $auth->verifyCallback(
284+
'application/x-www-form-urlencoded',
285+
'Qiniu abcdefghklmnopq:ZqS7EZuAKrhZaEIxqNGxDJi41IQ=',
286+
'https://test.qiniu.com/callback',
287+
'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123',
288+
'POST',
289+
array(
290+
'X-Qiniu-Bbb' => 'BBB'
291+
)
292+
);
293+
$this->assertFalse($ok);
294+
}
265295
}
266296
}

tests/Qiniu/Tests/PfopTest.php

+94-42
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ public function testPfopExecuteAndStatusWithMultipleFops()
5252
$this->assertNull($error);
5353
}
5454

55+
private function pfopTypeTestData()
56+
{
57+
return array(
58+
array(
59+
'type' => null
60+
),
61+
array(
62+
'type' => -1
63+
),
64+
array(
65+
'type' => 0
66+
),
67+
array(
68+
'type' => 1
69+
),
70+
array(
71+
'type' => 2
72+
)
73+
);
74+
}
75+
5576
public function testPfopWithIdleTimeType()
5677
{
5778
global $testAuth;
@@ -62,23 +83,35 @@ public function testPfopWithIdleTimeType()
6283
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
6384
$pfop = new PersistentFop($testAuth, self::getConfig());
6485

65-
list($id, $error) = $pfop->execute(
66-
$bucket,
67-
$key,
68-
$fops,
69-
null,
70-
null,
71-
false,
72-
1
73-
);
74-
$this->assertNull($error);
75-
list($status, $error) = $pfop->status($id);
76-
$this->assertNotNull($status);
77-
$this->assertNull($error);
78-
$this->assertEquals(1, $status['type']);
79-
$this->assertNotEmpty($status['creationDate']);
86+
$testCases = $this->pfopTypeTestData();
87+
88+
foreach ($testCases as $testCase) {
89+
list($id, $error) = $pfop->execute(
90+
$bucket,
91+
$key,
92+
$fops,
93+
null,
94+
null,
95+
false,
96+
$testCase['type']
97+
);
98+
99+
if (in_array($testCase['type'], array(null, 0, 1))) {
100+
$this->assertNull($error);
101+
list($status, $error) = $pfop->status($id);
102+
$this->assertNotNull($status);
103+
$this->assertNull($error);
104+
if ($testPrams['type'] == 1) {
105+
$this->assertEquals(1, $status['type']);
106+
}
107+
$this->assertNotEmpty($status['creationDate']);
108+
} else {
109+
$this->assertNotNull($error);
110+
}
111+
}
80112
}
81113

114+
82115
public function testPfopByUploadPolicy()
83116
{
84117
global $testAuth;
@@ -87,34 +120,53 @@ public function testPfopByUploadPolicy()
87120
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
88121
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
89122

90-
$token = $testAuth->uploadToken(
91-
$bucket,
92-
$key,
93-
3600,
94-
array(
95-
'persistentOps' => $fops,
96-
'persistentType' => 1
97-
)
98-
);
99-
$upManager = new UploadManager(self::getConfig());
100-
list($ret, $error) = $upManager->putFile(
101-
$token,
102-
$key,
103-
__file__,
104-
null,
105-
'text/plain',
106-
true
107-
);
108-
$this->assertNull($error);
109-
$this->assertNotEmpty($ret['persistentId']);
110-
$id = $ret['persistentId'];
123+
$testCases = $this->pfopTypeTestData();
111124

112-
$pfop = new PersistentFop($testAuth, self::getConfig());
113-
list($status, $error) = $pfop->status($id);
114-
$this->assertNotNull($status);
115-
$this->assertNull($error);
116-
$this->assertEquals(1, $status['type']);
117-
$this->assertNotEmpty($status['creationDate']);
125+
foreach ($testCases as $testCase) {
126+
$putPolicy = array(
127+
'persistentOps' => $fops,
128+
'persistentType' => $testCase['type']
129+
);
130+
131+
if ($testCase['type'] == null) {
132+
unset($putPolicy['persistentType']);
133+
}
134+
135+
$token = $testAuth->uploadToken(
136+
$bucket,
137+
$key,
138+
3600,
139+
$putPolicy
140+
);
141+
$upManager = new UploadManager(self::getConfig());
142+
list($ret, $error) = $upManager->putFile(
143+
$token,
144+
$key,
145+
__file__,
146+
null,
147+
'text/plain',
148+
true
149+
);
150+
151+
if (in_array($testCase['type'], array(null, 0, 1))) {
152+
$this->assertNull($error);
153+
$this->assertNotEmpty($ret['persistentId']);
154+
$id = $ret['persistentId'];
155+
} else {
156+
$this->assertNotNull($error);
157+
return;
158+
}
159+
160+
$pfop = new PersistentFop($testAuth, self::getConfig());
161+
list($status, $error) = $pfop->status($id);
162+
163+
$this->assertNotNull($status);
164+
$this->assertNull($error);
165+
if ($testCase['type'] == 1) {
166+
$this->assertEquals(1, $status['type']);
167+
}
168+
$this->assertNotEmpty($status['creationDate']);
169+
}
118170
}
119171

120172
public function testMkzip()

0 commit comments

Comments
 (0)