From 5242f6709f02e6d1cc6b8fb563b25c5c0f901e89 Mon Sep 17 00:00:00 2001 From: jeremykendall Date: Wed, 7 Jan 2015 09:03:50 -0500 Subject: [PATCH 1/2] Updates README --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5fa9df9..024f9b5 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,12 @@ tasks for you. ## Sample Implementation -A [sample implementation of the Query Auth library](https://github.com/jeremykendall/query-auth-impl) +A [sample implementation of the Query Auth library](https://github.com/jeremykendall/query-auth-impl) is available in order to better demonstrate how one might employ the library. ## Usage -There are three components to this library: +There are three components to this library: * Request signing * Request validation @@ -31,7 +31,7 @@ Request signing and validation are made possible by the use of request adapters. ### Request Adapters -Query Auth request adapters wrap outgoing and incoming requests and adapt them to the +Query Auth request adapters wrap outgoing and incoming requests and adapt them to the request interface that Query Auth expects. #### Outgoing @@ -164,6 +164,14 @@ $secret = $keyGenerator->generateSecret(); Both key and secret are generated using Anthony Ferrara's [RandomLib](https://github.com/ircmaxell/RandomLib) random string generator. +## Versions Less Than 3.0+ Deprecated, Not Obsolete + +While I'd advise upgrading to v3 as soon as possible, a happy side effect of refactoring +the API without changing the signature creation and validation logic is that +Query Auth 3.0+ is compatible with prior versions of Query Auth. This means that you'll +be able to upgrade Query Auth on the server-side (validation) without needing +to immediately upgrade all client-side (creation) applications. BONUS! + ## Installation Package installation is handled by Composer. From f082cfa722b53b61578798301477c0eea6e426e1 Mon Sep 17 00:00:00 2001 From: jeremykendall Date: Sun, 28 Jun 2015 17:30:12 -0500 Subject: [PATCH 2/2] Fixes #20 --- src/QueryAuth/Request/RequestSigner.php | 2 +- tests/QueryAuth/Request/RequestSignerTest.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/QueryAuth/Request/RequestSigner.php b/src/QueryAuth/Request/RequestSigner.php index a4413b7..9b06821 100644 --- a/src/QueryAuth/Request/RequestSigner.php +++ b/src/QueryAuth/Request/RequestSigner.php @@ -117,7 +117,7 @@ public function setKeyGenerator(KeyGenerator $keyGenerator) public function getTimestamp() { if ($this->timestamp === null) { - $this->timestamp = (int) gmdate('U'); + return (int) gmdate('U'); } return $this->timestamp; diff --git a/tests/QueryAuth/Request/RequestSignerTest.php b/tests/QueryAuth/Request/RequestSignerTest.php index 703a392..ada1966 100644 --- a/tests/QueryAuth/Request/RequestSignerTest.php +++ b/tests/QueryAuth/Request/RequestSignerTest.php @@ -92,4 +92,31 @@ public function testGetSetTimestamp() $this->requestSigner->setTimestamp($new); $this->assertEquals($new, $this->requestSigner->getTimestamp()); } + + /** + * @group 20 + * + * Issue #20 RequestSigner::getTimestamp() will return the wrong timestamp value in some situations + * @see https://github.com/jeremykendall/query-auth/issues/20 + */ + public function testGetTimestampReturnsCorrectTimestampOverMultipleCalls() + { + $gmdateTimestamp = (int) gmdate('U'); + $requestSignerTimestamp1 = $this->requestSigner->getTimestamp(); + + $this->assertEquals( + $gmdateTimestamp, + $requestSignerTimestamp1, + 'Timestamps differ by more than 1 second', + $delta = 1 + ); + + // Sleep for two seconds to ensure timestamp changes + sleep(2); + + $requestSignerTimestamp2 = $this->requestSigner->getTimestamp(); + // Because $requestSignerTimestamp2 should be > $requestSignerTimestamp1 + // by at least 1 second + $this->assertGreaterThan($requestSignerTimestamp1, $requestSignerTimestamp2); + } }