@screencloud/auth-sdk
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -71,2 +71,3 @@ "use strict"; | ||
var event_emitter_1 = require("@screencloud/event-emitter"); | ||
var UnixDate_1 = require("./lib/UnixDate"); | ||
function isNonEmptyString(str) { | ||
@@ -323,3 +324,3 @@ return typeof str === 'string' && !!str.trim(); | ||
// cached payload expires soon | ||
else if (this.cache.session && this.cache.session.claims.exp - (new Date().getTime()) < 1000 * 60 * 2) { | ||
else if (this.cache.session && (this.cache.session.claims.exp - UnixDate_1.UnixDate.now()) < 60 * 2) { | ||
this.log('shouldRefresh()', 'cached payload expires soon'); | ||
@@ -326,0 +327,0 @@ return true; |
@@ -55,3 +55,3 @@ "use strict"; | ||
email: 'bob@example.com', | ||
exp: Date.now() + (1000 * 60 * 60), | ||
exp: Math.floor(Date.now() / 1000) + (60 * 60), | ||
}, | ||
@@ -238,15 +238,15 @@ token: 'eyFooFoo', | ||
var auth = new Auth_1.Auth(defaultConfig); | ||
// false by default | ||
// true by default | ||
expect(auth.shouldRefresh()).toBeTruthy(); | ||
// true if valid | ||
// false if valid | ||
auth.setCache(defaultSession); | ||
expect(auth.shouldRefresh()).toBeFalsy(); | ||
}); | ||
it('returns true if exp is near is outdated', function () { | ||
it('returns true if exp is near or outdated', function () { | ||
var auth = new Auth_1.Auth(defaultConfig); | ||
// fresh session with long living date | ||
auth.setCache(defaultSession); | ||
// fresh session with 2+ minutes lifetime remaining | ||
auth.setCache(__assign(__assign({}, defaultSession), { claims: __assign(__assign({}, defaultSession.claims), { exp: Math.floor(Date.now() / 1000) + (60 * 2) + 2 }) })); | ||
expect(auth.shouldRefresh()).toBeFalsy(); | ||
// same session with changed exp-claim | ||
auth.setCache(__assign(__assign({}, defaultSession), { claims: __assign(__assign({}, defaultSession.claims), { exp: Date.now() + (1000 * 60 * 2) - 1 }) })); | ||
// same session with 2- minutes lifetime remaining | ||
auth.setCache(__assign(__assign({}, defaultSession), { claims: __assign(__assign({}, defaultSession.claims), { exp: Math.floor(Date.now() / 1000) + (60 * 2) - 2 }) })); | ||
expect(auth.shouldRefresh()).toBeTruthy(); | ||
@@ -263,2 +263,11 @@ }); | ||
}); | ||
it('returns false if session is cached and valid for another 2+ minutes', function () { | ||
var auth = new Auth_1.Auth(defaultConfig); | ||
// fresh session with long living date | ||
auth.setCache(defaultSession); | ||
expect(auth.shouldRefresh()).toBeFalsy(); | ||
// same session with changed exp-claim | ||
auth.setCache(__assign(__assign({}, defaultSession), { claims: __assign(__assign({}, defaultSession.claims), { exp: Date.now() + (1000 * 60 * 2) + 5 }) })); | ||
expect(auth.shouldRefresh()).toBeFalsy(); | ||
}); | ||
}); | ||
@@ -265,0 +274,0 @@ describe('refresh()', function () { |
@@ -67,3 +67,3 @@ { | ||
}, | ||
"version": "2.0.0" | ||
"version": "2.0.1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
74469
24
1410
1