Skip to content

Commit

Permalink
tests: remove shared server object
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Mar 15, 2020
1 parent 78003f1 commit ff3a789
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions test/cookieParser.js
Expand Up @@ -7,50 +7,41 @@ var request = require('supertest')
var signature = require('cookie-signature')

describe('cookieParser()', function () {
var server
before(function () {
server = createServer('keyboard cat')
})

after(function (done) {
server.close(done)
})

it('should export JSONCookies function', function () {
assert(typeof cookieParser.JSONCookies, 'function')
})

describe('when no cookies are sent', function () {
it('should default req.cookies to {}', function (done) {
request(server)
request(createServer('keyboard cat'))
.get('/')
.expect(200, '{}', done)
})

it('should default req.signedCookies to {}', function (done) {
request(server)
request(createServer('keyboard cat'))
.get('/signed')
.expect(200, '{}', done)
})
})

describe('when cookies are sent', function () {
it('should populate req.cookies', function (done) {
request(server)
request(createServer('keyboard cat'))
.get('/')
.set('Cookie', 'foo=bar; bar=baz')
.expect(200, '{"foo":"bar","bar":"baz"}', done)
})

it('should inflate JSON cookies', function (done) {
request(server)
request(createServer('keyboard cat'))
.get('/')
.set('Cookie', 'foo=j:{"foo":"bar"}')
.expect(200, '{"foo":{"foo":"bar"}}', done)
})

it('should not inflate invalid JSON cookies', function (done) {
request(server)
request(createServer('keyboard cat'))
.get('/')
.set('Cookie', 'foo=j:{"foo":')
.expect(200, '{"foo":"j:{\\"foo\\":"}', done)
Expand Down Expand Up @@ -85,21 +76,22 @@ describe('cookieParser()', function () {
// TODO: "bar" fails...

it('should populate req.signedCookies', function (done) {
request(server)
request(createServer('keyboard cat'))
.get('/signed')
.set('Cookie', 'foo=s:' + val)
.expect(200, '{"foo":"foobarbaz"}', done)
})

it('should remove the signed value from req.cookies', function (done) {
request(server)
request(createServer('keyboard cat'))
.get('/')
.set('Cookie', 'foo=s:' + val)
.expect(200, '{}', done)
})

it('should omit invalid signatures', function (done) {
server.listen()
var server = createServer('keyboard cat')

request(server)
.get('/signed')
.set('Cookie', 'foo=' + val + '3')
Expand Down

0 comments on commit ff3a789

Please sign in to comment.