Skip to content

Commit

Permalink
fix(sdk): Added a tolerance for expiration (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregChan authored Mar 9, 2018
1 parent 2d364ee commit 6980b66
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const Promise = require('bluebird');
const _ = require('lodash');

const util = require('./lib/util');
// Tolerance for expiration measured in milliseconds
const TOLERANCE = 10 * 1000;

/* eslint-disable global-require */
/** @exports smartcar */
Expand Down Expand Up @@ -31,7 +33,7 @@ smartcar.expired = function(access) {
throw new TypeError('"access.expiration" argument must be a valid ISO date string');
}

return Date.now() > expiration;
return Date.now() > expiration - TOLERANCE;
};

/**
Expand Down
3 changes: 3 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ test('expired - string', function(t) {
expiration = new Date(Date.now() - (60 * 1000)).toISOString();
t.true(smartcar.expired(expiration));

expiration = new Date(Date.now()).toISOString();
t.true(smartcar.expired(expiration));

expiration = new Date(Date.now() + (60 * 1000)).toISOString();
t.false(smartcar.expired(expiration));

Expand Down

0 comments on commit 6980b66

Please sign in to comment.