Skip to content

Commit

Permalink
no need to attempt verification of missing token
Browse files Browse the repository at this point in the history
  • Loading branch information
jksolbakken committed Aug 2, 2019
1 parent 7ceac04 commit f91c9fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/server/authsupport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

const stillValid = token => {
if (!token) {
return false;
}

try {
const claims = claimsFrom(token);
const expirationTime = parseInt(claims['exp']);
Expand Down
6 changes: 5 additions & 1 deletion tests/server/authsupport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ test('invalid token has expiry in the past', async () => {
expect(authsupport.stillValid(token)).toEqual(false);
});

test('missing token does not validate', async () => {
test('null token does not validate', async () => {
expect(authsupport.stillValid(null)).toEqual(false);
});

test('undefined token does not validate', async () => {
expect(authsupport.stillValid(undefined)).toEqual(false);
});

test('malformed token does not validate', async () => {
expect(authsupport.stillValid('bogustext')).toEqual(false);
});
Expand Down

0 comments on commit f91c9fe

Please sign in to comment.