From ea1ee67bdd02b2ea727c09cfef1784a61aa934f4 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 27 Mar 2018 03:50:17 +0100 Subject: 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. --- src/FileRouter.ts | 1 - src/app.ts | 9 +++------ src/auth.ts | 16 ++++++++-------- 3 files changed, 11 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 1cef85d..4dc3105 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -447,7 +447,6 @@ const postProjectName: Middleware = }); promise = file.save(); project = new Project({ - uuid: uuid.generate(), name: req.params.project_name, rootFolder: file }); diff --git a/src/app.ts b/src/app.ts index bedffa4..897896a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -94,8 +94,7 @@ class App { } }); if (user === null) { - next(new RequestError(404, 'user_not_found')); - return; + return next(new RequestError(404, 'user_not_found')); } else { res.locals.user = user; } @@ -142,8 +141,7 @@ class App { } }); if (fileOrNull === null) { - next(); - return; + return next(); } else { file = fileOrNull; } @@ -159,8 +157,7 @@ class App { } }); if (parentFolder === null) { - next(); - return; + return next(); } res.locals.parentFolder = parentFolder; const tFile: File | undefined = parentFolder.containedFiles.find( 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', -- cgit v1.2.1