Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await Promise.all([
request(app).get('/foo').set('Cookie', cookie).expect(200),
request(app).get('/bar').set('Cookie', cookie).expect(403),
]);
/* Add the admin group and permission */
await createConnection({
database: 'e2e_db.sqlite',
entities: [ User, Permission, Group ],
name: 'perm-connection',
type: 'sqlite',
});
const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
if (!user2) {
throw new Error('John was not found in the database.');
}
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
throw new Error('John was not found in the database.');
}
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
await getRepository(User, 'perm-connection').save(user2);
await getConnection('perm-connection').close();
/* Access the route that requires a specific permission */
await request(app).get('/bar').set('Cookie', cookie).expect(200);
/* Log out */
await request(app).get('/logout').set('Cookie', cookie).expect(204);
/* Try to access routes that require authentication and a specific permission */
await Promise.all([
request(app).get('/foo').expect(401),
request(app).get('/bar').expect(401),
const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
if (!user2) {
throw new Error('John was not found in the database.');
}
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
await getRepository(User, 'perm-connection').save(user2);
await getConnection('perm-connection').close();
/* Access the route that requires a specific permission */
await request(app).get('/bar').set('Cookie', cookie).expect(200);
/* Log out */
await request(app).get('/logout').set('Cookie', cookie).expect(204);
/* Try to access routes that require authentication and a specific permission */
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
await getRepository(User, 'perm-connection').save(user2);
await getConnection('perm-connection').close();
/* Access the route that requires a specific permission */
await request(app).get('/bar').set('Cookie', cookie).expect(200);
/* Log out */
await request(app).get('/logout').set('Cookie', cookie).expect(204);
/* Try to access routes that require authentication and a specific permission */
await Promise.all([
request(app).get('/foo').expect(401),
request(app).get('/bar').expect(401),
]);
await createConnection({
database: 'e2e_db.sqlite',
dropSchema: true,
entities: [ User, Permission, Group ],
name: 'create-connection',
synchronize: true,
type: 'sqlite',
});
const user = new User();
user.email = 'john@foalts.org';
user.password = await hashPassword('password');
await getRepository(User, 'create-connection').save(user);
await getConnection('create-connection').close();
/* Try to access routes that require authentication and a specific permission */
await Promise.all([
request(app).get('/foo').expect(401),
request(app).get('/bar').expect(401),
]);
/* Try to login with a wrong email */
await request(app)
.post('/login')
.send({ email: 'mary@foalts.org', password: 'password' })
.expect(401);
/* Try to login with a wrong password */
entities: [ User, Permission, Group ],
name: 'perm-connection',
type: 'sqlite',
});
const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
if (!user2) {
throw new Error('John was not found in the database.');
}
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
await getRepository(User, 'perm-connection').save(user2);
await getConnection('perm-connection').close();
/* Access the route that requires a specific permission */
await request(app).get('/bar').set('Cookie', cookie).expect(200);
/* Log out */
entities: [ User, Permission, Group ],
name: 'perm-connection',
type: 'sqlite',
});
const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
if (!user2) {
throw new Error('John was not found in the database.');
}
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
await getRepository(User, 'perm-connection').save(user2);
await getConnection('perm-connection').close();
/* Access the route that requires a specific permission */
await request(app).get('/bar').set('Cookie', cookie).expect(200);
/* Log out */
/* Add the admin group and permission */
await createConnection({
database: 'e2e_db.sqlite',
entities: [ User, Permission, Group ],
name: 'perm-connection',
type: 'sqlite',
});
const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
if (!user2) {
throw new Error('John was not found in the database.');
}
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
await getRepository(User, 'perm-connection').save(user2);
await getConnection('perm-connection').close();
/* Access the route that requires a specific permission */
/* Add the admin group and permission */
await createConnection({
database: 'e2e_db.sqlite',
entities: [ User, Permission, Group ],
name: 'perm-connection',
type: 'sqlite',
});
const user2 = await getRepository(User, 'perm-connection').findOne({ email: 'john@foalts.org' });
if (!user2) {
throw new Error('John was not found in the database.');
}
const perm = new Permission();
perm.codeName = 'admin';
perm.name = 'Admin permission';
await getRepository(Permission, 'perm-connection').save(perm);
const group = new Group();
group.name = 'Administrators';
group.codeName = 'administrators';
group.permissions = [ perm ];
await getRepository(Group, 'perm-connection').save(group);
user2.groups = [ group ];
await getRepository(User, 'perm-connection').save(user2);
await getConnection('perm-connection').close();
/* Access the route that requires a specific permission */
properties: {
// To complete
},
required: [ /* To complete */ ],
type: 'object',
};
export class TestFooBarCollection extends EntityResourceCollection {
// tslint:disable-next-line:whitespace
entityClass = TestFooBar;
allowedOperations: EntityResourceCollection['allowedOperations'] = [
'create', 'findById', 'find', 'modifyById', 'updateById', 'deleteById'
];
middlewares = [
middleware('create|modifyById|updateById', ({ data }) => validate(schema, data))
];
}