Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
{ | ||
"name": "cookies", | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"description": "Cookies, optionally signed using Keygrip.", | ||
"main": "./index", | ||
"engines": [ | ||
"node" | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"files": [ | ||
"" | ||
], | ||
"main": "./lib/cookies", | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} | ||
"devDependencies": { | ||
"express": "*", | ||
"keygrip": "*" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
}, | ||
"author": "Jed Schmidt <tr@nslator.jp> (http://jed.is)", | ||
"homepage": "https://github.com/jed/cookies", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jed/cookies.git" | ||
}, | ||
"scripts": { | ||
"test": "node ./test/http.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env node | ||
|
||
var assert = require( "assert" ) | ||
, express = require( "express" ) | ||
, http = require( "http" ) | ||
, keys = require( "keygrip" )() | ||
, cookies = require( "../" ).express | ||
, options = { host: "localhost", port: 8000, path: "/set" } | ||
, app = express.createServer() | ||
|
||
app.use( cookies( keys ) ) | ||
|
||
app.get( "/set", function(req, res) { | ||
res.cookies | ||
// set a regular cookie | ||
.set( "unsigned", "foo", { httpOnly: false } ) | ||
|
||
// set a signed cookie | ||
.set( "signed", "bar", { signed: true } ) | ||
|
||
// mimic a signed cookie, but with a bogus signature | ||
.set( "tampered", "baz" ) | ||
.set( "tampered.sig", "bogus" ) | ||
|
||
res.writeHead(302, {Location: "/"}) | ||
res.end() | ||
}) | ||
|
||
app.get("/", function(req, res) { | ||
var unsigned = req.cookies.get( "unsigned" ) | ||
, signed = req.cookies.get( "signed", { signed: true } ) | ||
, tampered = req.cookies.get( "tampered", { signed: true } ) | ||
|
||
assert.equal( unsigned, "foo" ) | ||
assert.equal( signed, "bar" ) | ||
assert.notEqual( tampered, "baz" ) | ||
assert.equal( tampered, undefined ) | ||
|
||
res.send( | ||
"unsigned expected: foo\n" + | ||
"unsigned actual: " + unsigned + "\n\n" + | ||
"signed expected: bar\n" + | ||
"signed actual: " + signed + "\n\n" + | ||
"tampered expected: undefined\n"+ | ||
"tampered: " + tampered + "\n" | ||
) | ||
}) | ||
|
||
app.listen( 8000 ) | ||
|
||
http.get( options, function( res ) { | ||
var header = res.headers[ "set-cookie" ] | ||
, body = "" | ||
|
||
console.log( "\ncookies set:", header ) | ||
console.log( "\n============\n" ) | ||
|
||
options.path = res.headers[ "Location" ] | ||
options.headers = { "Cookie": header.join(";") } | ||
|
||
http.get( options, function( res ) { | ||
res.on( "data", function( chunk ){ body += chunk } ) | ||
res.on( "end", function(){ console.log( body ) }) | ||
app.close() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters