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..e0028f47 100755 --- a/tests/Qiniu/Tests/PfopTest.php +++ b/tests/Qiniu/Tests/PfopTest.php @@ -52,6 +52,27 @@ public function testPfopExecuteAndStatusWithMultipleFops() $this->assertNull($error); } + private function pfopTypeTestData() + { + return array( + array( + 'type' => null + ), + array( + 'type' => -1 + ), + array( + 'type' => 0 + ), + array( + 'type' => 1 + ), + array( + 'type' => 2 + ) + ); + } + public function testPfopWithIdleTimeType() { global $testAuth; @@ -62,23 +83,35 @@ public function testPfopWithIdleTimeType() $fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry; $pfop = new PersistentFop($testAuth, self::getConfig()); - list($id, $error) = $pfop->execute( - $bucket, - $key, - $fops, - null, - null, - false, - 1 - ); - $this->assertNull($error); - list($status, $error) = $pfop->status($id); - $this->assertNotNull($status); - $this->assertNull($error); - $this->assertEquals(1, $status['type']); - $this->assertNotEmpty($status['creationDate']); + $testCases = $this->pfopTypeTestData(); + + foreach ($testCases as $testCase) { + list($id, $error) = $pfop->execute( + $bucket, + $key, + $fops, + null, + null, + false, + $testCase['type'] + ); + + if (in_array($testCase['type'], array(null, 0, 1))) { + $this->assertNull($error); + list($status, $error) = $pfop->status($id); + $this->assertNotNull($status); + $this->assertNull($error); + if ($testPrams['type'] == 1) { + $this->assertEquals(1, $status['type']); + } + $this->assertNotEmpty($status['creationDate']); + } else { + $this->assertNotNull($error); + } + } } + public function testPfopByUploadPolicy() { global $testAuth; @@ -87,34 +120,53 @@ public function testPfopByUploadPolicy() $persistentEntry = \Qiniu\entry($bucket, 'test-pfop-type_1'); $fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/' . $persistentEntry; - $token = $testAuth->uploadToken( - $bucket, - $key, - 3600, - array( - 'persistentOps' => $fops, - 'persistentType' => 1 - ) - ); - $upManager = new UploadManager(self::getConfig()); - list($ret, $error) = $upManager->putFile( - $token, - $key, - __file__, - null, - 'text/plain', - true - ); - $this->assertNull($error); - $this->assertNotEmpty($ret['persistentId']); - $id = $ret['persistentId']; + $testCases = $this->pfopTypeTestData(); - $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']); + foreach ($testCases as $testCase) { + $putPolicy = array( + 'persistentOps' => $fops, + 'persistentType' => $testCase['type'] + ); + + if ($testCase['type'] == null) { + unset($putPolicy['persistentType']); + } + + $token = $testAuth->uploadToken( + $bucket, + $key, + 3600, + $putPolicy + ); + $upManager = new UploadManager(self::getConfig()); + list($ret, $error) = $upManager->putFile( + $token, + $key, + __file__, + null, + 'text/plain', + true + ); + + if (in_array($testCase['type'], array(null, 0, 1))) { + $this->assertNull($error); + $this->assertNotEmpty($ret['persistentId']); + $id = $ret['persistentId']; + } else { + $this->assertNotNull($error); + return; + } + + $pfop = new PersistentFop($testAuth, self::getConfig()); + list($status, $error) = $pfop->status($id); + + $this->assertNotNull($status); + $this->assertNull($error); + if ($testCase['type'] == 1) { + $this->assertEquals(1, $status['type']); + } + $this->assertNotEmpty($status['creationDate']); + } } public function testMkzip()