From e0378494358f7bfcb530de3282f527bf1387575b Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Mon, 16 Sep 2024 13:33:07 +0000 Subject: [PATCH] Refactor connection test case to handle missing master password --- .../connection/use-cases/test-connection.use.case.ts | 10 +++++++++- .../src/exceptions/utils/process-exception-message.ts | 2 ++ .../src/exceptions/utils/processing-messages-find.ts | 1 + .../exceptions/utils/processing-messages-replace.ts | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/backend/src/entities/connection/use-cases/test-connection.use.case.ts b/backend/src/entities/connection/use-cases/test-connection.use.case.ts index 55e073402..a570c385a 100644 --- a/backend/src/entities/connection/use-cases/test-connection.use.case.ts +++ b/backend/src/entities/connection/use-cases/test-connection.use.case.ts @@ -41,8 +41,16 @@ export class TestConnectionUseCase update_info: { connectionId, masterPwd }, connection_parameters: connectionData, } = inputData; + const foundConnection = await this._dbContext.connectionRepository.findOne({ + where: { id: connectionId }, + }); + if (foundConnection.masterEncryption && !masterPwd) { + return { + result: false, + message: Messages.MASTER_PASSWORD_MISSING, + }; + } if (connectionId) { - let toUpdate; try { toUpdate = await this._dbContext.connectionRepository.findAndDecryptConnection(connectionId, masterPwd); diff --git a/backend/src/exceptions/utils/process-exception-message.ts b/backend/src/exceptions/utils/process-exception-message.ts index 50d5e5b99..67bffe60d 100644 --- a/backend/src/exceptions/utils/process-exception-message.ts +++ b/backend/src/exceptions/utils/process-exception-message.ts @@ -28,6 +28,8 @@ export function processExceptionMessage(message: string): string { return PROCESSING_MESSAGES_REPLACE.VIOLATES_FOREIGN_CONSTRAINT_MSSQL(msgInLowerCase); case msgInLowerCase.includes(PROCESSING_MESSAGES_FIND.SELECT_COMMAND_DENIED_MYSQL): return PROCESSING_MESSAGES_REPLACE.SELECT_COMMAND_DENIED_MYSQL(msgInLowerCase); + case msgInLowerCase.includes(PROCESSING_MESSAGES_FIND.Malformed_UTF_data): + return PROCESSING_MESSAGES_REPLACE.Malformed_UTF_data; default: return message; } diff --git a/backend/src/exceptions/utils/processing-messages-find.ts b/backend/src/exceptions/utils/processing-messages-find.ts index 2c97f4392..0a0cc6e9a 100644 --- a/backend/src/exceptions/utils/processing-messages-find.ts +++ b/backend/src/exceptions/utils/processing-messages-find.ts @@ -13,4 +13,5 @@ export const PROCESSING_MESSAGES_FIND = { VIOLATES_FOREIGN_CONSTRAINT_MYSQL: 'cannot delete or update a parent row: a foreign key constraint fails', VIOLATES_FOREIGN_CONSTRAINT_MSSQL: 'statement conflicted with the reference constraint', SELECT_COMMAND_DENIED_MYSQL: 'select command denied to user', + Malformed_UTF_data: 'malformed utf-8 data', }; diff --git a/backend/src/exceptions/utils/processing-messages-replace.ts b/backend/src/exceptions/utils/processing-messages-replace.ts index 5e246fc67..fd3fd70dc 100644 --- a/backend/src/exceptions/utils/processing-messages-replace.ts +++ b/backend/src/exceptions/utils/processing-messages-replace.ts @@ -70,4 +70,6 @@ export const PROCESSING_MESSAGES_REPLACE = { `; return message; }, + + Malformed_UTF_data: 'Failed to decrypt connection. Please check that master password is correct.', };