logout function
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Timo Hocker
2022-05-02 13:30:09 +02:00
parent ec08f8f04e
commit 84be087743
6 changed files with 73 additions and 7 deletions

View File

@ -6,7 +6,7 @@
*/
import http from 'http';
import { create_gateway } from '../../lib/index';
import { GatewayClass, create_gateway } from '../../lib/index';
import authority from '../../lib/Authority';
import blacklist from '../../lib/Blacklist';
import { clock_finalize, clock_setup, get } from '../Helper';
@ -18,7 +18,7 @@ describe ('gateway', () => {
beforeAll (() => {
clock_setup ();
const g = create_gateway ({
const g = new GatewayClass ({
redirect_url: 'http://localhost/auth',
cookie: { name: 'cookie_jar' },
refresh_cookie: { name: 'mint_cookies' },
@ -31,11 +31,15 @@ describe ('gateway', () => {
server = http.createServer ((req, res) => {
const passed_handler = () => {
if (typeof req.url !== 'undefined') {
if (req.url.endsWith ('logout'))
g.logout (req);
}
res.writeHead (200);
const con = req.connection as unknown as Record<string, unknown>;
res.end (JSON.stringify (con.auth));
};
g (req, res, passed_handler);
g.process_request (req, res, passed_handler);
});
server.listen (3000);
});
@ -169,4 +173,23 @@ describe ('gateway', () => {
})
.toThrowError ('access and refresh cookies cannot have the same name');
});
it ('should logout all tokens', async () => {
const token = await authority.sign ('access_token', 60);
const refresh = await authority.sign ('refresh_token', 3600);
const resp = await get (
// eslint-disable-next-line max-len
{ cookie: `foo=bar;cookie_jar=${token.signature};asd=efg;mint_cookies=${refresh.signature}` },
null,
'/logout'
);
expect (resp.statusCode)
.toEqual (200);
const blacklisted = blacklist.export_blacklist ()
.map ((v) => v.hash);
expect (blacklisted)
.toContain (token.id);
expect (blacklisted)
.toContain (refresh.id);
});
});