Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions qiniu/auth_digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ public function SignRequest($req, $incbody) // => ($token, $error)
}
return $this->Sign($data);
}

public function VerifyCallback($auth, $url, $body) // ==> bool
{
$url = parse_url($url);
$data = '';
if (isset($url['path'])) {
$data = $url['path'];
}
if (isset($url['query'])) {
$data .= '?' . $url['query'];
}
$data .= "\n";

$data .= $body;
$token = 'QBox ' . $this->Sign($data);
return $auth === $token;
}
}

function Qiniu_SetKeys($accessKey, $secretKey)
Expand Down
12 changes: 12 additions & 0 deletions tests/AuthDigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class AuthDigestTest extends PHPUnit_Framework_TestCase
{

public function testEncode()
{
$cases = array(
Expand All @@ -16,6 +17,17 @@ public function testEncode()
}
}

public function testVerifyCallback()
{
initKeys();
$mac1 = Qiniu_RequireMac(null);
$auth = 'QBox Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ:JrRyg9So6DNrNDY5qj1sygt0SmQ=';
$url = 'http://rs.qbox.me/batch';
$body = 'op=/delete/cGhwc2RrOnRlc3RPcDI=&op=/delete/cGhwc2RrOnRlc3RPcDM=&op=/delete/cGhwc2RrOnRlc3RPcDQ=';
$pass = $mac1->VerifyCallback($auth, $url, $body);
$this->assertTrue($pass);
}

/* public function testSetKeys()
{
$mac1 = Qiniu_RequireMac(null);
Expand Down