Skip to content

Commit

Permalink
Merge pull request #39 from rfink/sess_id_optional_check
Browse files Browse the repository at this point in the history
Sess id optional check
  • Loading branch information
dead-horse committed Jan 15, 2015
2 parents a7e874f + 0646a4d commit 129acbd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ module.exports = function (options) {

if (!matchPath(this)) return;

this.sessionId = this.cookies.get(key, {
signed: cookie.signed
});
if (!this.sessionId) {
this.sessionId = this.cookies.get(key, {
signed: cookie.signed
});
}

var session;
var isNew = false;
Expand Down
13 changes: 13 additions & 0 deletions test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,18 @@ describe('test/koa-session.test.js', function () {
.get('/session/id?test_sid_append=test')
.expect(/test$/, done);
});

it('should force a session id ok', function (done) {
request(app)
.get('/session/get')
.expect(/.*/, function(err, res) {
should.not.exist(err);
cookie = res.headers['set-cookie'][0].split(';');
var val = cookie[0].split('=').pop();
request(app)
.get('/session/id?force_session_id=' + val)
.expect(new RegExp(val), done);
});
});
});
});
8 changes: 8 additions & 0 deletions test/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ app.keys = ['keys', 'keykeys'];
app.proxy = true; // to support `X-Forwarded-*` header

var store = new Store();

app.use(function*(next) {
if (this.request.query.force_session_id) {
this.sessionId = this.request.query.force_session_id;
}
return yield next;
});

app.use(session({
key: 'koss:test_sid',
prefix: 'koss:test',
Expand Down

0 comments on commit 129acbd

Please sign in to comment.