Skip to content
Myr

spec.plugins.session.js

This file

Path

spec/spec.plugins.session.js

133 lines · 4.0 KiB · JavaScript

Last changed by

Merge branch 'integration'visionmediabefore adoption33443d9

History of this file

Take it

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

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 1–4why, one step back
1
2describe 'Express'3 before_each4 reset()

Fixed broken specs due to use(Cookie) missingvisionmediabefore adoption1a9a367

line 5why, one step back
5 use(require('express/plugins/cookie').Cookie)

Merge branch 'integration'visionmediabefore adoptionadd0a43

line 6why, one step back
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 'integration'visionmediabefore adoptionadd0a43

lines 8–17why, 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 '' })15 get('/login').headers['set-cookie'].should.match(/^sid=(\w+);/)16 end17 end

Merge branch 'integration'visionmediabefore adoption33443d9

lines 18–19why, one step back
18
19 describe 'when existing sid cookie is present'

Merge branch 'integration'visionmediabefore adoptionadd0a43

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

Merge branch 'integration'visionmediabefore adoption33443d9

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

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 22–25why, one step back
22 get('/login', function(){ return '' })
23 get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'set-cookie'24 end25 end

Merge branch 'integration'visionmediabefore adoption33443d9

lines 26–36why, one step back
26
27 describe 'when unknown sid cookie is present'28 it 'should set new sid'29 get('/login', function(){ return '' })30 var headers= get('/login', { headers: { cookie: 'sid=123' }}).headers31 32 headers.should.have_property 'set-cookie'33 headers['set-cookie'].should.not.be '123'34 end35 end 36

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 37–38why, one step back
37 describe 'session Store.Memory'
38 before_each

Merge branch 'integration'visionmediabefore adoption33443d9

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

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 40–48why, one step back
40 end
41 42 it 'should persist'43 post('/login', function(){44 return this.session.name = 'tj'45 })46 get('/login', function(){47 return this.session.name48 })

Merge branch 'integration'visionmediabefore adoption33443d9

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

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 50–64why, one step back
50 var headers = { headers: { cookie: 'sid=123' }}
51 post('/login', headers)52 get('/login', headers).status.should.eql 20053 get('/login', headers).body.should.eql 'tj'54 end55 56 describe '#toString()'57 it 'should return [Memory Store]'58 memory.toString().should.eql '[Memory Store]'59 end60 end61 62 describe '#fetch()'63 describe 'when the session does not exist'64 it 'should return a new Session'

Merge branch 'integration'visionmediabefore adoption33443d9

lines 65–69why, one step back
65 var result
66 memory.fetch('1', function(error,session){67 result= session68 })69 result.should.have_property 'lastAccess'

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 70–74why, one step back
70 end
71 end72 73 describe 'when the session does exist'74 it 'should return the previous session'

Merge branch 'integration'visionmediabefore adoption33443d9

lines 75–80why, one step back
75 var result
76 memory.commit(new Base('1'))77 memory.fetch('1', function(error, session){78 result = session79 })80 result.id.should.eql '1'

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 81–96why, one step back
81 end
82 end83 end84 85 describe '#clear()'86 it 'should remove all sessions'87 memory.commit({ id: '1' })88 memory.commit({ id: '2' })89 memory.clear()90 memory.should.not.have_property '1'91 memory.should.not.have_property '2'92 end93 end94 95 describe '#length()'96 it 'should return the number of session'

Merge branch 'integration'visionmediabefore adoption33443d9

line 97why, one step back
97 var length

Merge branch 'integration'visionmediabefore adoptionadd0a43

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

Merge branch 'integration'visionmediabefore adoption33443d9

lines 100–103why, one step back
100 memory.length(function(error, len) {
101 length = len102 })103 length.should.eql 2

Merge branch 'integration'visionmediabefore adoptionadd0a43

lines 104–133why, one step back
104 end
105 end106 107 describe '#destroy()'108 it 'should destroy a single session'109 memory.commit({ id: '1' })110 memory.commit({ id: '2' })111 memory.destroy('1')112 memory.store.should.not.have_property '1'113 memory.store.should.have_property '2'114 end115 end116 117 describe '#reap()'118 it 'should destroy sessions older than the given age in milliseconds'119 memory.commit({ id: '1', lastAccess: Number(new Date) - 300 })120 memory.commit({ id: '2', lastAccess: Number(new Date) - 250 })121 memory.commit({ id: '3', lastAccess: Number(new Date) - 100 })122 memory.commit({ id: '4', lastAccess: Number(new Date) })123 memory.reap(200)124 memory.store.should.not.have_property '1'125 memory.store.should.not.have_property '2'126 memory.store.should.have_property '3'127 memory.store.should.have_property '4'128 end129 end130 end131 132 end133end