Skip to content

Commit e6fa566

Browse files
Salakarmikehardy
andauthored
test(installations): add missing returns for promises / repair token exp check (#5881)
* tests(installations): add missing returns for promises * test(installations): token time is in seconds, not millis repair the comparison logic so the times are on same scale, javascript is in milliseconds and needs to be converted to match firebase seconds Co-authored-by: Mike Hardy <[email protected]>
1 parent 5f4eadf commit e6fa566

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/installations/e2e/installations.e2e.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ describe('installations()', function () {
3838
const decodedToken = jwt.decode(token);
3939
decodedToken.fid.should.equal(id); // fid == firebase installations id
4040
decodedToken.projectNumber.should.equal(PROJECT_ID);
41-
if (decodedToken.exp < Date.now()) {
42-
Promise.reject('Token already expired');
41+
42+
// token time is "Unix epoch time", which is in seconds vs javascript milliseconds
43+
if (decodedToken.exp < Math.round(new Date().getTime() / 1000)) {
44+
return Promise.reject(new Error('Token already expired: ' + JSON.stringify(decodedToken)));
4345
}
4446

4547
const token2 = await firebase.installations().getToken(true);
@@ -48,8 +50,10 @@ describe('installations()', function () {
4850
const decodedToken2 = jwt.decode(token2);
4951
decodedToken2.fid.should.equal(id);
5052
decodedToken2.projectNumber.should.equal(PROJECT_ID);
51-
if (decodedToken2.exp < Date.now()) {
52-
Promise.reject('Token already expired');
53+
54+
// token time is "Unix epoch time", which is in seconds vs javascript milliseconds
55+
if (decodedToken.exp < Math.round(new Date().getTime() / 1000)) {
56+
return Promise.reject(new Error('Token already expired'));
5357
}
5458
(token === token2).should.be.false();
5559
});
@@ -71,9 +75,11 @@ describe('installations()', function () {
7175
const token = await firebase.installations().getToken(false);
7276
const decodedToken = jwt.decode(token);
7377
decodedToken.fid.should.equal(id2); // fid == firebase installations id
78+
79+
// token time is "Unix epoch time", which is in seconds vs javascript milliseconds
7480
decodedToken.projectNumber.should.equal(PROJECT_ID);
75-
if (decodedToken.exp < Date.now()) {
76-
Promise.reject('Token already expired');
81+
if (decodedToken.exp < Math.round(new Date().getTime() / 1000)) {
82+
return Promise.reject(new Error('Token already expired'));
7783
}
7884
});
7985
});

0 commit comments

Comments
 (0)