diff --git a/tests/Qiniu/Tests/AuthTest.php b/tests/Qiniu/Tests/AuthTest.php index 02b82372..99aec858 100755 --- a/tests/Qiniu/Tests/AuthTest.php +++ b/tests/Qiniu/Tests/AuthTest.php @@ -236,7 +236,7 @@ public function testDisableQiniuTimestampSignatureEnvBeIgnored() $this->assertArrayHasKey("X-Qiniu-Date", $authedHeaders); putenv('DISABLE_QINIU_TIMESTAMP_SIGNATURE'); } - public function testQboxVerifyCallback() + public function testQboxVerifyCallbackShouldOkWithRequiredOptions() { $auth = new Auth('abcdefghklmnopq', '1234567890'); $ok = $auth->verifyCallback( @@ -247,7 +247,22 @@ public function testQboxVerifyCallback() ); $this->assertTrue($ok); } - public function testQiniuVerifyCallback() + public function testQboxVerifyCallbackShouldOkWithOmitOptions() + { + $auth = new Auth('abcdefghklmnopq', '1234567890'); + $ok = $auth->verifyCallback( + 'application/x-www-form-urlencoded', + 'QBox abcdefghklmnopq:T7F-SjxX7X2zI4Fc1vANiNt1AUE=', + 'https://test.qiniu.com/callback', + 'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123', + 'POST', // this should be omit + array( + 'X-Qiniu-Bbb' => 'BBB' + ) // this should be omit + ); + $this->assertTrue($ok); + } + public function testQiniuVerifyCallbackShouldOk() { $auth = new Auth('abcdefghklmnopq', '1234567890'); $ok = $auth->verifyCallback( @@ -262,5 +277,20 @@ public function testQiniuVerifyCallback() ); $this->assertTrue($ok); } + public function testQiniuVerifyCallbackShouldFailed() + { + $auth = new Auth('abcdefghklmnopq', '1234567890'); + $ok = $auth->verifyCallback( + 'application/x-www-form-urlencoded', + 'Qiniu abcdefghklmnopq:ZqS7EZuAKrhZaEIxqNGxDJi41IQ=', + 'https://test.qiniu.com/callback', + 'name=sunflower.jpg&hash=Fn6qeQi4VDLQ347NiRm-RlQx_4O2&location=Shanghai&price=1500.00&uid=123', + 'POST', + array( + 'X-Qiniu-Bbb' => 'BBB' + ) + ); + $this->assertFalse($ok); + } } } diff --git a/tests/Qiniu/Tests/PfopTest.php b/tests/Qiniu/Tests/PfopTest.php index 60edb0eb..66e0d3b4 100755 --- a/tests/Qiniu/Tests/PfopTest.php +++ b/tests/Qiniu/Tests/PfopTest.php @@ -52,7 +52,31 @@ public function testPfopExecuteAndStatusWithMultipleFops() $this->assertNull($error); } - public function testPfopWithIdleTimeType() + public function pfopTypeDataProvider() + { + return array( + array( + 'type' => null + ), + array( + 'type' => -1 + ), + array( + 'type' => 0 + ), + array( + 'type' => 1 + ), + array( + 'type' => 2 + ) + ); + } + + /** + * @dataProvider pfopTypeDataProvider + */ + public function testPfopWithIdleTimeType($testParams) { global $testAuth; @@ -69,17 +93,28 @@ public function testPfopWithIdleTimeType() null, null, false, - 1 + $testParams['type'] ); - $this->assertNull($error); - list($status, $error) = $pfop->status($id); - $this->assertNotNull($status); - $this->assertNull($error); - $this->assertEquals(1, $status['type']); - $this->assertNotEmpty($status['creationDate']); + + if (in_array($testParams['type'], array(null, 0, 1))) { + $this->assertNull($error); + list($status, $error) = $pfop->status($id); + $this->assertNotNull($status); + $this->assertNull($error); + if ($testParams['type'] == 1) { + $this->assertEquals(1, $status['type']); + } + $this->assertNotEmpty($status['creationDate']); + } else { + $this->assertNotNull($error); + } } - public function testPfopByUploadPolicy() + + /** + * @dataProvider pfopTypeDataProvider + */ + public function testPfopByUploadPolicy($testParams) { global $testAuth; $bucket = 'testres'; @@ -87,14 +122,20 @@ public function testPfopByUploadPolicy() $persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1'); $fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry; + $putPolicy = array( + 'persistentOps' => $fops, + 'persistentType' => $testParams['type'] + ); + + if ($testParams['type'] == null) { + unset($putPolicy['persistentType']); + } + $token = $testAuth->uploadToken( $bucket, $key, 3600, - array( - 'persistentOps' => $fops, - 'persistentType' => 1 - ) + $putPolicy ); $upManager = new UploadManager(self::getConfig()); list($ret, $error) = $upManager->putFile( @@ -111,10 +152,17 @@ public function testPfopByUploadPolicy() $pfop = new PersistentFop($testAuth, self::getConfig()); list($status, $error) = $pfop->status($id); - $this->assertNotNull($status); - $this->assertNull($error); - $this->assertEquals(1, $status['type']); - $this->assertNotEmpty($status['creationDate']); + + if (in_array($testParams['type'], array(null, 0, 1))) { + $this->assertNotNull($status); + $this->assertNull($error); + if ($testParams['type'] == 1) { + $this->assertEquals(1, $status['type']); + } + $this->assertNotEmpty($status['creationDate']); + } else { + $this->assertNotNull($error); + } } public function testMkzip()