fixed maxage support, added tests
This commit is contained in:
Родитель
fa843f5007
Коммит
4bf66f40bb
|
@ -180,8 +180,8 @@ var cookieSession = function(opts) {
|
|||
opts.cookieName = opts.cookieName || "session";
|
||||
|
||||
// support for maxAge
|
||||
if (opts.maxAge) {
|
||||
opts.expires = new Date(new Date().getTime() + opts.maxAge);
|
||||
if (opts.cookie.maxAge) {
|
||||
opts.cookie.expires = new Date(new Date().getTime() + opts.cookie.maxAge);
|
||||
}
|
||||
|
||||
// derive two keys, one for signing one for encrypting, from the secret.
|
||||
|
|
|
@ -9,7 +9,10 @@ var vows = require("vows"),
|
|||
// set up the session middleware
|
||||
var middleware = cookieSessions({
|
||||
cookieName: 'session',
|
||||
secret: 'yo'
|
||||
secret: 'yo',
|
||||
cookie: {
|
||||
maxAge: 5000
|
||||
}
|
||||
});
|
||||
|
||||
var suite = vows.describe('all');
|
||||
|
@ -51,6 +54,36 @@ suite.addBatch({
|
|||
}
|
||||
});
|
||||
|
||||
suite.addBatch({
|
||||
"a single request object" : {
|
||||
topic: function() {
|
||||
var self = this;
|
||||
|
||||
// simple app
|
||||
var app = express.createServer();
|
||||
app.use(middleware);
|
||||
app.get("/foo", function(req, res) {
|
||||
req.session.foo = 'foobar';
|
||||
res.send("hello");
|
||||
});
|
||||
|
||||
var browser = tobi.createBrowser(app);
|
||||
browser.get("/foo", function(res, $) {
|
||||
self.callback(null, res);
|
||||
});
|
||||
},
|
||||
"includes a set-cookie header": function(err, res) {
|
||||
assert.isArray(res.headers['set-cookie']);
|
||||
},
|
||||
"with an expires attribute": function(err, res) {
|
||||
assert.match(res.headers['set-cookie'][0], /expires/);
|
||||
},
|
||||
"with a path attribute": function(err, res) {
|
||||
assert.match(res.headers['set-cookie'][0], /path/);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
suite.addBatch({
|
||||
"across two requests" : {
|
||||
topic: function() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче