Skip to content

Commit

Permalink
Add domain when clearing cookie (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
bunea authored Mar 31, 2020
1 parent d34b319 commit 215ff62
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/handlers/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default function logoutHandler(settings: IAuth0Settings, sessionSettings:
name: sessionSettings.cookieName,
value: '',
maxAge: -1,
path: sessionSettings.cookiePath
path: sessionSettings.cookiePath,
domain: sessionSettings.cookieDomain
}
]);

Expand Down
37 changes: 37 additions & 0 deletions tests/handlers/logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,40 @@ describe('logout handler', () => {
});
});
});

describe('logout handler with cookieDomain', () => {
const cookieDomain = 'www.acme.com';
let httpServer: HttpServer;

beforeAll(done => {
httpServer = new HttpServer(
logout(withoutApi, new CookieSessionStoreSettings({ ...withoutApi.session, cookieDomain }))
);
httpServer.start(done);
});

afterAll(done => {
httpServer.stop(done);
});

test('should delete the state and session', async () => {
const { headers } = await getAsync({
url: httpServer.getUrl(),
headers: {
cookie: ['a0:state=foo', 'a0:session=bar'].join('; ')
},
followRedirect: false
});

const [stateCookie, sessionCookie] = headers['set-cookie'];
expect(parse(stateCookie)).toMatchObject({
'a0:state': '',
'Max-Age': '-1'
});
expect(parse(sessionCookie)).toMatchObject({
'a0:session': '',
'Max-Age': '-1',
Domain: cookieDomain
});
});
});

0 comments on commit 215ff62

Please sign in to comment.