Skip to content

Commit 5e31bc0

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

File tree

2 files changed

+97
-19
lines changed

2 files changed

+97
-19
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

+65-17
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,31 @@ public function testPfopExecuteAndStatusWithMultipleFops()
5252
$this->assertNull($error);
5353
}
5454

55-
public function testPfopWithIdleTimeType()
55+
public function pfopTypeDataProvider()
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+
76+
/**
77+
* @dataProvider pfopTypeDataProvider
78+
*/
79+
public function testPfopWithIdleTimeType($testParams)
5680
{
5781
global $testAuth;
5882

@@ -69,32 +93,49 @@ public function testPfopWithIdleTimeType()
6993
null,
7094
null,
7195
false,
72-
1
96+
$testParams['type']
7397
);
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']);
98+
99+
if (in_array($testParams['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 ($testParams['type'] == 1) {
105+
$this->assertEquals(1, $status['type']);
106+
}
107+
$this->assertNotEmpty($status['creationDate']);
108+
} else {
109+
$this->assertNotNull($error);
110+
}
80111
}
81112

82-
public function testPfopByUploadPolicy()
113+
114+
/**
115+
* @dataProvider pfopTypeDataProvider
116+
*/
117+
public function testPfopByUploadPolicy($testParams)
83118
{
84119
global $testAuth;
85120
$bucket = 'testres';
86121
$key = 'sintel_trailer.mp4';
87122
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
88123
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
89124

125+
$putPolicy = array(
126+
'persistentOps' => $fops,
127+
'persistentType' => $testParams['type']
128+
);
129+
130+
if ($testParams['type'] == null) {
131+
unset($putPolicy['persistentType']);
132+
}
133+
90134
$token = $testAuth->uploadToken(
91135
$bucket,
92136
$key,
93137
3600,
94-
array(
95-
'persistentOps' => $fops,
96-
'persistentType' => 1
97-
)
138+
$putPolicy
98139
);
99140
$upManager = new UploadManager(self::getConfig());
100141
list($ret, $error) = $upManager->putFile(
@@ -111,10 +152,17 @@ public function testPfopByUploadPolicy()
111152

112153
$pfop = new PersistentFop($testAuth, self::getConfig());
113154
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']);
155+
156+
if (in_array($testParams['type'], array(null, 0, 1))) {
157+
$this->assertNotNull($status);
158+
$this->assertNull($error);
159+
if ($testParams['type'] == 1) {
160+
$this->assertEquals(1, $status['type']);
161+
}
162+
$this->assertNotEmpty($status['creationDate']);
163+
} else {
164+
$this->assertNotNull($error);
165+
}
118166
}
119167

120168
public function testMkzip()

0 commit comments

Comments
 (0)