diff options
| author | Tom Harley | 2018-03-27 03:50:17 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-03-27 03:50:17 +0100 |
| commit | ea1ee67bdd02b2ea727c09cfef1784a61aa934f4 (patch) | |
| tree | 6bf1e8a086bd5250416307501147ee4fe942b87b /src/auth.ts | |
| parent | small fix (diff) | |
| download | medicine-ea1ee67bdd02b2ea727c09cfef1784a61aa934f4.tar.gz medicine-ea1ee67bdd02b2ea727c09cfef1784a61aa934f4.zip | |
Centralise test configuration and introduce SQLite
Tests now take their configuration from a new file test-db.ts. Additionally, this configuration sets up and uses an in-memory SQLite3 database for testing, to avoid writing to disk and to prevent edits to a current database.
Diffstat (limited to 'src/auth.ts')
| -rw-r--r-- | src/auth.ts | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/auth.ts b/src/auth.ts index 6339260..b055d9f 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -26,7 +26,7 @@ export class AuthRouter { username: req.body.username }, include: [ UserGroup, Project] - }); + }); if (user === null) { // Whoa, what an error! @@ -68,18 +68,18 @@ export class AuthRouter { // Checks for errors within request before authentication public checkErr(req: Request, res: Response, next: NextFunction): void { if (!req.body.grant_type || !req.body.username || !req.body.password) { - next(new RequestError(400, 'invalid_request', 'Missing parameters')); + return next(new RequestError(400, 'invalid_request', 'Missing parameters')); } if (req.body.grant_type !== 'refresh_token' && req.body.grant_type !== 'password') { - next(new RequestError(400, 'unsupported_grant_type', 'invalid grant type')); + return next(new RequestError(400, 'unsupported_grant_type', `invalid grant type`)); } next(); } - + // Configure local strategy to use with passport-js. private configStrategy(): void { // tslint:disable-next-line:typedef @@ -93,7 +93,7 @@ export class AuthRouter { if (!user || user.password !== password) { return done(null, false); - } + } return done(null, user); })); } @@ -122,10 +122,10 @@ export const unauthorisedErr: Errorware = }; // Middleware to check privileges - admin -export const isAdmin: any = -(req: Request, res: Response, next: NextFunction): void => { +export const isAdmin: any = +(req: Request, res: Response, next: NextFunction): void => { var isAdmin: boolean = req.user.object.userGroups.some((x: UserGroup): boolean => x.name === 'admin'); - + if (!isAdmin) { next(new RequestError( 401, 'not_authorised', |
