Skip to content

Commit 0e0005b

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

File tree

2 files changed

+96
-19
lines changed

2 files changed

+96
-19
lines changed

tests/Qiniu/Tests/AuthTest.php

Lines changed: 32 additions & 2 deletions
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

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,30 @@ public function testPfopExecuteAndStatusWithMultipleFops()
5252
$this->assertNull($error);
5353
}
5454

55-
public function testPfopWithIdleTimeType()
55+
public function pfopTypeDataProvider() {
56+
return array(
57+
array(
58+
'type' => null
59+
),
60+
array(
61+
'type' => -1
62+
),
63+
array(
64+
'type' => 0
65+
),
66+
array(
67+
'type' => 1
68+
),
69+
array(
70+
'type' => 2
71+
)
72+
);
73+
}
74+
75+
/**
76+
* @dataProvider pfopTypeDataProvider
77+
*/
78+
public function testPfopWithIdleTimeType($testParams)
5679
{
5780
global $testAuth;
5881

@@ -69,32 +92,49 @@ public function testPfopWithIdleTimeType()
6992
null,
7093
null,
7194
false,
72-
1
95+
$testParams['type']
7396
);
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']);
97+
98+
if (in_array($testParams['type'], array(null, 0, 1))) {
99+
$this->assertNull($error);
100+
list($status, $error) = $pfop->status($id);
101+
$this->assertNotNull($status);
102+
$this->assertNull($error);
103+
if ($testPrams['type'] == 1) {
104+
$this->assertEquals(1, $status['type']);
105+
}
106+
$this->assertNotEmpty($status['creationDate']);
107+
} else {
108+
$this->assertNotNull($error);
109+
}
80110
}
81111

82-
public function testPfopByUploadPolicy()
112+
113+
/**
114+
* @dataProvider pfopTypeDataProvider
115+
*/
116+
public function testPfopByUploadPolicy($testParams)
83117
{
84118
global $testAuth;
85119
$bucket = 'testres';
86120
$key = 'sintel_trailer.mp4';
87121
$persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1');
88122
$fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry;
89123

124+
$putPolicy = array(
125+
'persistentOps' => $fops,
126+
'persistentType' => $testParams['type']
127+
);
128+
129+
if ($testParams['type'] == null) {
130+
unset($putPolicy['persistentType']);
131+
}
132+
90133
$token = $testAuth->uploadToken(
91134
$bucket,
92135
$key,
93136
3600,
94-
array(
95-
'persistentOps' => $fops,
96-
'persistentType' => 1
97-
)
137+
$putPolicy
98138
);
99139
$upManager = new UploadManager(self::getConfig());
100140
list($ret, $error) = $upManager->putFile(
@@ -111,10 +151,17 @@ public function testPfopByUploadPolicy()
111151

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

120167
public function testMkzip()

0 commit comments

Comments
 (0)