spec.plugins.cookie.js
This file
Path
spec/spec.plugins.cookie.js
100 lines · 3.1 KiB · JavaScript
Last changed by
Merge branch 'integration'visionmediabefore adoptione03a023
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
describe 'Express' before_each reset() use(require('express/plugins/cookie').Cookie) compileCookie = require('express/plugins/cookie').compileCookie parseCookie = require('express/plugins/cookie').parseCookie end describe 'Cookie' describe 'compileCookie()' it 'should return a cookie string' var options = { path: '/', domain: '.vision-media.ca' } compileCookie('foo', 'bar', options).should.eql 'foo=bar; path=/; domain=.vision-media.ca' end it 'should correctly format any Date objects' var options = { expires: new Date(Date.parse('May 25, 1987 11:13:00 PDT')), path: '/foo', domain: '.vision-media.ca' } compileCookie('foo', 'bar', options).should.eql 'foo=bar; expires=Mon, 25 May 1987 18:13:00 GMT; path=/foo; domain=.vision-media.ca' end it 'should convert true to a key without a value' var options = { path: '/', secure: true, httpOnly: true } compileCookie('foo', 'bar', options).should.eql 'foo=bar; path=/; secure; httpOnly' end it 'should compile without options' compileCookie('foo', 'bar').should.eql 'foo=bar' end end describe 'parseCookie()' it 'should parse cookie key/value pairs' var attrs = 'sid=1232431234234; data=foo' parseCookie(attrs).should.eql { sid: '1232431234234', data: 'foo' } end it 'should preserve case' var attrs = 'SID=1232431234234; Data=foo' parseCookie(attrs).should.eql { SID: '1232431234234', Data: 'foo' } end it 'should disregard ad-hoc invalid whitespace' var attrs = ' SID = 1232431234234 ; data = foo' parseCookie(attrs).should.eql { SID: '1232431234234', data: 'foo' } end end describe 'on' describe 'request' it 'should parse the Cookie header' get('/user', function(){ return this.cookie('foo') }) get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar' end end describe 'response' it 'should populate Set-Cookie' get('/user', function(){ this.cookie('SID', '732423sdfs73243', { path: '/', secure: true }) return '' }) get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure' end it 'should set multiple cookies' get('/user', function(){ this.cookie('SID', '732423sdfs73243', { path: '/', secure: true }) this.cookie('foo', 'bar') return '' }) get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure\nset-cookie: foo=bar; path=/' end end end describe 'cookie()' it 'should get request cookie values' get('/user', function(){ return this.cookie('foo') }) get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar' end end endend