From 4430d61b381d0b3dce4831fea1a9faa78d9efdf6 Mon Sep 17 00:00:00 2001 From: jw255 Date: Fri, 13 Apr 2018 14:25:42 +0100 Subject: changed 2 debug msgs --- src/FileRouter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FileRouter.ts b/src/FileRouter.ts index f01e1a0..ddcb3d5 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -569,7 +569,7 @@ export class FileRouter { req: Request, res: Response, next: NextFunction, project: string ): Promise => { - console.log("## as " + project) + logger.debug('Retrieving project \'${project}\''); res.locals.project = await Project.findOne({ where: { name: project -- cgit v1.2.1 From 01f3bde6fc51c398a36b42215c4056990821991b Mon Sep 17 00:00:00 2001 From: Hafeez Date: Fri, 13 Apr 2018 14:44:22 +0100 Subject: datebase retrieves all properties --- src/FileRouter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/FileRouter.ts b/src/FileRouter.ts index aa13872..619be9e 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -572,6 +572,7 @@ export class FileRouter { ): Promise => { logger.debug('Retrieving project \'${project}\''); res.locals.project = await Project.findOne({ + include: [{all: true}], where: { name: project } -- cgit v1.2.1 From 8f013438e4e4c96594b7ed567e7a58dfc1b7ce5a Mon Sep 17 00:00:00 2001 From: Hafeez Date: Fri, 13 Apr 2018 15:53:10 +0100 Subject: fixed mock file tests --- src/FileRouter.ts | 10 ++++------ test/integration/protocol.routes.test.ts | 10 ++++++---- test/test-db.ts | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 619be9e..b76dea7 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -415,13 +415,10 @@ const getProjects: Middleware = const getProjectName: Middleware = async(req: Request, res: Response, next: NextFunction): Promise => { const project: Project | null = res.locals.project; - if (project == null) { - console.log("was null") + if (project == null) { return next(new RequestError(404, 'project_not_found')); - } else { - console.log(project.contributors); - res.locals.data = project.fullInfo; - console.log("wasnt " + res.locals.data) + } else { + res.locals.data = project.fullInfo; next(); } }; @@ -639,6 +636,7 @@ export class FileRouter { fileId: string ): Promise => { const file: File | null = await File.findOne({ + include: [{all: true}], where: { uuid: fileId } diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts index 6a08278..7554f0e 100644 --- a/test/integration/protocol.routes.test.ts +++ b/test/integration/protocol.routes.test.ts @@ -8,7 +8,7 @@ import * as chai from 'chai'; const expect: Chai.ExpectStatic = chai.expect; import { Credentials, Database, addUser, initDB, resetDB, - Projec, addProjec } from '../test-db'; + Projec, addProjec, Filee, addFilee } from '../test-db'; import { default as User } from '../../src/db/model/User'; // Chai-http must be imported this way: @@ -30,6 +30,7 @@ let database: Database; let mockUser: Credentials; let token: string; let mockProj: Projec; +let mockFile: Filee; const initDatabase = async() => { database = initDB(); @@ -40,6 +41,7 @@ const populateDatabase = async() => { await resetDB(database); mockUser = await addUser(database, true); mockProj = await addProjec(database, mockUser); + mockFile = await addFilee(database, mockUser); }; const getToken = async() => { @@ -228,9 +230,9 @@ describe('routes : protocol', () => { ['get', '/projects/mocky/properties', { data: optional(types.anything) }, 200], - ['get', '/projects/mocky/files/:path', null, 200], - ['post', '/projects/mocky/files/:id', null, 200], - ['get', '/projects/mocky/files_by_id/:id', null, 200] + ['get', '/projects/mocky/files/example/path', null, 200], + ['post', '/projects/mocky/files/mockyfile2', null, 200], + ['get', '/projects/mocky/files_by_id/file1', null, 200] ]; /* tslint:enable:align */ diff --git a/test/test-db.ts b/test/test-db.ts index fa62ad7..32f2f0b 100644 --- a/test/test-db.ts +++ b/test/test-db.ts @@ -1,6 +1,8 @@ import { default as Project } from '../src/db/model/Project'; import { default as User } from '../src/db/model/User'; import { default as UserGroup } from '../src/db/model/UserGroup'; +import { default as File } from '../src/db/model/File'; +import { FileTypeName } from '../src/files'; import { Sequelize } from 'sequelize-typescript'; import * as sqlite from 'sqlite3'; @@ -37,6 +39,14 @@ export interface Projec { lastActivity: Date; } +export interface Filee { + name: string, + path: string, + uuid: string, + creator: Credentials, + type: FileTypeName +} + export const addUser: (database?: Database, admin?: boolean) => Promise = async( database?: Database, admin?: boolean @@ -78,3 +88,19 @@ export const addProjec: (database: Database, user: Credentials) => await new Project(mockProject).save(); return mockProject; }; + +export const addFilee: (database: Database, user: Credentials) => + Promise = async( + database: Database, user: Credentials +): Promise => { + const mockFile: Filee = { + name: 'mockyFile', + path: 'example/path', + uuid: 'file1', + creator: user, + type: "generic" + }; + + await new File(mockFile).save(); + return mockFile; +}; \ No newline at end of file -- cgit v1.2.1 From deab81f8ef469c4119838d72b56683b8dd4cbcfe Mon Sep 17 00:00:00 2001 From: jw255 Date: Fri, 13 Apr 2018 16:10:32 +0100 Subject: fixed some privs --- src/FileRouter.ts | 1 + src/app.ts | 1 + src/db/model/UserGroup.ts | 3 +++ src/index.ts | 20 ++++++++++++++++++-- test/integration/protocol.routes.test.ts | 16 +++++++++++++++- test/test-db.ts | 1 + 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/FileRouter.ts b/src/FileRouter.ts index 619be9e..7db7eb2 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -550,6 +550,7 @@ export class FileRouter { name: string ): Promise => { const user: User | null = await User.findOne({ + include: [{all: true}], where: { username: name } diff --git a/src/app.ts b/src/app.ts index d8dfe5d..f71ecf3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -68,6 +68,7 @@ class App { private middleware(): void { this.express.use(expressJwt({secret: 'Mr Secret'}) .unless({path: [ + '/', '/cs3099group-be-4/oauth/token', '/cs3099group-be-4/_supported_protocols_' ] }) diff --git a/src/db/model/UserGroup.ts b/src/db/model/UserGroup.ts index 46945de..60d45c8 100644 --- a/src/db/model/UserGroup.ts +++ b/src/db/model/UserGroup.ts @@ -37,6 +37,9 @@ export default class UserGroup extends Model { @Column public canEditProjects!: boolean; + @Column + public canAccessLogs!: boolean; + @Column public isInternal!: boolean; diff --git a/src/index.ts b/src/index.ts index f172e61..7e21c35 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,18 +52,34 @@ logger.info(`Port ${port} chosen`); isInternal: false, description: 'Systems admin' }); + const logging: UserGroup = new UserGroup({ + name: 'logging', + canAccessLogs: true, + isInternal: false, + description: 'Allows Post to Log' + }); + await logging.save(); await admin.save(); + logger.info('Adding admin user'); const root: User = new User({ username: 'hafeez', - password: 'pass', - userGroups: [admin] + password: 'pass' }); await root.save(); + await root.$set('userGroups', [admin, logging]); + + const user: User | null = await User.findOne({ + include: [{all: true}], + where: { + username: 'hafeez' + } + }); + logger.info('Booting ExpressJS server'); app.listen(port, (err: Error) => { if (err) { diff --git a/test/integration/protocol.routes.test.ts b/test/integration/protocol.routes.test.ts index 6a08278..3eaafe5 100644 --- a/test/integration/protocol.routes.test.ts +++ b/test/integration/protocol.routes.test.ts @@ -239,8 +239,22 @@ describe('routes : protocol', () => { beforeEach(populateDatabase); beforeEach(getToken); + it.only('test log', () => { + return chai.request(app).get(base + '/log') + .set('Authorization', `Bearer ${token}`) + .catch((err) => { + console.log("a") + console.log(err.response.body) + expect(false); + }).then((res: ChaiHttp.Response) => { + console.log("b") + console.log(res.body) + expect(false); + }); + }); + describe('Access all valid routes', () => { - forEach(completeProtocol).it.only( + forEach(completeProtocol).it( '%s %s should be json', (method: string, path: string, temp: Template, resCode: number) => { const request: ChaiHttp.Request = method === 'get' diff --git a/test/test-db.ts b/test/test-db.ts index fa62ad7..be5782a 100644 --- a/test/test-db.ts +++ b/test/test-db.ts @@ -55,6 +55,7 @@ export const addUser: (database?: Database, admin?: boolean) => canCreateProjects: true, canDeleteProjects: true, canEditProjects: true, + canAccessLogs: true, isInternal: false }); await priv.save(); -- cgit v1.2.1