This commit is contained in:
parent
debb7debf1
commit
48afa73ae8
@ -37,7 +37,7 @@ class AuthRequest {
|
||||
public is_basic: boolean;
|
||||
public user: string;
|
||||
public password: string;
|
||||
public token_data?: Record<string, unknown>;
|
||||
public token_data?: unknown;
|
||||
public token_id?: string;
|
||||
public body: string;
|
||||
|
||||
|
@ -22,7 +22,7 @@ interface VerificationResult {
|
||||
type: TokenType;
|
||||
id: string;
|
||||
next_module?: string;
|
||||
data?: Record<string, unknown>;
|
||||
data?: unknown;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ interface SignatureResult {
|
||||
|
||||
interface SignatureOptions
|
||||
{
|
||||
data?: Record<string, unknown>
|
||||
data?: unknown
|
||||
next_module?: string
|
||||
}
|
||||
|
||||
|
@ -67,10 +67,8 @@ class GatewayClass {
|
||||
|
||||
const ver = authority.verify (auth);
|
||||
|
||||
const con = req.connection as Record<string, unknown>;
|
||||
con.auth = {};
|
||||
con.auth.token_id = ver.id;
|
||||
con.auth.token_data = ver.data;
|
||||
const con = req.connection as unknown as Record<string, unknown>;
|
||||
con.auth = { token_id: ver.id, token_data: ver.data };
|
||||
|
||||
return ver.authorized;
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ describe ('gateway', () => {
|
||||
server = http.createServer ((req, res) => {
|
||||
const passed_handler = () => {
|
||||
res.writeHead (200);
|
||||
res.end ('passed');
|
||||
const con = req.connection as unknown as Record<string, unknown>;
|
||||
res.end (JSON.stringify (con.auth));
|
||||
};
|
||||
g (req, res, passed_handler);
|
||||
});
|
||||
@ -60,8 +61,8 @@ describe ('gateway', () => {
|
||||
const resp = await get ({ authorization: `Bearer ${token.signature}` });
|
||||
expect (resp.statusCode)
|
||||
.toEqual (200);
|
||||
expect (resp.body)
|
||||
.toEqual ('passed');
|
||||
expect (JSON.parse (resp.body as string).token_id)
|
||||
.toEqual (token.id);
|
||||
});
|
||||
|
||||
it ('should allow a valid access token using cookies', async () => {
|
||||
@ -69,8 +70,20 @@ describe ('gateway', () => {
|
||||
const resp = await get ({ cookie: `cookie_jar=${token.signature}` });
|
||||
expect (resp.statusCode)
|
||||
.toEqual (200);
|
||||
expect (resp.body)
|
||||
.toEqual ('passed');
|
||||
expect (JSON.parse (resp.body as string).token_id)
|
||||
.toEqual (token.id);
|
||||
});
|
||||
|
||||
it ('should correctly deliver token data', async () => {
|
||||
const token = authority.sign ('access_token', 60, { data: 'foobar' });
|
||||
const resp = await get ({ authorization: `Bearer ${token.signature}` });
|
||||
expect (resp.statusCode)
|
||||
.toEqual (200);
|
||||
const body = JSON.parse (resp.body as string);
|
||||
expect (body.token_id)
|
||||
.toEqual (token.id);
|
||||
expect (body.token_data)
|
||||
.toEqual ('foobar');
|
||||
});
|
||||
|
||||
it ('should reject an outdated access token', async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user