Skip to content

Commit

Permalink
fix: images form iOS are blocked when restrictions are applied [WPB-1…
Browse files Browse the repository at this point in the history
…0830] πŸ’ πŸ’ (#3016)

* Commit with unresolved merge conflicts

* fix merge conflicts

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Mohamad Jaara <[email protected]>
  • Loading branch information
github-actions[bot] and MohamadJaara authored Sep 25, 2024
1 parent 597cdec commit ee5615f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
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 @@ -251,7 +251,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 +276,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 +295,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 +322,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 +338,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,7 +360,14 @@ class AssetMessageHandlerTest {
coVerify { arrangement.messageRepository.getMessageById(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id)) }
.wasNotInvoked()

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

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

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

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

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

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

0 comments on commit ee5615f

Please sign in to comment.