Skip to content

Commit

Permalink
Fix tests: unsigned cookie was actually getting signed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikko Koponen committed Nov 13, 2012
1 parent c328df4 commit 73aa92d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions test/express.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ app.use( cookies( keys ) )
app.get( "/set", function(req, res) { app.get( "/set", function(req, res) {
res.cookies res.cookies
// set a regular cookie // set a regular cookie
.set( "unsigned", "foo", { httpOnly: false } ) .set( "unsigned", "foo", { signed:false, httpOnly: false } )


// set a signed cookie // set a signed cookie
.set( "signed", "bar", { signed: true } ) .set( "signed", "bar", { signed: true } )
Expand All @@ -32,6 +32,7 @@ app.get("/", function(req, res) {
, tampered = req.cookies.get( "tampered", { signed: true } ) , tampered = req.cookies.get( "tampered", { signed: true } )


assert.equal( unsigned, "foo" ) assert.equal( unsigned, "foo" )
assert.equal( req.cookies.get( "unsigned.sig", { signed:false } ), undefined)
assert.equal( signed, "bar" ) assert.equal( signed, "bar" )
assert.notEqual( tampered, "baz" ) assert.notEqual( tampered, "baz" )
assert.equal( tampered, undefined ) assert.equal( tampered, undefined )
Expand All @@ -57,7 +58,7 @@ http.get( options, function( res ) {


console.log( "\ncookies set:", header ) console.log( "\ncookies set:", header )
console.log( "\n============\n" ) console.log( "\n============\n" )
assert.equal(header.length, 6) assert.equal(header.length, 5)


options.path = res.headers[ "Location" ] options.path = res.headers[ "Location" ]
options.headers = { "Cookie": header.join(";") } options.headers = { "Cookie": header.join(";") }
Expand Down
5 changes: 3 additions & 2 deletions test/http.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ server = http.createServer( function( req, res ) {
if ( req.url == "/set" ) { if ( req.url == "/set" ) {
cookies cookies
// set a regular cookie // set a regular cookie
.set( "unsigned", "foo", { httpOnly: false } ) .set( "unsigned", "foo", { signed:false, httpOnly: false } )


// set a signed cookie // set a signed cookie
.set( "signed", "bar", { signed: true } ) .set( "signed", "bar", { signed: true } )
Expand All @@ -32,6 +32,7 @@ server = http.createServer( function( req, res ) {
tampered = cookies.get( "tampered", { signed: true } ) tampered = cookies.get( "tampered", { signed: true } )


assert.equal( unsigned, "foo" ) assert.equal( unsigned, "foo" )
assert.equal( cookies.get( "unsigned.sig", { signed:false } ), undefined)
assert.equal( signed, "bar" ) assert.equal( signed, "bar" )
assert.notEqual( tampered, "baz" ) assert.notEqual( tampered, "baz" )
assert.equal( tampered, undefined ) assert.equal( tampered, undefined )
Expand All @@ -56,7 +57,7 @@ http.get( options, function( res ) {


console.log( "\ncookies set:", cookies ) console.log( "\ncookies set:", cookies )
console.log( "\n============\n" ) console.log( "\n============\n" )
assert.equal(cookies.length, 6) assert.equal(cookies.length, 5)


options.path = res.headers[ "location" ] options.path = res.headers[ "location" ]
options.headers = { "Cookie": cookies.join(";") } options.headers = { "Cookie": cookies.join(";") }
Expand Down

0 comments on commit 73aa92d

Please sign in to comment.