diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt index 3bc9fa7ac2e..b99adccea0e 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandler.kt @@ -60,23 +60,18 @@ internal class AssetMessageHandlerImpl( // asset data then we can not decide now if it is allowed or not // it is safe to continue and the code later will check the original // asset message and decide if it is allowed or not - if ( - messageContent.value.name.isNullOrEmpty() && - messageContent.value.isAssetDataComplete - ) { - kaliumLogger.e("The asset message trying to be processed has invalid data looking locally") - AssetRestrictionContinuationStrategy.RestrictIfThereIsNotOldMessageWithTheSameAssetID - } else { - validateAssetMimeTypeUseCase( + if (validateAssetMimeTypeUseCase( fileName = messageContent.value.name, mimeType = messageContent.value.mimeType, allowedExtension = it.state.allowedType - ).let { validateResult -> - if (validateResult) { - AssetRestrictionContinuationStrategy.Continue - } else { - AssetRestrictionContinuationStrategy.Restrict - } + ) + ) { + AssetRestrictionContinuationStrategy.Continue + } else { + if (messageContent.value.name.isNullOrEmpty() && messageContent.value.isAssetDataComplete) { + AssetRestrictionContinuationStrategy.RestrictIfThereIsNotOldMessageWithTheSameAssetID + } else { + AssetRestrictionContinuationStrategy.Restrict } } } diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt index 64b4db40220..fae069d2613 100644 --- a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/sync/receiver/asset/AssetMessageHandlerTest.kt @@ -36,6 +36,7 @@ import com.wire.kalium.logic.functional.Either import com.wire.kalium.util.time.UNIX_FIRST_DATE import io.mockative.Mock import io.mockative.any +import io.mockative.classOf import io.mockative.coEvery import io.mockative.coVerify import io.mockative.eq @@ -251,7 +252,7 @@ class AssetMessageHandlerTest { val isFileSharingEnabled = FileSharingStatus.Value.EnabledSome(listOf("txt", "png", "zip")) val (arrangement, assetMessageHandler) = Arrangement() .withSuccessfulFileSharingFlag(isFileSharingEnabled) - .withValidateAssetMime(true) + .withValidateAssetFileType(true) .withSuccessfulStoredMessage(previewAssetMessage) .withSuccessfulPersistMessageUseCase(updateAssetMessage) .arrange() @@ -276,11 +277,10 @@ class AssetMessageHandlerTest { eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id) ) - } - .wasInvoked(exactly = once) + }.wasInvoked(exactly = once) coVerify { - arrangement.validateAssetMimeType( + arrangement.validateAssetFileTypeUseCase( fileName = eq(COMPLETE_ASSET_CONTENT.value.name), mimeType = eq("application/zip"), allowedExtension = eq(isFileSharingEnabled.allowedType) @@ -296,7 +296,7 @@ class AssetMessageHandlerTest { val isFileSharingEnabled = FileSharingStatus.Value.EnabledSome(listOf("txt", "png")) val (arrangement, assetMessageHandler) = Arrangement() .withSuccessfulFileSharingFlag(isFileSharingEnabled) - .withValidateAssetMime(true) + .withValidateAssetFileType(true) .withSuccessfulStoredMessage(previewAssetMessage) .withSuccessfulPersistMessageUseCase(updateAssetMessage) .arrange() @@ -323,7 +323,7 @@ class AssetMessageHandlerTest { }.wasInvoked(exactly = once) coVerify { - arrangement.validateAssetMimeType( + arrangement.validateAssetFileTypeUseCase( fileName = eq(COMPLETE_ASSET_CONTENT.value.name), mimeType = eq("application/zip"), allowedExtension = eq(isFileSharingEnabled.allowedType) @@ -339,7 +339,7 @@ class AssetMessageHandlerTest { val isFileSharingEnabled = FileSharingStatus.Value.Disabled val (arrangement, assetMessageHandler) = Arrangement() .withSuccessfulFileSharingFlag(isFileSharingEnabled) - .withValidateAssetMime(true) + .withValidateAssetFileType(true) .withSuccessfulStoredMessage(previewAssetMessage) .withSuccessfulPersistMessageUseCase(updateAssetMessage) .arrange() @@ -361,8 +361,7 @@ class AssetMessageHandlerTest { coVerify { arrangement.messageRepository.getMessageById(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id)) } .wasNotInvoked() - coVerify { arrangement.validateAssetMimeType(any(), any(), any>()) } - .wasNotInvoked() + coVerify { arrangement.validateAssetFileTypeUseCase(any(), any(), any>()) } } @Test @@ -396,6 +395,7 @@ class AssetMessageHandlerTest { val (arrangement, assetMessageHandler) = Arrangement() .withSuccessfulFileSharingFlag(isFileSharingEnabled) .withSuccessfulStoredMessage(previewAssetMessage) + .withValidateAssetFileType(true) .arrange() // When @@ -440,6 +440,7 @@ class AssetMessageHandlerTest { .withSuccessfulFileSharingFlag(isFileSharingEnabled) .withSuccessfulStoredMessage(null) .withSuccessfulPersistMessageUseCase(storedMessage) + .withValidateAssetFileType(true) .arrange() // When @@ -465,14 +466,14 @@ class AssetMessageHandlerTest { val userConfigRepository = mock(UserConfigRepository::class) @Mock - val validateAssetMimeType = mock(ValidateAssetFileTypeUseCase::class) + val validateAssetFileTypeUseCase = mock(classOf()) private val assetMessageHandlerImpl = - AssetMessageHandlerImpl(messageRepository, persistMessage, userConfigRepository, validateAssetMimeType) + AssetMessageHandlerImpl(messageRepository, persistMessage, userConfigRepository, validateAssetFileTypeUseCase) - fun withValidateAssetMime(result: Boolean) = apply { + fun withValidateAssetFileType(result: Boolean) = apply { every { - validateAssetMimeType.invoke(any(), any(), any()) + validateAssetFileTypeUseCase.invoke(any(), any(), any()) }.returns(result) }