Skip to content

Commit

Permalink
Merge pull request #47 from firebase/rd-improve-test-isolation
Browse files Browse the repository at this point in the history
Reset clock skew / leeway after relevant tests & update README
  • Loading branch information
Chris Raynor committed May 20, 2015
2 parents 7a15d3c + ee031fb commit 08a5a47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ $decoded_array = (array) $decoded;

/**
* You can add a leeway to account for when there is a clock skew times between
* the signing and verifying servers. It is recomended this leeway should not
* be bigger than a few minutes.
* the signing and verifying servers. It is recommended that this leeway should
* not be bigger than a few minutes.
*
* Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
*/

JWT::$leeway = 60;
JWT::$leeway = 60; // $leeway in seconds
$decoded = JWT::decode($jwt, $key, array('HS256'));

?>
Expand Down
6 changes: 6 additions & 0 deletions tests/JWTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function testValidTokenWithLeeway()
$encoded = JWT::encode($payload, 'my_key');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
$this->assertEquals($decoded->message, 'abc');
JWT::$leeway = 0;
}

public function testExpiredTokenWithLeeway()
Expand All @@ -96,6 +97,7 @@ public function testExpiredTokenWithLeeway()
$encoded = JWT::encode($payload, 'my_key');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
$this->assertEquals($decoded->message, 'abc');
JWT::$leeway = 0;
}

public function testValidTokenWithList()
Expand Down Expand Up @@ -129,6 +131,7 @@ public function testValidTokenWithNbfLeeway()
$encoded = JWT::encode($payload, 'my_key');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
$this->assertEquals($decoded->message, 'abc');
JWT::$leeway = 0;
}

public function testInvalidTokenWithNbfLeeway()
Expand All @@ -140,6 +143,7 @@ public function testInvalidTokenWithNbfLeeway()
$encoded = JWT::encode($payload, 'my_key');
$this->setExpectedException('BeforeValidException');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
JWT::$leeway = 0;
}

public function testValidTokenWithIatLeeway()
Expand All @@ -151,6 +155,7 @@ public function testValidTokenWithIatLeeway()
$encoded = JWT::encode($payload, 'my_key');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
$this->assertEquals($decoded->message, 'abc');
JWT::$leeway = 0;
}

public function testInvalidTokenWithIatLeeway()
Expand All @@ -162,6 +167,7 @@ public function testInvalidTokenWithIatLeeway()
$encoded = JWT::encode($payload, 'my_key');
$this->setExpectedException('BeforeValidException');
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
JWT::$leeway = 0;
}

public function testInvalidToken()
Expand Down

0 comments on commit 08a5a47

Please sign in to comment.