permissions, connection data reader
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -36,8 +36,13 @@ describe ('gateway', () => {
|
||||
g.logout (req);
|
||||
}
|
||||
res.writeHead (200);
|
||||
const con = req.connection as unknown as Record<string, unknown>;
|
||||
res.end (JSON.stringify (con.auth));
|
||||
const data = {
|
||||
...g.get_info (req),
|
||||
foo: g.has_permission (req, 'foo'),
|
||||
bar: g.has_permission (req, 'bar')
|
||||
};
|
||||
|
||||
res.end (JSON.stringify (data));
|
||||
};
|
||||
g.process_request (req, res, passed_handler);
|
||||
});
|
||||
@ -112,6 +117,8 @@ describe ('gateway', () => {
|
||||
.toEqual (token.id);
|
||||
expect (body.token_data)
|
||||
.toEqual ('foobar');
|
||||
expect (body.permissions)
|
||||
.toEqual ([]);
|
||||
});
|
||||
|
||||
it ('should reject an outdated access token', async () => {
|
||||
@ -198,4 +205,22 @@ describe ('gateway', () => {
|
||||
expect (blacklisted)
|
||||
.toContain (refresh.id);
|
||||
});
|
||||
|
||||
it ('should correctly check permissions', async () => {
|
||||
const token = await authority.sign (
|
||||
'access_token',
|
||||
60,
|
||||
{ permissions: [ 'foo' ] }
|
||||
);
|
||||
const resp = await get ({ authorization: `Bearer ${token.signature}` });
|
||||
expect (resp.statusCode)
|
||||
.toEqual (200);
|
||||
expect (JSON.parse (resp.body as string))
|
||||
.toEqual ({
|
||||
token_id: token.id,
|
||||
permissions: [ 'foo' ],
|
||||
foo: true,
|
||||
bar: false
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,15 @@
|
||||
import { generate_token_id, parse_token_id } from '../../lib/token_id';
|
||||
import { clock_finalize, clock_setup } from '../Helper';
|
||||
|
||||
describe ('token_id', () => {
|
||||
beforeAll (() => {
|
||||
clock_setup ();
|
||||
});
|
||||
|
||||
afterAll (() => {
|
||||
clock_finalize ();
|
||||
});
|
||||
|
||||
it ('should always generate valid tokens', () => {
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
const date = new Date;
|
||||
|
Reference in New Issue
Block a user