/
spec.plugins.cookie.js
100 lines (87 loc) · 3.07 KB
/
spec.plugins.cookie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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 currectly format any Date objects'
var options = {
expires: new Date('May 25, 1987 11:13:00'),
path: '/foo',
domain: '.vision-media.ca'
}
compileCookie('foo', 'bar', options).should.eql 'foo=bar; expires=Mon, 25-May-1987 11: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 join 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, 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
end
end