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 fileTake 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 back12describe '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 back7 Base = require('express/plugins/session').BaseMerge branch 'async-plugins'visionmediabefore adoption4c246a4
lines 8–14why, one step back8 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 back15 get('/login').headers['Set-Cookie'].should.match(/^sid=(\w+);/)Merge branch 'async-plugins'visionmediabefore adoption4c246a4
line 16why, one step back16 endMerge branch 'fix-opera'visionmediabefore adoption399e0d9
lines 17–23why, one step back17 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 endMerge branch 'async-plugins'visionmediabefore adoption4c246a4
line 24why, one step back24 endMerge branch 'fix-opera'visionmediabefore adoption399e0d9
line 25why, one step back25 Merge branch 'integration'visionmediabefore adoption33443d9
line 26why, one step back26 describe 'when existing sid cookie is present'Merge branch 'async-plugins'visionmediabefore adoption4c246a4
line 27why, one step back27 it 'should not set sid'Merge branch 'integration'visionmediabefore adoption33443d9
line 28why, one step back28 Session.store.commit(new Base(123))Merge branch 'async-plugins'visionmediabefore adoption4c246a4
line 29why, one step back29 get('/login', function(){ return '' })Merge branch 'etag'visionmediabefore adoptionb5d6f1a
line 30why, one step back30 get('/login', { headers: { cookie: 'sid=123' }}).headers.should.not.have_property 'Set-Cookie'Merge branch 'async-plugins'visionmediabefore adoption4c246a4
lines 31–32why, one step back31 end32 endMerge branch 'integration'visionmediabefore adoption33443d9
lines 33–38why, one step back33 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 back39 headers.should.have_property 'Set-Cookie'Merge branch 'integration'visionmediabefore adoption33443d9
lines 40–43why, one step back40 headers['set-cookie'].should.not.be '123'41 end42 end 43Merge branch 'async-plugins'visionmediabefore adoption4c246a4
lines 44–45why, one step back44 describe 'session Store.Memory'45 before_eachMerge branch 'integration'visionmediabefore adoption33443d9
line 46why, one step back46 Session.store= memory = new (require('express/plugins/session').Store.Memory)Merge branch 'async-plugins'visionmediabefore adoption4c246a4
lines 47–55why, one step back47 end48 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 back56 memory.commit(new Base(123))Merge branch 'async-plugins'visionmediabefore adoption4c246a4
lines 57–71why, one step back57 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 back72 var result73 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 back77 end78 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 back82 var result83 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 back88 end89 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 back104 var lengthMerge branch 'async-plugins'visionmediabefore adoption4c246a4
lines 105–106why, one step back105 memory.commit({ id: '1' })106 memory.commit({ id: '2' })Merge branch 'integration'visionmediabefore adoption33443d9
lines 107–110why, one step back107 memory.length(function(error, len) {108 length = len109 })110 length.should.eql 2Merge branch 'async-plugins'visionmediabefore adoption4c246a4
lines 111–140why, one step back111 end112 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