Skip to content

Commit 08a5a47

Browse files
author
Chris Raynor
committed
Merge pull request firebase#47 from firebase/rd-improve-test-isolation
Reset clock skew / leeway after relevant tests & update README
2 parents 7a15d3c + ee031fb commit 08a5a47

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ $decoded_array = (array) $decoded;
4747

4848
/**
4949
* You can add a leeway to account for when there is a clock skew times between
50-
* the signing and verifying servers. It is recomended this leeway should not
51-
* be bigger than a few minutes.
50+
* the signing and verifying servers. It is recommended that this leeway should
51+
* not be bigger than a few minutes.
52+
*
5253
* Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef
5354
*/
54-
55-
JWT::$leeway = 60;
55+
JWT::$leeway = 60; // $leeway in seconds
5656
$decoded = JWT::decode($jwt, $key, array('HS256'));
5757

5858
?>

tests/JWTTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function testValidTokenWithLeeway()
8484
$encoded = JWT::encode($payload, 'my_key');
8585
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
8686
$this->assertEquals($decoded->message, 'abc');
87+
JWT::$leeway = 0;
8788
}
8889

8990
public function testExpiredTokenWithLeeway()
@@ -96,6 +97,7 @@ public function testExpiredTokenWithLeeway()
9697
$encoded = JWT::encode($payload, 'my_key');
9798
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
9899
$this->assertEquals($decoded->message, 'abc');
100+
JWT::$leeway = 0;
99101
}
100102

101103
public function testValidTokenWithList()
@@ -129,6 +131,7 @@ public function testValidTokenWithNbfLeeway()
129131
$encoded = JWT::encode($payload, 'my_key');
130132
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
131133
$this->assertEquals($decoded->message, 'abc');
134+
JWT::$leeway = 0;
132135
}
133136

134137
public function testInvalidTokenWithNbfLeeway()
@@ -140,6 +143,7 @@ public function testInvalidTokenWithNbfLeeway()
140143
$encoded = JWT::encode($payload, 'my_key');
141144
$this->setExpectedException('BeforeValidException');
142145
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
146+
JWT::$leeway = 0;
143147
}
144148

145149
public function testValidTokenWithIatLeeway()
@@ -151,6 +155,7 @@ public function testValidTokenWithIatLeeway()
151155
$encoded = JWT::encode($payload, 'my_key');
152156
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
153157
$this->assertEquals($decoded->message, 'abc');
158+
JWT::$leeway = 0;
154159
}
155160

156161
public function testInvalidTokenWithIatLeeway()
@@ -162,6 +167,7 @@ public function testInvalidTokenWithIatLeeway()
162167
$encoded = JWT::encode($payload, 'my_key');
163168
$this->setExpectedException('BeforeValidException');
164169
$decoded = JWT::decode($encoded, 'my_key', array('HS256'));
170+
JWT::$leeway = 0;
165171
}
166172

167173
public function testInvalidToken()

0 commit comments

Comments
 (0)