Skip to content
Myr

spec.plugins.cookie.js

This file

Path

spec/spec.plugins.cookie.js

115 lines · 3.6 KiB · JavaScript

Last changed by

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

History of this file

Take it

The walk stopped after 200 commits: lines older than fbf547d point at it.

Added Session classvisionmediabefore adoptionfbf547d

lines 1–19why, one step back
1
2describe '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 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 20why, one step back
20 it 'should correctly format any Date objects'

Added Session classvisionmediabefore adoptionfbf547d

line 21why, one step back
21 var options = {

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 22why, one step back
22 expires: new Date(Date.parse('May 25, 1987 11:13:00 PDT')),

Added Session classvisionmediabefore adoptionfbf547d

lines 23–25why, one step back
23 path: '/foo',
24 domain: '.vision-media.ca'25 }

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 26why, one step back
26 compileCookie('foo', 'bar', options).should.eql 'foo=bar; expires=Mon, 25 May 1987 18:13:00 GMT; path=/foo; domain=.vision-media.ca'

Added Session classvisionmediabefore adoptionfbf547d

lines 27–57why, one step back
27 end
28 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 end

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

lines 58–72why, one step back
58
59 it 'should support complex quoted values'60 var attrs = 'SID="123456789"; fbs_0011223355="uid=0987654321&name=Test+User"'61 parseCookie(attrs).should.eql { SID: '123456789', fbs_0011223355: 'uid=0987654321&name=Test User' }62 end63 64 it 'should not override when a duplicate key is found'65 var attrs = 'SID=1234; SID=9999'66 parseCookie(attrs).should.eql { SID: '1234' }67 end68 69 it 'should support malformed cookies'70 var attrs = 'SID'71 parseCookie(attrs).should.eql {}72 end

Added Session classvisionmediabefore adoptionfbf547d

lines 73–90why, one step back
73 end
74 75 describe 'on'76 describe 'request'77 it 'should parse the Cookie header'78 get('/user', function(){79 return this.cookie('foo')80 })81 get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar'82 end83 end84 85 describe 'response'86 it 'should populate Set-Cookie'87 get('/user', function(){88 this.cookie('SID', '732423sdfs73243', { path: '/', secure: true })89 return '' 90 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 91why, one step back
91 get('/user').headers['Set-Cookie'].should.eql 'SID=732423sdfs73243; path=/; secure'

Added Session classvisionmediabefore adoptionfbf547d

lines 92–93why, one step back
92 end
93

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 94why, one step back
94 it 'should set multiple cookies'

Added Session classvisionmediabefore adoptionfbf547d

lines 95–99why, one step back
95 get('/user', function(){
96 this.cookie('SID', '732423sdfs73243', { path: '/', secure: true })97 this.cookie('foo', 'bar')98 return '' 99 })

Merge branch 'master' of http://github.com/visionmedia/expressGuillermo Rauchbefore adoption8ef6a0b

line 100why, one step back
100 get('/user').headers['Set-Cookie'].should.eql 'SID=732423sdfs73243; path=/; secure\r\nSet-Cookie: foo=bar; path=/'

Added Session classvisionmediabefore adoptionfbf547d

lines 101–115why, one step back
101 end
102 end103 end104 105 describe 'cookie()'106 it 'should get request cookie values'107 get('/user', function(){108 return this.cookie('foo')109 })110 get('/user', { headers: { cookie: 'foo=bar' }}).body.should.eql 'bar'111 end112 end113 114 end115end