Skip to content

Commit

Permalink
fix: 🐛 Remove Prefix During S3 Image Validation & Fix Infinite Invita…
Browse files Browse the repository at this point in the history
…tion Messages (#234)

* fix: substring s3 prefix from image url in the chat room image exist validation

* fix: infinity message send error handle

* test: remove obj prefix from mock test
  • Loading branch information
psychology50 authored Feb 4, 2025
1 parent dc8c0c2 commit 60ec395
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ private String processRequestImage(String requestImageUrl, Long chatRoomId) {
}

if (requestImageUrl.startsWith(awsS3Adapter.getObjectPrefix())) {
validateExistingImage(requestImageUrl);
var originImageUrl = requestImageUrl.substring(awsS3Adapter.getObjectPrefix().length());

return requestImageUrl.substring(awsS3Adapter.getObjectPrefix().length());
validateExistingImage(originImageUrl);

return originImageUrl;
}

throw new StorageException(StorageErrorCode.INVALID_IMAGE_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void keepExistingImage() {

when(chatRoomService.readChatRoom(CHATROOM_ID)).thenReturn(Optional.of(chatRoom));
when(awsS3Adapter.getObjectPrefix()).thenReturn("https://cdn.test.com/");
when(awsS3Adapter.isObjectExist("https://cdn.test.com/" + ORIGIN_PATH)).thenReturn(true);
when(awsS3Adapter.isObjectExist(ORIGIN_PATH)).thenReturn(true);

ChatRoomReq.Update request = new ChatRoomReq.Update("title", "desc", null, "https://cdn.test.com/" + ORIGIN_PATH);

Expand All @@ -115,7 +115,7 @@ void keepExistingImage() {
// then
verify(awsS3Adapter, never()).deleteImage(anyString());
verify(awsS3Adapter, never()).saveImage(anyString(), any());
verify(awsS3Adapter).isObjectExist("https://cdn.test.com/" + ORIGIN_PATH);
verify(awsS3Adapter).isObjectExist(ORIGIN_PATH);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ChatMessageSendService(
)
}

command.senderName.takeIf { it.isNotBlank() }?.let { senderName ->
command.senderName?.takeIf { it.isNotBlank() }?.let { senderName ->
simpMessagingTemplate.convertAndSendToUser(
senderName,
"/queue/success",
Expand Down

0 comments on commit 60ec395

Please sign in to comment.