Skip to content

Commit

Permalink
Merge branch 'develop', fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykendall committed Jun 28, 2015
2 parents d0cd49d + b8aca94 commit 4a2eb27
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/QueryAuth/Request/RequestSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions tests/QueryAuth/Request/RequestSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 4a2eb27

Please sign in to comment.