Skip to content
Myr

spec.plugins.session.js

This file

Path

spec/spec.plugins.session.js

93 lines · 2.8 KiB · JavaScript

Last changed by

Added session reapingvisionmediabefore adoption8ed99f6

History of this file

Take it

Started Session pluginvisionmediabefore adoption7238afb

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

Bulk of memory store based session support complete.visionmediabefore adoptionf4b4c03

lines 10–23why, one step back
10 describe 'when sid cookie is not present'
11 it 'should set sid cookie'12 get('/login', function(){ return '' })13 get('/login').headers['set-cookie'].should.match(/^sid=(\w+);/)14 end15 end16 17 describe 'when sid cookie is present'18 it 'should not set sid'19 get('/login', function(){ return '' })20 get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'set-cookie'21 end22 end23

Added session reapingvisionmediabefore adoption8ed99f6

lines 24–28why, one step back
24 describe 'MemoryStore'
25 before_each26 memory = new (require('express/plugins/session').MemoryStore)27 end28

Bulk of memory store based session support complete.visionmediabefore adoptionf4b4c03

lines 29–40why, one step back
29 it 'should persist'
30 post('/login', function(){31 return this.session.name = 'tj'32 })33 get('/login', function(){34 return this.session.name35 })36 var headers = { headers: { cookie: 'sid=123' }}37 post('/login', headers)38 get('/login', headers).status.should.eql 20039 get('/login', headers).body.should.eql 'tj'40 end

Added session reapingvisionmediabefore adoption8ed99f6

lines 41–89why, one step back
41
42 describe '#fetch()'43 describe 'when the session does not exist'44 it 'should return a new Session'45 memory.fetch('1').should.have_property 'lastAccess'46 end47 end48 49 describe 'when the session does exist'50 it 'should return the previous session'51 memory.commit({ id: '1', same: true })52 memory.fetch('1').should.have_property 'same', true53 end54 end55 end56 57 describe '#clear()'58 it 'should remove all sessions'59 memory.commit({ id: '1' })60 memory.commit({ id: '2' })61 memory.clear()62 memory.should.not.have_property '1'63 memory.should.not.have_property '2'64 end65 end66 67 describe '#destroy()'68 it 'should destroy a single session'69 memory.commit({ id: '1' })70 memory.commit({ id: '2' })71 memory.destroy('1')72 memory.store.should.not.have_property '1'73 memory.store.should.have_property '2'74 end75 end76 77 describe '#reap()'78 it 'should destroy sessions older than the given age in milliseconds'79 memory.commit({ id: '1', lastAccess: Number(new Date) - 300 })80 memory.commit({ id: '2', lastAccess: Number(new Date) - 250 })81 memory.commit({ id: '3', lastAccess: Number(new Date) - 100 })82 memory.commit({ id: '4', lastAccess: Number(new Date) })83 memory.reap(200)84 memory.store.should.not.have_property '1'85 memory.store.should.not.have_property '2'86 memory.store.should.have_property '3'87 memory.store.should.have_property '4'88 end89 end

Started Session pluginvisionmediabefore adoption7238afb

line 90why, one step back
90 end

Added session reapingvisionmediabefore adoption8ed99f6

line 91why, one step back
91

Started Session pluginvisionmediabefore adoption7238afb

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