Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Can set session-only cookies #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/cookie-sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,13 @@ exports.valid = function(secret, timeout, str){
var hmac_sig = exports.hmac_signature(
secret, parts.timestamp, parts.data_blob
);
return (
parts.hmac_signature === hmac_sig &&
parts.timestamp + timeout > new Date().getTime()
);

var validatedTimeout = true;
if(timeout){
validatedTimeout = parts.timestamp + timeout > new Date().getTime();
}

return (parts.hmac_signature === hmac_sig && validatedTimeout);
};

exports.decrypt = function(secret, str){
Expand Down Expand Up @@ -210,10 +213,13 @@ exports.readSession = function(key, secret, timeout, req){
if(cookies[key]){
return exports.deserialize(secret, timeout, cookies[key]);
}
return undefined;
return {};
};


exports.expires = function(timeout){
return (new Date(new Date().getTime() + (timeout))).toUTCString();
if(timeout){
return (new Date(new Date().getTime() + (timeout))).toUTCString();
}
return null;
};
2 changes: 1 addition & 1 deletion test/test-cookie-sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ exports['readSession no cookie'] = function(test){
var r = sessions.readSession(
'node_session', 'secret', 12, 'request_obj'
);
test.same(r, undefined, 'return empty session');
test.same(r, {}, 'return empty session');

// restore copied functions
sessions.readCookies = readCookies;
Expand Down