Skip to content
Myr

spec.plugins.session.js

This file

Path

spec/spec.plugins.session.js

140 lines · 4.3 KiB · JavaScript

Last changed by

Merge branch 'etag'visionmediabefore adoptionb5d6f1a

History of this file

Take it

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

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 1–6why, one step back
1
2describe 'Express'3 before_each4 reset()5 use(require('express/plugins/cookie').Cookie)6 use(Session = require('express/plugins/session').Session)

Merge branch 'integration'visionmediabefore adoption33443d9

line 7why, one step back
7 Base = require('express/plugins/session').Base

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 8–14why, one step back
8 Session.store.clear()
9 end10 11 describe 'Session'12 describe 'when sid cookie is not present'13 it 'should set sid cookie'14 get('/login', function(){ return '' })

Merge branch 'etag'visionmediabefore adoptionb5d6f1a

line 15why, one step back
15 get('/login').headers['Set-Cookie'].should.match(/^sid=(\w+);/)

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

line 16why, one step back
16 end

Merge branch 'fix-opera'visionmediabefore adoption399e0d9

lines 17–23why, one step back
17
18 describe 'and requesting /favicon.ico'19 it 'should not set sid cookie'20 get('/favicon.ico', function(){ this.halt() })21 get('/favicon.ico').headers.should.not.have_property 'set-cookie'22 end23 end

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

line 24why, one step back
24 end

Merge branch 'fix-opera'visionmediabefore adoption399e0d9

line 25why, one step back
25

Merge branch 'integration'visionmediabefore adoption33443d9

line 26why, one step back
26 describe 'when existing sid cookie is present'

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

line 27why, one step back
27 it 'should not set sid'

Merge branch 'integration'visionmediabefore adoption33443d9

line 28why, one step back
28 Session.store.commit(new Base(123))

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

line 29why, one step back
29 get('/login', function(){ return '' })

Merge branch 'etag'visionmediabefore adoptionb5d6f1a

line 30why, one step back
30 get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'Set-Cookie'

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 31–32why, one step back
31 end
32 end

Merge branch 'integration'visionmediabefore adoption33443d9

lines 33–38why, one step back
33
34 describe 'when unknown sid cookie is present'35 it 'should set new sid'36 get('/login', function(){ return '' })37 var headers= get('/login', { headers: { cookie: 'sid=123' }}).headers38

Merge branch 'etag'visionmediabefore adoptionb5d6f1a

line 39why, one step back
39 headers.should.have_property 'Set-Cookie'

Merge branch 'integration'visionmediabefore adoption33443d9

lines 40–43why, one step back
40 headers['set-cookie'].should.not.be '123'
41 end42 end 43

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 44–45why, one step back
44 describe 'session Store.Memory'
45 before_each

Merge branch 'integration'visionmediabefore adoption33443d9

line 46why, one step back
46 Session.store= memory = new (require('express/plugins/session').Store.Memory)

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 47–55why, one step back
47 end
48 49 it 'should persist'50 post('/login', function(){51 return this.session.name = 'tj'52 })53 get('/login', function(){54 return this.session.name55 })

Merge branch 'integration'visionmediabefore adoption33443d9

line 56why, one step back
56 memory.commit(new Base(123))

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 57–71why, one step back
57 var headers = { headers: { cookie: 'sid=123' }}
58 post('/login', headers)59 get('/login', headers).status.should.eql 20060 get('/login', headers).body.should.eql 'tj'61 end62 63 describe '#toString()'64 it 'should return [Memory Store]'65 memory.toString().should.eql '[Memory Store]'66 end67 end68 69 describe '#fetch()'70 describe 'when the session does not exist'71 it 'should return a new Session'

Merge branch 'integration'visionmediabefore adoption33443d9

lines 72–76why, one step back
72 var result
73 memory.fetch('1', function(error,session){74 result= session75 })76 result.should.have_property 'lastAccess'

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 77–81why, one step back
77 end
78 end79 80 describe 'when the session does exist'81 it 'should return the previous session'

Merge branch 'integration'visionmediabefore adoption33443d9

lines 82–87why, one step back
82 var result
83 memory.commit(new Base('1'))84 memory.fetch('1', function(error, session){85 result = session86 })87 result.id.should.eql '1'

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 88–103why, one step back
88 end
89 end90 end91 92 describe '#clear()'93 it 'should remove all sessions'94 memory.commit({ id: '1' })95 memory.commit({ id: '2' })96 memory.clear()97 memory.should.not.have_property '1'98 memory.should.not.have_property '2'99 end100 end101 102 describe '#length()'103 it 'should return the number of session'

Merge branch 'integration'visionmediabefore adoption33443d9

line 104why, one step back
104 var length

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 105–106why, one step back
105 memory.commit({ id: '1' })
106 memory.commit({ id: '2' })

Merge branch 'integration'visionmediabefore adoption33443d9

lines 107–110why, one step back
107 memory.length(function(error, len) {
108 length = len109 })110 length.should.eql 2

Merge branch 'async-plugins'visionmediabefore adoption4c246a4

lines 111–140why, one step back
111 end
112 end113 114 describe '#destroy()'115 it 'should destroy a single session'116 memory.commit({ id: '1' })117 memory.commit({ id: '2' })118 memory.destroy('1')119 memory.store.should.not.have_property '1'120 memory.store.should.have_property '2'121 end122 end123 124 describe '#reap()'125 it 'should destroy sessions older than the given age in milliseconds'126 memory.commit({ id: '1', lastAccess: Number(new Date) - 300 })127 memory.commit({ id: '2', lastAccess: Number(new Date) - 250 })128 memory.commit({ id: '3', lastAccess: Number(new Date) - 100 })129 memory.commit({ id: '4', lastAccess: Number(new Date) })130 memory.reap(200)131 memory.store.should.not.have_property '1'132 memory.store.should.not.have_property '2'133 memory.store.should.have_property '3'134 memory.store.should.have_property '4'135 end136 end137 end138 139 end140end