Skip to content

Commit

Permalink
test: add sameSite=none test case (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 1, 2020
1 parent c9865a7 commit 75c8ee6
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -12,3 +12,5 @@ script:
- npm run ci
after_script:
- npminstall codecov && codecov
services:
- redis-server
1 change: 1 addition & 0 deletions config/config.default.js
Expand Up @@ -5,4 +5,5 @@ exports.session = {
key: 'EGG_SESS',
httpOnly: true,
encrypt: true,
// sameSite: null,
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -48,7 +48,7 @@
"autod": "autod"
},
"ci": {
"version": "8, 9",
"version": "8, 10, 12",
"services": "redis-server",
"type": "travis"
},
Expand Down
26 changes: 26 additions & 0 deletions test/app/middleware/session.test.js
Expand Up @@ -41,6 +41,10 @@ describe('test/app/middlewares/session.test.js', () => {
.get('/set?foo=bar')
.expect(200)
.expect({ foo: 'bar' })
.expect(res => {
const cookie = res.headers['set-cookie'].join('|');
assert(!cookie.includes('; samesite=none;'));
})
.expect('set-cookie', /EGG_SESS=.*?;/);

yield agent.get('/get')
Expand All @@ -64,6 +68,28 @@ describe('test/app/middlewares/session.test.js', () => {
});
});

describe('sameSite', () => {
before(() => {
app = mm.app({ baseDir: 'samesite-none-session' });
return app.ready();
});
beforeEach(() => {
agent = request.agent(app.callback());
});
after(() => app.close());

it('should work with sameSite=none', async () => {
await agent
.get('/set?foo=bar')
.expect(200)
.expect({ foo: 'bar' })
.expect(res => {
const cookie = res.headers['set-cookie'].join('|');
assert(cookie.includes('; samesite=none;'));
});
});
});

[
'cookie-session',
'memory-session',
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/samesite-none-session/app/controller/home.js
@@ -0,0 +1,10 @@
'use strict';

exports.get = function* (ctx) {
ctx.body = ctx.session;
};

exports.set = function* (ctx) {
ctx.session = ctx.query;
ctx.body = ctx.session;
};
6 changes: 6 additions & 0 deletions test/fixtures/samesite-none-session/app/router.js
@@ -0,0 +1,6 @@
'use strict';

module.exports = function(app) {
app.get('/get', 'home.get');
app.get('/set', 'home.set');
};
6 changes: 6 additions & 0 deletions test/fixtures/samesite-none-session/config/config.default.js
@@ -0,0 +1,6 @@
'use strict';

exports.keys = 'keys';
exports.session = {
sameSite: 'none',
};
3 changes: 3 additions & 0 deletions test/fixtures/samesite-none-session/package.json
@@ -0,0 +1,3 @@
{
"name": "samesite-none-session"
}

0 comments on commit 75c8ee6

Please sign in to comment.