Skip to content

Commit 74a3f3d

Browse files
Merge pull request #78 from luuuis/saml11-dont-mutate-moment
fix(saml11): do not mutate moment() when `options.lifetimeInSeconds` is provided
2 parents c19541b + 0a5afd1 commit 74a3f3d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

lib/saml11.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function createAssertion(options, strategies, callback) {
118118

119119
if (options.lifetimeInSeconds) {
120120
conditions[0].setAttribute('NotBefore', now.format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'));
121-
conditions[0].setAttribute('NotOnOrAfter', now.add(options.lifetimeInSeconds, 'seconds').format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'));
121+
conditions[0].setAttribute('NotOnOrAfter', moment(now).add(options.lifetimeInSeconds, 'seconds').format('YYYY-MM-DDTHH:mm:ss.SSS[Z]'));
122122
}
123123

124124
if (options.audiences) {

test/saml11.tests.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ describe('saml 1.1', function () {
9595
var signedAssertion = saml11[createAssertion](options);
9696
var conditions = utils.getConditions(signedAssertion);
9797
assert.equal(1, conditions.length);
98+
var authenticationInstant = utils.getAuthenticationInstant(signedAssertion);
9899
var notBefore = conditions[0].getAttribute('NotBefore');
99100
var notOnOrAfter = conditions[0].getAttribute('NotOnOrAfter');
101+
100102
should.ok(notBefore);
101103
should.ok(notOnOrAfter);
104+
should.equal(authenticationInstant, notBefore);
102105

103106
var lifetime = Math.round((moment(notOnOrAfter).utc() - moment(notBefore).utc()) / 1000);
104107
assert.equal(600, lifetime);

test/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ exports.getIssueInstant = function(assertion) {
4747
return doc.documentElement.getAttribute('IssueInstant');
4848
};
4949

50+
exports.getAuthenticationInstant = function (assertion) {
51+
return exports.getAuthenticationStatement(assertion).getAttribute('AuthenticationInstant');
52+
};
53+
5054
exports.getConditions = function(assertion) {
5155
var doc = new xmldom.DOMParser().parseFromString(assertion);
5256
return doc.documentElement.getElementsByTagName('saml:Conditions');

0 commit comments

Comments
 (0)