From a0f24861fef8463aa87e5b08c02c42a0458e1a7e Mon Sep 17 00:00:00 2001 From: Adrian Palmer Date: Wed, 27 Aug 2014 17:45:39 +1000 Subject: [PATCH 1/6] Initial commit --- .gitignore | 2 + .travis.yml | 12 +++++ LICENSE.txt | 22 ++++++++ README.md | 28 ++++++++++ composer.json | 26 +++++++++ .../Guzzle/CreateRequestSubscriber.php | 28 ++++++++++ src/HttpSignatures/Guzzle/Message.php | 30 +++++++++++ src/HttpSignatures/Guzzle/MessageHeaders.php | 28 ++++++++++ tests/GuzzleSignerTest.php | 53 +++++++++++++++++++ tests/bootstrap.php | 3 ++ 10 files changed, 232 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 composer.json create mode 100644 src/HttpSignatures/Guzzle/CreateRequestSubscriber.php create mode 100644 src/HttpSignatures/Guzzle/Message.php create mode 100644 src/HttpSignatures/Guzzle/MessageHeaders.php create mode 100644 tests/GuzzleSignerTest.php create mode 100644 tests/bootstrap.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8153b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/composer.lock +/vendor/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6c322ae --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: php + +php: + - 5.6 + - 5.5 + - 5.4 + - 5.3 + - hhvm + +install: composer install + +script: vendor/bin/phpunit diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..943bbcc --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2014 99designs + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d5c13b1 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +HTTP Signatures Guzzle 3 +=== + +Adds Guzzle 3 support to [99designs/http-signatures][99signatures] + +Signing with Guzzle 3 +--- + +This library includes support for automatically signing Guzzle requests using an event subscriber. + +```php +use HttpSignatures\Guzzle\CreateRequestSubscriber; + +$client = new \Guzzle\Http\Client('http://example.org'); +$client->addSubscriber(new CreateRequestSubscriber($context)); + +// The below will now send a signed request to: http://example.org/path?query=123 +$client->get('/path?query=123', array( + 'Date' => 'Wed, 30 Jul 2014 16:40:19 -0700', + 'Accept' => 'llamas', +))->send(); +``` + +## Contributing + +Pull Requests are welcome. + +[99signatures]: https://github.com/99designs/http-signatures-php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..0908d67 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "99designs/http-signatures-guzzle", + "description": "Sign and verify HTTP messages with Guzzle", + "homepage": "https://github.com/99designs/http-signatures-php", + "keywords": ["http", "https", "signing", "signed", "signature", "hmac", "guzzle"], + "license": "MIT", + "authors": [ + { + "name": "Adrian Palmer", + "email": "adrian.palmer@99designs.com" + } + ], + "autoload": { + "psr-4": { + "HttpSignatures\\": "src/" + } + }, + "require": { + "php": ">=5.3.0", + "99designs/http-signatures": "~1.1", + "guzzle/guzzle": ">=3.9" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + } +} diff --git a/src/HttpSignatures/Guzzle/CreateRequestSubscriber.php b/src/HttpSignatures/Guzzle/CreateRequestSubscriber.php new file mode 100644 index 0000000..d3f50fb --- /dev/null +++ b/src/HttpSignatures/Guzzle/CreateRequestSubscriber.php @@ -0,0 +1,28 @@ +context = $context; + } + + public static function getSubscribedEvents() + { + return array( + 'client.create_request' => 'signRequest' + ); + } + + public function signRequest($e) + { + $this->context->signer()->sign(new Message($e['request'])); + } +} diff --git a/src/HttpSignatures/Guzzle/Message.php b/src/HttpSignatures/Guzzle/Message.php new file mode 100644 index 0000000..5a55452 --- /dev/null +++ b/src/HttpSignatures/Guzzle/Message.php @@ -0,0 +1,30 @@ +request = $request; + $this->headers = new MessageHeaders($request); + } + + public function getQueryString() + { + return $this->request->getQuery(true); + } + + public function getMethod() + { + return $this->request->getMethod(); + } + + public function getPathInfo() + { + return $this->request->getPath(); + } +} diff --git a/src/HttpSignatures/Guzzle/MessageHeaders.php b/src/HttpSignatures/Guzzle/MessageHeaders.php new file mode 100644 index 0000000..4ff22fd --- /dev/null +++ b/src/HttpSignatures/Guzzle/MessageHeaders.php @@ -0,0 +1,28 @@ +request = $request; + } + + public function has($header) + { + return $this->request->hasHeader($header); + } + + public function get($header) + { + return $this->request->getHeader($header); + } + + public function set($header, $value) + { + $this->request->setHeader($header, $value); + } +} diff --git a/tests/GuzzleSignerTest.php b/tests/GuzzleSignerTest.php new file mode 100644 index 0000000..3e7e91b --- /dev/null +++ b/tests/GuzzleSignerTest.php @@ -0,0 +1,53 @@ +context = new Context(array( + 'keys' => array('pda' => 'secret'), + 'algorithm' => 'hmac-sha256', + 'headers' => array('(request-target)', 'date'), + )); + + $this->client = new \Guzzle\Http\Client(); + $this->client->addSubscriber(new CreateRequestSubscriber($this->context)); + } + + public function testGuzzleRequestHasExpectedHeaders() + { + $message = $this->client->get('/path?query=123', array('date' => 'today', 'accept' => 'llamas')); + + $expectedString = implode( + ',', + array( + 'keyId="pda"', + 'algorithm="hmac-sha256"', + 'headers="(request-target) date"', + 'signature="SFlytCGpsqb/9qYaKCQklGDvwgmrwfIERFnwt+yqPJw="', + ) + ); + + $this->assertEquals( + $expectedString, + (string) $message->getHeader('Signature') + ); + + $this->assertEquals( + 'Signature ' . $expectedString, + (string) $message->getHeader('Authorization') + ); + } + + public function testVerifyGuzzleRequest() + { + $message = $this->client->get('/path?query=123', array('date' => 'today', 'accept' => 'dogs')); + $this->assertTrue($this->context->verifier()->isValid(new Message($message))); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..223f5ba --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ + Date: Wed, 27 Aug 2014 17:47:56 +1000 Subject: [PATCH 2/6] Add phpunit.xml.dist --- phpunit.xml.dist | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 phpunit.xml.dist diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..6b8cd5e --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,13 @@ + + + + + tests + + + + + src + + + From e6028d63797fa72649a54165495b428827145d34 Mon Sep 17 00:00:00 2001 From: Adrian Palmer Date: Wed, 27 Aug 2014 18:01:07 +1000 Subject: [PATCH 3/6] Update composer with correct details and version pinning --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 0908d67..6a6cd50 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "99designs/http-signatures-guzzle", "description": "Sign and verify HTTP messages with Guzzle", - "homepage": "https://github.com/99designs/http-signatures-php", + "homepage": "https://github.com/99designs/http-signatures-guzzle", "keywords": ["http", "https", "signing", "signed", "signature", "hmac", "guzzle"], "license": "MIT", "authors": [ @@ -12,13 +12,13 @@ ], "autoload": { "psr-4": { - "HttpSignatures\\": "src/" + "": "src/" } }, "require": { "php": ">=5.3.0", "99designs/http-signatures": "~1.1", - "guzzle/guzzle": ">=3.9" + "guzzle/guzzle": "~3.9" }, "require-dev": { "phpunit/phpunit": "~4.1" From 760d0a7686eca7f4e1dabb3f4737dbe36ea706d2 Mon Sep 17 00:00:00 2001 From: Adrian Palmer Date: Thu, 28 Aug 2014 09:59:31 +1000 Subject: [PATCH 4/6] Update README with better usage example --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index d5c13b1..45d0878 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ HTTP Signatures Guzzle 3 === +[![Build Status](https://travis-ci.org/99designs/http-signatures-guzzle.svg)](https://travis-ci.org/99designs/http-signatures-guzzle) + Adds Guzzle 3 support to [99designs/http-signatures][99signatures] Signing with Guzzle 3 @@ -9,8 +11,15 @@ Signing with Guzzle 3 This library includes support for automatically signing Guzzle requests using an event subscriber. ```php +use HttpSignatures\Context; use HttpSignatures\Guzzle\CreateRequestSubscriber; +$context = new Context(array( + 'keys' => array('examplekey' => 'secret-key-here'), + 'algorithm' => 'hmac-sha256', + 'headers' => array('(request-target)', 'Date', 'Accept'), +)); + $client = new \Guzzle\Http\Client('http://example.org'); $client->addSubscriber(new CreateRequestSubscriber($context)); From 78cccf1a8fe7784b99d1ab0553255af480c10bfe Mon Sep 17 00:00:00 2001 From: Adrian Palmer Date: Thu, 28 Aug 2014 13:02:37 +1000 Subject: [PATCH 5/6] Rename CreateRequestSubscriber to RequestSubscriber --- README.md | 4 ++-- .../{CreateRequestSubscriber.php => RequestSubscriber.php} | 2 +- tests/GuzzleSignerTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/HttpSignatures/Guzzle/{CreateRequestSubscriber.php => RequestSubscriber.php} (88%) diff --git a/README.md b/README.md index 45d0878..84e165c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This library includes support for automatically signing Guzzle requests using an ```php use HttpSignatures\Context; -use HttpSignatures\Guzzle\CreateRequestSubscriber; +use HttpSignatures\Guzzle\RequestSubscriber; $context = new Context(array( 'keys' => array('examplekey' => 'secret-key-here'), @@ -21,7 +21,7 @@ $context = new Context(array( )); $client = new \Guzzle\Http\Client('http://example.org'); -$client->addSubscriber(new CreateRequestSubscriber($context)); +$client->addSubscriber(new RequestSubscriber($context)); // The below will now send a signed request to: http://example.org/path?query=123 $client->get('/path?query=123', array( diff --git a/src/HttpSignatures/Guzzle/CreateRequestSubscriber.php b/src/HttpSignatures/Guzzle/RequestSubscriber.php similarity index 88% rename from src/HttpSignatures/Guzzle/CreateRequestSubscriber.php rename to src/HttpSignatures/Guzzle/RequestSubscriber.php index d3f50fb..bf28ff2 100644 --- a/src/HttpSignatures/Guzzle/CreateRequestSubscriber.php +++ b/src/HttpSignatures/Guzzle/RequestSubscriber.php @@ -5,7 +5,7 @@ namespace HttpSignatures\Guzzle; use Guzzle\Common\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class CreateRequestSubscriber implements EventSubscriberInterface +class RequestSubscriber implements EventSubscriberInterface { private $context; diff --git a/tests/GuzzleSignerTest.php b/tests/GuzzleSignerTest.php index 3e7e91b..6993148 100644 --- a/tests/GuzzleSignerTest.php +++ b/tests/GuzzleSignerTest.php @@ -2,7 +2,7 @@ namespace HttpSignatures\Test; -use HttpSignatures\Guzzle\CreateRequestSubscriber; +use HttpSignatures\Guzzle\RequestSubscriber; use HttpSignatures\Context; use HttpSignatures\Guzzle\Message; @@ -17,7 +17,7 @@ class GuzzleSignerTest extends \PHPUnit_Framework_TestCase )); $this->client = new \Guzzle\Http\Client(); - $this->client->addSubscriber(new CreateRequestSubscriber($this->context)); + $this->client->addSubscriber(new RequestSubscriber($this->context)); } public function testGuzzleRequestHasExpectedHeaders() From a20de9b9bd023ed22fd7040d7873ce795c295bd2 Mon Sep 17 00:00:00 2001 From: Ruben de Vries Date: Mon, 6 Oct 2014 10:21:26 +0200 Subject: [PATCH 6/6] Guzzle4 support --- .travis.yml | 1 - README.md | 17 ++- composer.json | 16 ++- src/HttpSignatures/Guzzle/Message.php | 30 ----- .../Guzzle/RequestSubscriber.php | 28 ----- src/HttpSignatures/GuzzleHttp/Message.php | 47 ++++++++ .../{Guzzle => GuzzleHttp}/MessageHeaders.php | 16 ++- .../GuzzleHttp/RequestSubscriber.php | 37 ++++++ tests/GuzzleHttpSignerTest.php | 109 ++++++++++++++++++ tests/GuzzleSignerTest.php | 53 --------- 10 files changed, 225 insertions(+), 129 deletions(-) delete mode 100644 src/HttpSignatures/Guzzle/Message.php delete mode 100644 src/HttpSignatures/Guzzle/RequestSubscriber.php create mode 100644 src/HttpSignatures/GuzzleHttp/Message.php rename src/HttpSignatures/{Guzzle => GuzzleHttp}/MessageHeaders.php (52%) create mode 100644 src/HttpSignatures/GuzzleHttp/RequestSubscriber.php create mode 100644 tests/GuzzleHttpSignerTest.php delete mode 100644 tests/GuzzleSignerTest.php diff --git a/.travis.yml b/.travis.yml index 6c322ae..5a4f48c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ php: - 5.6 - 5.5 - 5.4 - - 5.3 - hhvm install: composer install diff --git a/README.md b/README.md index 84e165c..733b49f 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,19 @@ -HTTP Signatures Guzzle 3 +HTTP Signatures Guzzle 4 === -[![Build Status](https://travis-ci.org/99designs/http-signatures-guzzle.svg)](https://travis-ci.org/99designs/http-signatures-guzzle) +[![Build Status](https://travis-ci.org/99designs/http-signatures-guzzlehttp.svg)](https://travis-ci.org/99designs/http-signatures-guzzlehttp) -Adds Guzzle 3 support to [99designs/http-signatures][99signatures] +Adds [99designs/http-signatures](http-signatures) support to Guzzle 4. +For Guzzle 3 see the [99designs/http-signatures-guzzle](99designs/http-signatures-guzzle) repo. -Signing with Guzzle 3 +Signing with Guzzle 4 --- This library includes support for automatically signing Guzzle requests using an event subscriber. ```php use HttpSignatures\Context; -use HttpSignatures\Guzzle\RequestSubscriber; +use HttpSignatures\GuzzleHttp\RequestSubscriber; $context = new Context(array( 'keys' => array('examplekey' => 'secret-key-here'), @@ -21,17 +22,15 @@ $context = new Context(array( )); $client = new \Guzzle\Http\Client('http://example.org'); -$client->addSubscriber(new RequestSubscriber($context)); +$client->getEmiter()->attach(new RequestSubscriber($context)); // The below will now send a signed request to: http://example.org/path?query=123 $client->get('/path?query=123', array( 'Date' => 'Wed, 30 Jul 2014 16:40:19 -0700', 'Accept' => 'llamas', -))->send(); +)); ``` ## Contributing Pull Requests are welcome. - -[99signatures]: https://github.com/99designs/http-signatures-php diff --git a/composer.json b/composer.json index 6a6cd50..ff25532 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,17 @@ { - "name": "99designs/http-signatures-guzzle", - "description": "Sign and verify HTTP messages with Guzzle", - "homepage": "https://github.com/99designs/http-signatures-guzzle", - "keywords": ["http", "https", "signing", "signed", "signature", "hmac", "guzzle"], + "name": "99designs/http-signatures-guzzlehttp", + "description": "Sign and verify HTTP messages with Guzzle 4", + "homepage": "https://github.com/99designs/http-signatures-guzzlehttp", + "keywords": ["http", "https", "signing", "signed", "signature", "hmac", "guzzle 4"], "license": "MIT", "authors": [ { "name": "Adrian Palmer", "email": "adrian.palmer@99designs.com" + }, + { + "name": "Ruben de Vries", + "email": "ruben@blocktrail.com" } ], "autoload": { @@ -16,9 +20,9 @@ } }, "require": { - "php": ">=5.3.0", + "php": ">=5.4.0", "99designs/http-signatures": "~1.1", - "guzzle/guzzle": "~3.9" + "guzzlehttp/guzzle": "~4.2" }, "require-dev": { "phpunit/phpunit": "~4.1" diff --git a/src/HttpSignatures/Guzzle/Message.php b/src/HttpSignatures/Guzzle/Message.php deleted file mode 100644 index 5a55452..0000000 --- a/src/HttpSignatures/Guzzle/Message.php +++ /dev/null @@ -1,30 +0,0 @@ -request = $request; - $this->headers = new MessageHeaders($request); - } - - public function getQueryString() - { - return $this->request->getQuery(true); - } - - public function getMethod() - { - return $this->request->getMethod(); - } - - public function getPathInfo() - { - return $this->request->getPath(); - } -} diff --git a/src/HttpSignatures/Guzzle/RequestSubscriber.php b/src/HttpSignatures/Guzzle/RequestSubscriber.php deleted file mode 100644 index bf28ff2..0000000 --- a/src/HttpSignatures/Guzzle/RequestSubscriber.php +++ /dev/null @@ -1,28 +0,0 @@ -context = $context; - } - - public static function getSubscribedEvents() - { - return array( - 'client.create_request' => 'signRequest' - ); - } - - public function signRequest($e) - { - $this->context->signer()->sign(new Message($e['request'])); - } -} diff --git a/src/HttpSignatures/GuzzleHttp/Message.php b/src/HttpSignatures/GuzzleHttp/Message.php new file mode 100644 index 0000000..ed9c4fc --- /dev/null +++ b/src/HttpSignatures/GuzzleHttp/Message.php @@ -0,0 +1,47 @@ +request = $request; + $this->headers = new MessageHeaders($request); + } + + public function getQueryString() + { + $qs = $this->request->getQuery(); + return $qs->count() ? $qs : null; + } + + public function getMethod() + { + return $this->request->getMethod(); + } + + public function getPathInfo() + { + return $this->request->getPath(); + } +} diff --git a/src/HttpSignatures/Guzzle/MessageHeaders.php b/src/HttpSignatures/GuzzleHttp/MessageHeaders.php similarity index 52% rename from src/HttpSignatures/Guzzle/MessageHeaders.php rename to src/HttpSignatures/GuzzleHttp/MessageHeaders.php index 4ff22fd..c1f2547 100644 --- a/src/HttpSignatures/Guzzle/MessageHeaders.php +++ b/src/HttpSignatures/GuzzleHttp/MessageHeaders.php @@ -1,12 +1,24 @@ request = $request; } diff --git a/src/HttpSignatures/GuzzleHttp/RequestSubscriber.php b/src/HttpSignatures/GuzzleHttp/RequestSubscriber.php new file mode 100644 index 0000000..6edaea3 --- /dev/null +++ b/src/HttpSignatures/GuzzleHttp/RequestSubscriber.php @@ -0,0 +1,37 @@ +context = $context; + } + + public function getEvents() + { + return ['before' => ['onBefore', RequestEvents::SIGN_REQUEST]]; + } + + public function onBefore(BeforeEvent $event) + { + $request = $event->getRequest(); + + if ($request->getConfig()['auth'] != 'http-signatures') { + return; + } + + $this->context->signer()->sign(new Message($request)); + } +} diff --git a/tests/GuzzleHttpSignerTest.php b/tests/GuzzleHttpSignerTest.php new file mode 100644 index 0000000..47da96d --- /dev/null +++ b/tests/GuzzleHttpSignerTest.php @@ -0,0 +1,109 @@ +context = new Context(array( + 'keys' => array('pda' => 'secret'), + 'algorithm' => 'hmac-sha256', + 'headers' => array('(request-target)', 'date'), + )); + + $this->client = new \GuzzleHttp\Client([ + 'auth' => 'http-signatures' + ]); + $this->client->getEmitter()->attach(new RequestSubscriber($this->context)); + } + + /** + * test signing a message + */ + public function testGuzzleRequestHasExpectedHeaders() + { + $message = $this->client->createRequest('GET', '/path?query=123', array( + 'headers' => array('date' => 'today', 'accept' => 'llamas') + )); + + $this->context->signer()->sign(new Message($message)); + + $expectedString = implode( + ',', + array( + 'keyId="pda"', + 'algorithm="hmac-sha256"', + 'headers="(request-target) date"', + 'signature="SFlytCGpsqb/9qYaKCQklGDvwgmrwfIERFnwt+yqPJw="', + ) + ); + + $this->assertEquals( + $expectedString, + (string) $message->getHeader('Signature') + ); + + $this->assertEquals( + 'Signature ' . $expectedString, + (string) $message->getHeader('Authorization') + ); + } + + /** + * test signing a message with a URL that doesn't contain a ?query + */ + public function testGuzzleRequestHasExpectedHeaders2() + { + $message = $this->client->createRequest('GET', '/path', array( + 'headers' => array('date' => 'today', 'accept' => 'llamas') + )); + + $this->context->signer()->sign(new Message($message)); + + $expectedString = implode( + ',', + array( + 'keyId="pda"', + 'algorithm="hmac-sha256"', + 'headers="(request-target) date"', + 'signature="DAtF133khP05pS5Gh8f+zF/UF7mVUojMj7iJZO3Xk4o="', + ) + ); + + $this->assertEquals( + $expectedString, + (string) $message->getHeader('Signature') + ); + + $this->assertEquals( + 'Signature ' . $expectedString, + (string) $message->getHeader('Authorization') + ); + } + + public function testVerifyGuzzleRequest() + { + $message = $this->client->createRequest('GET', '/path?query=123', array( + 'headers' => array('date' => 'today', 'accept' => 'dogs') + )); + + $this->context->signer()->sign(new Message($message)); + + $this->assertTrue($this->context->verifier()->isValid(new Message($message))); + } +} diff --git a/tests/GuzzleSignerTest.php b/tests/GuzzleSignerTest.php deleted file mode 100644 index 6993148..0000000 --- a/tests/GuzzleSignerTest.php +++ /dev/null @@ -1,53 +0,0 @@ -context = new Context(array( - 'keys' => array('pda' => 'secret'), - 'algorithm' => 'hmac-sha256', - 'headers' => array('(request-target)', 'date'), - )); - - $this->client = new \Guzzle\Http\Client(); - $this->client->addSubscriber(new RequestSubscriber($this->context)); - } - - public function testGuzzleRequestHasExpectedHeaders() - { - $message = $this->client->get('/path?query=123', array('date' => 'today', 'accept' => 'llamas')); - - $expectedString = implode( - ',', - array( - 'keyId="pda"', - 'algorithm="hmac-sha256"', - 'headers="(request-target) date"', - 'signature="SFlytCGpsqb/9qYaKCQklGDvwgmrwfIERFnwt+yqPJw="', - ) - ); - - $this->assertEquals( - $expectedString, - (string) $message->getHeader('Signature') - ); - - $this->assertEquals( - 'Signature ' . $expectedString, - (string) $message->getHeader('Authorization') - ); - } - - public function testVerifyGuzzleRequest() - { - $message = $this->client->get('/path?query=123', array('date' => 'today', 'accept' => 'dogs')); - $this->assertTrue($this->context->verifier()->isValid(new Message($message))); - } -}