Skip to content

Commit

Permalink
test: add more cases for VerifyCallback and persistent type of pfop
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Sep 18, 2024
1 parent 1d70c2e commit c418dfa
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 44 deletions.
34 changes: 32 additions & 2 deletions tests/Qiniu/Tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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);
}
}
}
136 changes: 94 additions & 42 deletions tests/Qiniu/Tests/PfopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ($testCase['type'] == 1) {
$this->assertEquals(1, $status['type']);
}
$this->assertNotEmpty($status['creationDate']);
} else {
$this->assertNotNull($error);
}
}
}


public function testPfopByUploadPolicy()
{
global $testAuth;
Expand All @@ -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()
Expand Down

0 comments on commit c418dfa

Please sign in to comment.