Skip to content

Commit c23bab4

Browse files
committed
fix: remvoe unused code
1 parent bdf51c3 commit c23bab4

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/context.js

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class ContextSession {
3333
// unset
3434
if (session === false) return null;
3535

36-
// cookie session store
37-
if (this.session) return this.session;
3836
// create an empty session or init from cookie
3937
this.store ? this.create() : this.initFromCookie();
4038
return this.session;

test/store.test.js

+36
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,42 @@ describe('Koa Session External Store', () => {
769769
should.not.exist(res.headers['set-cookie']);
770770
});
771771
});
772+
773+
describe('when get session before middleware', () => {
774+
it('should return empty session', async () => {
775+
const app = new Koa();
776+
app.keys = [ 'a', 'b' ];
777+
const options = {};
778+
options.store = store;
779+
app.use(async (ctx, next) => {
780+
// will not take effect
781+
ctx.session.should.be.ok();
782+
ctx.session.foo = '123';
783+
await next();
784+
});
785+
app.use(session(options, app));
786+
app.use(async ctx => {
787+
if (ctx.path === '/set') ctx.session = { foo: 'bar' };
788+
ctx.body = ctx.session;
789+
});
790+
791+
let res = await request(app.callback())
792+
.get('/')
793+
.expect({});
794+
795+
res = await request(app.callback())
796+
.get('/set')
797+
.expect({ foo: 'bar' });
798+
799+
res.headers['set-cookie'].should.have.length(2);
800+
const cookie = res.headers['set-cookie'].join(';');
801+
await sleep(1200);
802+
res = await request(app.callback())
803+
.get('/')
804+
.set('cookie', cookie)
805+
.expect({ foo: 'bar' });
806+
});
807+
});
772808
});
773809

774810
function App(options) {

0 commit comments

Comments
 (0)