fix: Bypass auth tijdens testen
This commit is contained in:
		
							parent
							
								
									e348e1198b
								
							
						
					
					
						commit
						84de3cc424
					
				
					 2 changed files with 13 additions and 0 deletions
				
			
		|  | @ -8,6 +8,7 @@ | |||
| ### Dwengo ### | ||||
| 
 | ||||
| DWENGO_PORT=3000 | ||||
| DWENGO_RUN_MODE=test | ||||
| 
 | ||||
| DWENGO_DB_NAME=":memory:" | ||||
| DWENGO_DB_UPDATE=true | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ import * as express from 'express'; | |||
| import { RequestHandler } from 'express'; | ||||
| import { UnauthorizedException } from '../../../exceptions/unauthorized-exception.js'; | ||||
| import { ForbiddenException } from '../../../exceptions/forbidden-exception.js'; | ||||
| import { envVars, getEnvVar } from '../../../util/envVars.js'; | ||||
| 
 | ||||
| /** | ||||
|  * Middleware which rejects unauthenticated users (with HTTP 401) and authenticated users which do not fulfill | ||||
|  | @ -14,6 +15,17 @@ import { ForbiddenException } from '../../../exceptions/forbidden-exception.js'; | |||
| export function authorize<P, ResBody, ReqBody, ReqQuery, Locals extends Record<string, unknown>>( | ||||
|     accessCondition: (auth: AuthenticationInfo, req: AuthenticatedRequest<P, ResBody, ReqBody, ReqQuery, Locals>) => boolean | Promise<boolean> | ||||
| ): RequestHandler<P, ResBody, ReqBody, ReqQuery, Locals> { | ||||
|     // Bypass authentication during testing
 | ||||
|     if (getEnvVar(envVars.RunMode) === "test") { | ||||
|         return async ( | ||||
|             _req: AuthenticatedRequest<P, ResBody, ReqBody, ReqQuery, Locals>, | ||||
|             _res: express.Response, | ||||
|             next: express.NextFunction | ||||
|         ): Promise<void> => { | ||||
|             next(); | ||||
|         }; | ||||
|     } | ||||
| 
 | ||||
|     return async ( | ||||
|         req: AuthenticatedRequest<P, ResBody, ReqBody, ReqQuery, Locals>, | ||||
|         _res: express.Response, | ||||
|  |  | |||
		Reference in a new issue