diff --git a/qiniu/auth_digest.php b/qiniu/auth_digest.php index ae78dc4a..907acdbd 100644 --- a/qiniu/auth_digest.php +++ b/qiniu/auth_digest.php @@ -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) diff --git a/tests/AuthDigestTest.php b/tests/AuthDigestTest.php index 07cc7a80..e8486f7b 100644 --- a/tests/AuthDigestTest.php +++ b/tests/AuthDigestTest.php @@ -4,6 +4,7 @@ class AuthDigestTest extends PHPUnit_Framework_TestCase { + public function testEncode() { $cases = array( @@ -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);