supertest-session
Advanced tools
Comparing version 0.0.5 to 0.0.6
30
index.js
@@ -5,6 +5,16 @@ var _ = require('lodash'), | ||
// A/V pairs defined for Set-Cookie in RFC-6265 | ||
var reservedAvs = [ | ||
'path', | ||
'expires', | ||
'max-age', | ||
'domain', | ||
'secure', | ||
'httponly' | ||
]; | ||
function serializeCookie (c) { | ||
return _.compact(_.map(c, function (v, k) { | ||
if (k.toLowerCase() !== 'path') { | ||
return decodeURIComponent(cookie.serialize(k, v)); | ||
return _.compact(Object.keys(c).map(function (k) { | ||
if (reservedAvs.indexOf(k.toLowerCase()) === -1) { | ||
return decodeURIComponent(cookie.serialize(k, c[k])); | ||
} | ||
@@ -22,3 +32,3 @@ })); | ||
if (config.envs && _.isObject(config.envs)) { | ||
_.each(Object.keys(config.envs), function(e) { | ||
Object.keys(config.envs).forEach(function(e) { | ||
process.env[e] = config.envs[e]; | ||
@@ -30,3 +40,5 @@ }); | ||
Session.prototype._before = function (req) { | ||
req.cookies = _.map(this.cookies, serializeCookie).join('; '); | ||
if (this.cookies) { | ||
req.cookies = this.cookies.map(serializeCookie).join('; '); | ||
} | ||
if (config.before) config.before.call(this, req); | ||
@@ -38,4 +50,4 @@ }; | ||
if (config.after) config.after.call(this, req, res); | ||
if (_.has(res.headers, 'set-cookie')) { | ||
this.cookies = _.map(res.headers['set-cookie'], cookie.parse); | ||
if (res.headers.hasOwnProperty('set-cookie')) { | ||
this.cookies = res.headers['set-cookie'].map(cookie.parse); | ||
} | ||
@@ -55,3 +67,3 @@ }; | ||
req.end = _.wrap(_.bind(req.end, req), function (end, callback) { | ||
req.end = _.wrap(req.end.bind(req), function (end, callback) { | ||
return end(_.wrap(callback, function (callback, err, res) { | ||
@@ -72,3 +84,3 @@ if (err === null) { | ||
_.each(['get','put','post','del', 'patch'], function (m) { | ||
['get', 'put', 'post', 'del', 'patch'].forEach(function (m) { | ||
Session.prototype[m] = _.partial(Session.prototype.request, m); | ||
@@ -75,0 +87,0 @@ }); |
{ | ||
"name": "supertest-session", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Cookie-based session persistence for Supertest", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha", | ||
"cover": "istanbul cover ./node_modules/mocha/bin/_mocha" | ||
"test": "./node_modules/jasmine-node/bin/jasmine-node --forceexit test", | ||
"cover": "./node_modules/istanbul/lib/cli.js cover ./node_modules/jasmine-node/bin/jasmine-node ./spec/ && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" | ||
}, | ||
@@ -32,2 +32,4 @@ "repository": { | ||
"cookie": "^0.1.2", | ||
"coveralls": "^2.11.2", | ||
"jasmine-node": "^1.14.5", | ||
"lodash": "~2.2.1", | ||
@@ -38,7 +40,7 @@ "supertest": "^0.14.0" | ||
"connect": "^3.2.0", | ||
"cookie-session": "^1.0.2", | ||
"cookie-session": "^1.1.0", | ||
"express": "^4.9.5", | ||
"istanbul": "^0.3.0", | ||
"mocha": "~1.13.0" | ||
"through": "^2.3.6" | ||
} | ||
} |
@@ -5,2 +5,8 @@ # Supertest sessions | ||
[![Build | ||
Status](https://travis-ci.org/rjz/supertest-session.svg?branch=master)](https://travis-ci.org/rjz/supertest-session) | ||
[![Coverage | ||
Status](https://coveralls.io/repos/rjz/supertest-session/badge.png)](https://coveralls.io/r/rjz/supertest-session) | ||
References: | ||
@@ -7,0 +13,0 @@ |
@@ -8,3 +8,4 @@ var connect = require('connect'), | ||
name: 'supertest-session', | ||
secret: 'not-very' | ||
secret: 'not-very', | ||
maxAge: 3600 | ||
})); | ||
@@ -11,0 +12,0 @@ |
@@ -1,2 +0,2 @@ | ||
var _ = require('lodash'), | ||
var tr = require('through'), | ||
assert = require('assert'), | ||
@@ -8,2 +8,4 @@ app = require('./app'), | ||
var sess = null; | ||
var Session = session({ | ||
@@ -14,5 +16,5 @@ app: app, | ||
before(function (done) { | ||
this.sess = new Session(); | ||
this.sess.request('get', '/') | ||
beforeEach(function (done) { | ||
sess = new Session(); | ||
sess.request('get', '/') | ||
.expect(200) | ||
@@ -24,3 +26,3 @@ .expect('GET,,1') | ||
it('should increment session counter', function (done) { | ||
this.sess.request('get', '/') | ||
sess.request('get', '/') | ||
.expect(200) | ||
@@ -32,3 +34,3 @@ .expect('GET,,2') | ||
it('should set enviromental variables', function(done) { | ||
this.sess.request('get', '/env') | ||
sess.request('get', '/env') | ||
.expect(200) | ||
@@ -43,4 +45,4 @@ .end(function(err, res) { | ||
it('should destroy session', function (done) { | ||
this.sess.destroy(); | ||
this.sess.get('/') | ||
sess.destroy(); | ||
sess.get('/') | ||
.expect(200) | ||
@@ -51,5 +53,12 @@ .expect('GET,,1') | ||
it('supports streaming', function (done) { | ||
sess = new Session(); | ||
sess.get('/') | ||
.pipe(tr(function (data) { | ||
assert.equal(data.toString('utf8'), 'GET,,1'); | ||
}, done)); | ||
}); | ||
describe('method sugar', function () { | ||
var count = 1, | ||
methods = { | ||
var methods = { | ||
'del' : 'DELETE', | ||
@@ -62,7 +71,7 @@ 'get' : 'GET', | ||
_.each(methods, function (v, m) { | ||
it('should support ' + m, function (done) { | ||
this.sess[m]('/') | ||
Object.keys(methods).forEach(function (key) { | ||
it('should support ' + key, function (done) { | ||
sess[key]('/') | ||
.expect(200) | ||
.expect([v, '', ++count].join(',')) | ||
.expect(methods[key] + ',,2') | ||
.end(done); | ||
@@ -76,2 +85,4 @@ }); | ||
var sess = null; | ||
var Session = session({ | ||
@@ -84,5 +95,5 @@ app: app, | ||
before(function (done) { | ||
this.sess = new Session(); | ||
this.sess.request('get', '/token') | ||
beforeEach(function (done) { | ||
sess = new Session(); | ||
sess.request('get', '/token') | ||
.expect(200) | ||
@@ -94,3 +105,3 @@ .expect('GET,token,1') | ||
it('should increment session counter', function (done) { | ||
this.sess.request('get', '/token') | ||
sess.request('get', '/token') | ||
.expect(200) | ||
@@ -97,0 +108,0 @@ .expect('GET,token,2') |
10344
10
186
99
5
+ Addedcoveralls@^2.11.2
+ Addedjasmine-node@^1.14.5
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@0.2.01.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.6.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcaseless@0.11.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcoffeescript@1.12.7(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcoveralls@2.13.3(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@2.7.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.1.4(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgaze@1.1.3(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedglob@7.1.7(transitive)
+ Addedglobule@1.3.4(transitive)
+ Addedgrowl@1.7.0(transitive)
+ Addedhar-validator@2.0.6(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.1.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjasmine-growl-reporter@0.2.1(transitive)
+ Addedjasmine-node@1.16.2(transitive)
+ Addedjasmine-reporters@1.0.2(transitive)
+ Addedjs-yaml@3.6.1(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlcov-parse@0.0.10(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlog-driver@1.2.5(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedminimatch@3.0.8(transitive)
+ Addedminimist@1.2.0(transitive)
+ Addedmkdirp@0.3.5(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.3.3(transitive)
+ Addedrequest@2.79.0(transitive)
+ Addedrequirejs@2.3.7(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtough-cookie@2.3.4(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedunderscore@1.9.2(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwalkdir@0.0.12(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)