Skip to content

Commit eb03564

Browse files
committed
Added a tolerance for 1 second in the "should set maxAge" test, to avoid timing false positives.
Also fixed the "should equal original maxAge for all requests" tests so that the first actual value of originalMaxAge is used to compare both requests, rather than a hard coded value.
1 parent 609fbd7 commit eb03564

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

session/cookie.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ var deprecate = require('depd')('express-session')
1717
/**
1818
* Initialize a new `Cookie` with the given `options`.
1919
*
20-
* @param {IncomingMessage} req
2120
* @param {Object} options
2221
* @api private
2322
*/

test/cookie.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ describe('new Cookie()', function () {
9090

9191
it('should set maxAge', function () {
9292
var maxAge = 60000
93+
9394
var cookie = new Cookie({ maxAge: maxAge })
95+
var cookieMaxAge = cookie.maxAge
9496

95-
assert.strictEqual(cookie.maxAge, maxAge)
97+
assert.ok(cookieMaxAge <= maxAge)
98+
// Allow up to 1 seconds to happen in between the cookie creation and getting of the current max age.
99+
assert.ok(cookieMaxAge >= (maxAge - 1000))
96100
})
97101

98102
it('should accept Date object', function () {

test/session.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,39 +1943,47 @@ describe('session()', function(){
19431943
.expect(200, '2000', done)
19441944
})
19451945

1946-
it('should equal original maxAge for all requests', function (done) {
1946+
it('should equal original maxAge for all requests with memory store', function (done) {
1947+
var originalMaxAge = undefined
19471948
var server = createServer({ cookie: { maxAge: 2000 } }, function (req, res) {
1949+
if (!originalMaxAge) {
1950+
originalMaxAge = req.session.cookie.originalMaxAge
1951+
}
19481952
res.end(JSON.stringify(req.session.cookie.originalMaxAge))
19491953
})
19501954

19511955
request(server)
19521956
.get('/')
1953-
.expect(200, '2000', function (err, res) {
1957+
.expect(200, originalMaxAge, function (err, res) {
19541958
if (err) return done(err)
19551959
setTimeout(function () {
19561960
request(server)
19571961
.get('/')
19581962
.set('Cookie', cookie(res))
1959-
.expect(200, '2000', done)
1963+
.expect(200, originalMaxAge, done)
19601964
}, 100)
19611965
})
19621966
})
19631967

1964-
it('should equal original maxAge for all requests', function (done) {
1968+
it('should equal original maxAge for all requests with smart store', function (done) {
19651969
var store = new SmartStore()
1970+
var originalMaxAge = undefined
19661971
var server = createServer({ cookie: { maxAge: 2000 }, store: store }, function (req, res) {
1972+
if (!originalMaxAge) {
1973+
originalMaxAge = req.session.cookie.originalMaxAge
1974+
}
19671975
res.end(JSON.stringify(req.session.cookie.originalMaxAge))
19681976
})
19691977

19701978
request(server)
19711979
.get('/')
1972-
.expect(200, '2000', function (err, res) {
1980+
.expect(200, originalMaxAge, function (err, res) {
19731981
if (err) return done(err)
19741982
setTimeout(function () {
19751983
request(server)
19761984
.get('/')
19771985
.set('Cookie', cookie(res))
1978-
.expect(200, '2000', done)
1986+
.expect(200, originalMaxAge, done)
19791987
}, 100)
19801988
})
19811989
})

0 commit comments

Comments
 (0)