Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: images form iOS are blocked when restrictions are applied [WPB-10830] 🍒 #3010

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -361,8 +361,7 @@ class AssetMessageHandlerTest {
coVerify { arrangement.messageRepository.getMessageById(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id)) }
.wasNotInvoked()

coVerify { arrangement.validateAssetMimeType(any<String>(), any<String>(), any<List<String>>()) }
.wasNotInvoked()
coVerify { arrangement.validateAssetFileTypeUseCase(any<String>(), any<String>(), any<List<String>>()) }
}

@Test
Expand Down Expand Up @@ -396,6 +395,7 @@ class AssetMessageHandlerTest {
val (arrangement, assetMessageHandler) = Arrangement()
.withSuccessfulFileSharingFlag(isFileSharingEnabled)
.withSuccessfulStoredMessage(previewAssetMessage)
.withValidateAssetFileType(true)
.arrange()

// When
Expand Down Expand Up @@ -440,6 +440,7 @@ class AssetMessageHandlerTest {
.withSuccessfulFileSharingFlag(isFileSharingEnabled)
.withSuccessfulStoredMessage(null)
.withSuccessfulPersistMessageUseCase(storedMessage)
.withValidateAssetFileType(true)
.arrange()

// When
Expand All @@ -465,14 +466,14 @@ class AssetMessageHandlerTest {
val userConfigRepository = mock(UserConfigRepository::class)

@Mock
val validateAssetMimeType = mock(ValidateAssetFileTypeUseCase::class)
val validateAssetFileTypeUseCase = mock(classOf<ValidateAssetFileTypeUseCase>())

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)
}

Expand Down
Loading