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 0e0005b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 19 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);
}
}
}
81 changes: 64 additions & 17 deletions tests/Qiniu/Tests/PfopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,30 @@ 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;

Expand All @@ -69,32 +92,49 @@ 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 ($testPrams['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';
$key = 'sintel_trailer.mp4';
$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(
Expand All @@ -111,10 +151,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()
Expand Down

0 comments on commit 0e0005b

Please sign in to comment.