diff options
| author | Tom Harley | 2018-04-13 16:21:46 +0100 |
|---|---|---|
| committer | Tom Harley | 2018-04-13 16:21:46 +0100 |
| commit | 1905365083dc63d06de2a169c18163f4b04e231d (patch) | |
| tree | 10ee91cbdb921a2f8c74291eeecca9cae9c9c7ec | |
| parent | Fix minor places, and add Postman collection (diff) | |
| parent | Merge branch 'trh/gets' of https://gitlab.cs.st-andrews.ac.uk/cs3099group-be-... (diff) | |
| download | medicine-1905365083dc63d06de2a169c18163f4b04e231d.tar.gz medicine-1905365083dc63d06de2a169c18163f4b04e231d.zip | |
Merge branch ‘trh/gets’ of gitlab.cs.st-andrews.ac.uk:cs3099group-be-4/project-code into trh/gets
| -rw-r--r-- | src/FileRouter.ts | 3 | ||||
| -rw-r--r-- | src/app.ts | 1 | ||||
| -rw-r--r-- | src/db/model/UserGroup.ts | 3 | ||||
| -rw-r--r-- | src/index.ts | 20 | ||||
| -rw-r--r-- | test/integration/protocol.routes.test.ts | 26 | ||||
| -rw-r--r-- | test/test-db.ts | 27 |
6 files changed, 72 insertions, 8 deletions
diff --git a/src/FileRouter.ts b/src/FileRouter.ts index bbcc0f2..b750094 100644 --- a/src/FileRouter.ts +++ b/src/FileRouter.ts @@ -617,6 +617,7 @@ export class FileRouter { ): Promise<void> => { logger.debug(`Searching for user ${name}`); const user: User | null = await User.findOne({ + include: [{all: true}], where: { username: name } @@ -637,7 +638,6 @@ export class FileRouter { req: Request, res: Response, next: NextFunction, projectName: string ): Promise<void> => { - logger.debug(`Searching for project ${projectName}`); res.locals.project = await Project.findOne({ where: { name: projectName @@ -708,6 +708,7 @@ export class FileRouter { ): Promise<void> => { logger.debug(`Searching for file ${fileId}`); const file: File | null = await File.findOne({ + include: [{all: true}], where: { uuid: fileId } @@ -75,6 +75,7 @@ class App { logger.debug('Loading basic middleware'); 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 @@ -38,6 +38,9 @@ export default class UserGroup extends Model<UserGroup> { public canEditProjects!: boolean; @Column + public canAccessLogs!: boolean; + + @Column public isInternal!: boolean; @AllowNull 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..1c80fb2 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 */ @@ -239,8 +241,22 @@ describe('routes : protocol', () => { beforeEach(populateDatabase); beforeEach(getToken); + it('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..12fc17c 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<Credentials> = async( database?: Database, admin?: boolean @@ -55,6 +65,7 @@ export const addUser: (database?: Database, admin?: boolean) => canCreateProjects: true, canDeleteProjects: true, canEditProjects: true, + canAccessLogs: true, isInternal: false }); await priv.save(); @@ -78,3 +89,19 @@ export const addProjec: (database: Database, user: Credentials) => await new Project(mockProject).save(); return mockProject; }; + +export const addFilee: (database: Database, user: Credentials) => + Promise<Filee> = async( + database: Database, user: Credentials +): Promise<Filee> => { + 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 |
