Skip to content

Commit

Permalink
Refactor connection test case to handle missing master password
Browse files Browse the repository at this point in the history
  • Loading branch information
Artuomka committed Sep 16, 2024
1 parent 887b38d commit e037849
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions backend/src/exceptions/utils/process-exception-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions backend/src/exceptions/utils/processing-messages-find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
2 changes: 2 additions & 0 deletions backend/src/exceptions/utils/processing-messages-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
};

0 comments on commit e037849

Please sign in to comment.