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