diff --git a/Control/lib/controllers/Lock.controller.js b/Control/lib/controllers/Lock.controller.js index 3cdc41ae6..e646a5993 100644 --- a/Control/lib/controllers/Lock.controller.js +++ b/Control/lib/controllers/Lock.controller.js @@ -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) { @@ -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 { diff --git a/Control/lib/services/Lock.service.js b/Control/lib/services/Lock.service.js index b937a0f4a..c644597d0 100644 --- a/Control/lib/services/Lock.service.js +++ b/Control/lib/services/Lock.service.js @@ -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; @@ -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(); diff --git a/Control/test/api/lock/api-put-locks.test.js b/Control/test/api/lock/api-put-locks.test.js index f02c5f2e8..ff6f2943b 100644 --- a/Control/test/api/lock/api-put-locks.test.js +++ b/Control/test/api/lock/api-put-locks.test.js @@ -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, }); @@ -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', }); diff --git a/Control/test/lib/controllers/mocha-lock.controller.test.js b/Control/test/lib/controllers/mocha-lock.controller.test.js index 5fb8393ff..b2e6daa52 100644 --- a/Control/test/lib/controllers/mocha-lock.controller.test.js +++ b/Control/test/lib/controllers/mocha-lock.controller.test.js @@ -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', })); @@ -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, })); diff --git a/Control/test/lib/services/mocha-lock.service.test.js b/Control/test/lib/services/mocha-lock.service.test.js index ce740abab..c12015ee2 100644 --- a/Control/test/lib/services/mocha-lock.service.test.js +++ b/Control/test/lib/services/mocha-lock.service.test.js @@ -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') ); }); @@ -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') ); });