From e1d1e35e32688cb85492d1b1cc4ce45a2b4ba240 Mon Sep 17 00:00:00 2001 From: rwifeng Date: Wed, 17 Jul 2013 10:19:41 +0800 Subject: [PATCH 1/2] callback verify --- qiniu/auth_digest.php | 19 +++++++++++++++++++ tests/AuthDigestTest.php | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/qiniu/auth_digest.php b/qiniu/auth_digest.php index ae78dc4a..7245e14b 100644 --- a/qiniu/auth_digest.php +++ b/qiniu/auth_digest.php @@ -46,6 +46,25 @@ 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); From 422f8961cadcbb4b15cd7762dd42617915b54c58 Mon Sep 17 00:00:00 2001 From: rwifeng Date: Wed, 17 Jul 2013 10:23:48 +0800 Subject: [PATCH 2/2] fix --- qiniu/auth_digest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qiniu/auth_digest.php b/qiniu/auth_digest.php index 7245e14b..907acdbd 100644 --- a/qiniu/auth_digest.php +++ b/qiniu/auth_digest.php @@ -47,11 +47,9 @@ public function SignRequest($req, $incbody) // => ($token, $error) return $this->Sign($data); } - public function VerifyCallback($auth, $url, $body) // ==> bool + public function VerifyCallback($auth, $url, $body) // ==> bool { - $url = parse_url($url); - $data = ''; if (isset($url['path'])) { $data = $url['path'];