Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/routers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { permissionCache } from '../helpers/cache';
import { responseException } from '../exceptions';
import * as Services from '../services/admin';
import { SwitcherKeys } from '../external/switcher-api-facade';
import { checkActionType } from '../models/permission';

const router = new express.Router();

Expand Down Expand Up @@ -101,6 +102,7 @@ router.get('/admin/me', auth, async (req, res) => {
router.post('/admin/collaboration/permission', auth, [
check('domain', 'Domain Id is required').isMongoId(),
check('action', 'Array of actions is required').isArray({ min: 1 }),
check('action.*').custom(async value => checkActionType([value])),
check('router', 'Router name is required').isLength({ min: 1 }),
check('environment').isString().optional()
], validate, async (req, res) => {
Expand All @@ -124,9 +126,9 @@ router.post('/admin/collaboration/permission', auth, [
try {
await verifyOwnership(req.admin, element, req.body.domain, action_perm,
req.body.router, false, req.body.environment);
result.push({ action: action_perm.toString(), result: 'ok' });
result.push({ action: action_perm, result: 'ok' });
} catch (e) {
result.push({ action : action_perm.toString(), result: 'nok' });
result.push({ action : action_perm, result: 'nok' });
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/services/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import mongoose from 'mongoose';
import { response } from './common';
import { Config } from '../models/config';
import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers';
Expand Down Expand Up @@ -258,15 +257,14 @@ export async function removeComponent(id, args, admin) {

export async function updateComponent(id, args, admin) {
const config = await verifyAddComponentInput(id, admin);
const componentIds = args.components.map(component => new mongoose.Types.ObjectId(component));
const components = await getComponents({ _id: { $in: componentIds } });
const components = await getComponents({ _id: { $in: args.components } });

if (components.length != args.components.length) {
throw new NotFoundError('One or more component was not found');
}

config.updatedBy = admin.email;
config.components = componentIds;
config.components = args.components;
await config.save();
updateDomainVersion(config.domain);

Expand Down
16 changes: 16 additions & 0 deletions tests/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,22 @@ describe('Testing Admin collaboration endpoint - Reading permissions', () => {
token = responseLogin.body.jwt.token;
});

test('ADMIN_SUITE - Should NOT read permissions given invalid action request', async () => {
const response = await request(app)
.post('/admin/collaboration/permission')
.set('Authorization', `Bearer ${token}`)
.send({
domain: domainId,
action: ['INVALID_ACTION'],
router: RouterTypes.GROUP,
environment: EnvType.DEFAULT
})
.expect(422);

expect(response.body.errors[0].msg).toEqual(
'Permission validation failed: action: \'INVALID_ACTION\' is not a valid enum value.');
});

test('ADMIN_SUITE - Should read permissions given request - Group', async () => {
const response = await request(app)
.post('/admin/collaboration/permission')
Expand Down
2 changes: 1 addition & 1 deletion tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ describe('Testing component association', () => {
}).expect(200);

// DB validation - document updated
const config = await Config.findById(configId1).exec()
const config = await Config.findById(configId1).exec();
expect(config.components.includes(responseComponent.body.component._id)).toBe(true);
});

Expand Down