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: 3 additions & 3 deletions Control/lib/controllers/Lock.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ class LockController {
try {
this._lockService.takeLock(detector, user, shouldForce);
} catch (error) {
console.error(error);
this._logger.errorMessage(error, {level: LogLevel.DEVELOPER, facility: LOG_FACILITY});
}
});
} else {
this._lockService.takeLock(detectorId, user, shouldForce);
}
}
res.status(200).json(this._lockService.locksByDetectorToJSON());
} else if (action.toLocaleUpperCase() === DetectorLockAction.RELEASE) {
if (detectorId === DetectorId.ALL) {
Expand All @@ -92,7 +92,7 @@ class LockController {
try {
this._lockService.releaseLock(detector, user, shouldForce);
} catch (error) {
console.error(error);
this._logger.errorMessage(error, {level: LogLevel.DEVELOPER, facility: LOG_FACILITY});
}
});
} else {
Expand Down
10 changes: 4 additions & 6 deletions Control/lib/services/Lock.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ class LockService {
throw new NotFoundError(`Detector ${detectorName} not found in the list of detectors`);
} else if (lock.isTaken()) {
if (!lock.isOwnedBy(user) && !shouldForce) {
throw new UnauthorizedAccessError(
`Unauthorized TAKE action for lock of detector ${detectorName} by user ${user.fullName}`
);
throw new UnauthorizedAccessError(`Unauthorized TAKE action for lock ${detectorName} `
+ `by ${ user.fullName } while lock is held by ${ lock.owner.fullName }`);
}
if (lock.isOwnedBy(user)) {
return this._locksByDetector;
Expand Down Expand Up @@ -117,9 +116,8 @@ class LockService {
} else if (lock.isFree()) {
return this._locksByDetector;
} else if (!lock.isOwnedBy(user) && !shouldForce) {
throw new UnauthorizedAccessError(
`Unauthorized RELEASE action for lock of detector ${detectorName} by user ${user.fullName}`
);
throw new UnauthorizedAccessError(`Unauthorized RELEASE action for lock ${detectorName} `
+ `by ${ user.fullName } while lock is held by ${ lock.owner.fullName }`);
}
this._locksByDetector[detectorName].release();

Expand Down
4 changes: 2 additions & 2 deletions Control/test/api/lock/api-put-locks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe(`'API - PUT - /locks/:action/:detectorId' test suite`, () => {
await request(`${TEST_URL}/api/locks`)
.put(`/${DetectorLockAction.TAKE}/MID?token=${ADMIN_TEST_TOKEN}`)
.expect(403, {
message: 'Unauthorized TAKE action for lock of detector MID by user Admin User',
message: 'Unauthorized TAKE action for lock MID by Admin User while lock is held by Global User',
title: 'Unauthorized Access',
status: 403,
});
Expand Down Expand Up @@ -172,7 +172,7 @@ describe(`'API - PUT - /locks/:action/:detectorId' test suite`, () => {
await request(`${TEST_URL}/api/locks`)
.put(`/${DetectorLockAction.RELEASE}/MID?token=${DET_MID_TEST_TOKEN}`)
.expect(403, {
message: 'Unauthorized RELEASE action for lock of detector MID by user Detector User',
message: 'Unauthorized RELEASE action for lock MID by Detector User while lock is held by Admin User',
status: 403,
title: 'Unauthorized Access',
});
Expand Down
4 changes: 2 additions & 2 deletions Control/test/lib/controllers/mocha-lock.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe(`'LockController' test suite`, () => {
}, res);
assert.ok(res.status.calledWith(403));
assert.ok(res.json.calledWith({
message: 'Unauthorized TAKE action for lock of detector ABC by user NotAnonymous',
message: 'Unauthorized TAKE action for lock ABC by NotAnonymous while lock is held by Anonymous',
status: 403,
title: 'Unauthorized Access',
}));
Expand All @@ -134,7 +134,7 @@ describe(`'LockController' test suite`, () => {
}, res);
assert.ok(res.status.calledWith(403));
assert.ok(res.json.calledWith({
message: 'Unauthorized RELEASE action for lock of detector ABC by user NotAnonymous',
message: 'Unauthorized RELEASE action for lock ABC by NotAnonymous while lock is held by Anonymous',
title: 'Unauthorized Access',
status: 403,
}));
Expand Down
4 changes: 2 additions & 2 deletions Control/test/lib/services/mocha-lock.service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe(`'LockService' test suite`, () => {
it('should throw error when a user attempts to take a lock that is already held by another user', () => {
assert.throws(
() => lockService.takeLock('ABC', userB),
new UnauthorizedAccessError(`Unauthorized TAKE action for lock of detector ABC by user userB`)
new UnauthorizedAccessError('Unauthorized TAKE action for lock ABC by userB while lock is held by userA')
);
});

Expand Down Expand Up @@ -98,7 +98,7 @@ describe(`'LockService' test suite`, () => {
lockService.takeLock('ABC', userA);
assert.throws(
() => lockService.releaseLock('ABC', userB),
new UnauthorizedAccessError(`Unauthorized RELEASE action for lock of detector ABC by user userB`)
new UnauthorizedAccessError('Unauthorized RELEASE action for lock ABC by userB while lock is held by userA')
);
});

Expand Down
Loading