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
The walk stopped after 200 commits: lines older than 3863a76 point at it.
Merge branch 'flash'visionmediabefore adoption3863a76
lines 1–19why, one step back12describe 'Express'3 before_each4 reset()5 use(require('express/plugins/cookie').Cookie)6 compileCookie = require('express/plugins/cookie').compileCookie7 parseCookie = require('express/plugins/cookie').parseCookie8 end9 10 describe 'Cookie'11 describe 'compileCookie()'12 it 'should return a cookie string'13 var options = {14 path: '/',15 domain: '.vision-media.ca'16 }17 compileCookie('foo', 'bar', options).should.eql 'foo=bar; path=/; domain=.vision-media.ca'18 end19 Merge branch 'integration'visionmediabefore adoptione03a023
line 20why, one step back20 it 'should correctly format any Date objects'Merge branch 'flash'visionmediabefore adoption3863a76
line 21why, one step back21 var options = {Merge branch 'integration'visionmediabefore adoptione03a023
line 22why, one step back22 expires: new Date(Date.parse('May 25, 1987 11:13:00 PDT')),Merge branch 'flash'visionmediabefore adoption3863a76
lines 23–25why, one step back23 path: '/foo',24 domain: '.vision-media.ca'25 }Cookie expires now using Date#toGMTString()visionmediabefore adoptiona318ef2
line 26why, one step back26 compileCookie('foo', 'bar', options).should.eql 'foo=bar; expires=Mon, 25 May 1987 18:13:00 GMT; path=/foo; domain=.vision-media.ca'Merge branch 'flash'visionmediabefore adoption3863a76
lines 27–78why, one step back27 end28 29 it 'should convert true to a key without a value'30 var options = {31 path: '/',32 secure: true,33 httpOnly: true34 }35 compileCookie('foo', 'bar', options).should.eql 'foo=bar; path=/; secure; httpOnly'36 end37 38 it 'should compile without options'39 compileCookie('foo', 'bar').should.eql 'foo=bar'40 end41 end42 43 describe 'parseCookie()'44 it 'should parse cookie key/value pairs'45 var attrs = 'sid=1232431234234; data=foo'46 parseCookie(attrs).should.eql { sid: '1232431234234', data: 'foo' }47 end48 49 it 'should preserve case'50 var attrs = 'SID=1232431234234; Data=foo'51 parseCookie(attrs).should.eql { SID: '1232431234234', Data: 'foo' }52 end53 54 it 'should disregard ad-hoc invalid whitespace'55 var attrs = ' SID = 1232431234234 ; data = foo'56 parseCookie(attrs).should.eql { SID: '1232431234234', data: 'foo' }57 end58 end59 60 describe 'on'61 describe 'request'62 it 'should parse the Cookie header'63 get('/user', function(){64 return this.cookie('foo')65 })66 get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar'67 end68 end69 70 describe 'response'71 it 'should populate Set-Cookie'72 get('/user', function(){73 this.cookie('SID', '732423sdfs73243', { path: '/', secure: true })74 return '' 75 })76 get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure'77 end78 Fixed setting of multiple cookies. Closes #199visionmediabefore adoption0849768
line 79why, one step back79 it 'should set multiple cookies'Merge branch 'flash'visionmediabefore adoption3863a76
lines 80–84why, one step back80 get('/user', function(){81 this.cookie('SID', '732423sdfs73243', { path: '/', secure: true })82 this.cookie('foo', 'bar')83 return '' 84 })Fixed setting of multiple cookies. Closes #199visionmediabefore adoption0849768
line 85why, one step back85 get('/user').headers['set-cookie'].should.eql 'SID=732423sdfs73243; path=/; secure\nset-cookie: foo=bar; path=/'Merge branch 'flash'visionmediabefore adoption3863a76
lines 86–100why, one step back86 end87 end88 end89 90 describe 'cookie()'91 it 'should get request cookie values'92 get('/user', function(){93 return this.cookie('foo')94 })95 get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar'96 end97 end98 99 end100end