Skip to content

Commit

Permalink
Commit with unresolved merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara authored and github-actions[bot] committed Sep 13, 2024
1 parent 987b782 commit 94a6a38
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,33 @@ internal class AssetMessageHandlerImpl(
FileSharingStatus.Value.Disabled -> false
FileSharingStatus.Value.EnabledAll -> true

<<<<<<< HEAD
is FileSharingStatus.Value.EnabledSome -> validateAssetMimeTypeUseCase(
messageContent.value.name,
it.state.allowedType
)
=======
is FileSharingStatus.Value.EnabledSome -> {
// If the asset message is missing the name, but it does have full
// 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 (validateAssetMimeTypeUseCase(
fileName = messageContent.value.name,
mimeType = messageContent.value.mimeType,
allowedExtension = it.state.allowedType
)
) {
AssetRestrictionContinuationStrategy.Continue
} else {
if (messageContent.value.name.isNullOrEmpty() && messageContent.value.isAssetDataComplete) {
AssetRestrictionContinuationStrategy.RestrictIfThereIsNotOldMessageWithTheSameAssetID
} else {
AssetRestrictionContinuationStrategy.Restrict
}
}
}
>>>>>>> 28a9dc301b (fix: images form iOS are blocked when restrictions are applied (#3006))
}

if (isThisAssetAllowed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ import com.wire.kalium.logic.functional.Either
import com.wire.kalium.util.time.UNIX_FIRST_DATE
import io.mockative.Mock
import io.mockative.any
<<<<<<< HEAD
import io.mockative.coEvery
import io.mockative.coVerify
=======
import io.mockative.anything
import io.mockative.classOf
>>>>>>> 28a9dc301b (fix: images form iOS are blocked when restrictions are applied (#3006))
import io.mockative.eq
import io.mockative.every
import io.mockative.matches
Expand Down Expand Up @@ -251,7 +256,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 @@ -274,7 +279,18 @@ class AssetMessageHandlerTest {
coVerify { arrangement.messageRepository.getMessageById(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id)) }
.wasInvoked(exactly = once)

<<<<<<< HEAD
coVerify { arrangement.validateAssetMimeType(eq(COMPLETE_ASSET_CONTENT.value.name), eq(isFileSharingEnabled.allowedType)) }
=======
verify(arrangement.messageRepository)
.suspendFunction(arrangement.messageRepository::getMessageById)
.with(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id))
.wasInvoked(exactly = once)

verify(arrangement.validateAssetFileTypeUseCase)
.suspendFunction(arrangement.validateAssetFileTypeUseCase::invoke)
.with(eq(COMPLETE_ASSET_CONTENT.value.name), eq("application/zip"), eq(isFileSharingEnabled.allowedType))
>>>>>>> 28a9dc301b (fix: images form iOS are blocked when restrictions are applied (#3006))
.wasInvoked(exactly = once)
}

Expand All @@ -286,7 +302,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 @@ -308,7 +324,18 @@ class AssetMessageHandlerTest {
coVerify { arrangement.messageRepository.getMessageById(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id)) }
.wasInvoked(exactly = once)

<<<<<<< HEAD
coVerify { arrangement.validateAssetMimeType(eq(COMPLETE_ASSET_CONTENT.value.name), eq(isFileSharingEnabled.allowedType)) }
=======
verify(arrangement.messageRepository)
.suspendFunction(arrangement.messageRepository::getMessageById)
.with(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id))
.wasInvoked(exactly = once)

verify(arrangement.validateAssetFileTypeUseCase)
.suspendFunction(arrangement.validateAssetFileTypeUseCase::invoke)
.with(eq(COMPLETE_ASSET_CONTENT.value.name), eq("application/zip"), eq(isFileSharingEnabled.allowedType))
>>>>>>> 28a9dc301b (fix: images form iOS are blocked when restrictions are applied (#3006))
.wasInvoked(exactly = once)
}

Expand All @@ -320,7 +347,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 @@ -342,10 +369,118 @@ class AssetMessageHandlerTest {
coVerify { arrangement.messageRepository.getMessageById(eq(previewAssetMessage.conversationId), eq(previewAssetMessage.id)) }
.wasNotInvoked()

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

=======
verify(arrangement.validateAssetFileTypeUseCase)
.suspendFunction(arrangement.validateAssetFileTypeUseCase::invoke)
.with(any<String>(), any<List<String>>())
.wasNotInvoked()
}

@Test
fun givenFileWithNullNameAndCompleteData_whenProcessingCheckAPreviousAssetWithTheSameIDIsRestricted_thenDoNotStore() = runTest {
// Given
val messageCOntant = MessageContent.Asset(
AssetContent(
sizeInBytes = 100,
name = null,
mimeType = "",
metadata = null,
remoteData = AssetContent.RemoteData(
otrKey = "otrKey".toByteArray(),
sha256 = "sha256".toByteArray(),
assetId = "some-asset-id",
assetDomain = "some-asset-domain",
assetToken = "some-asset-token",
encryptionAlgorithm = MessageEncryptionAlgorithm.AES_GCM
),
uploadStatus = Message.UploadStatus.NOT_UPLOADED,
downloadStatus = Message.DownloadStatus.NOT_DOWNLOADED
)

)
val assetMessage = COMPLETE_ASSET_MESSAGE.copy(content = messageCOntant)

val previewAssetMessage = PREVIEW_ASSET_MESSAGE.copy(
visibility = Message.Visibility.HIDDEN,
content = MessageContent.RestrictedAsset("application/zip", 500, "some-asset-name.zip.")
)

val isFileSharingEnabled = FileSharingStatus.Value.EnabledSome(listOf("txt", "png", "zip"))
val (arrangement, assetMessageHandler) = Arrangement()
.withSuccessfulFileSharingFlag(isFileSharingEnabled)
.withSuccessfulStoredMessage(previewAssetMessage)
.withValidateAssetFileType(true)
.arrange()

// When
assetMessageHandler.handle(assetMessage)

// Then
verify(arrangement.persistMessage)
.suspendFunction(arrangement.persistMessage::invoke)
.with(any())
.wasNotInvoked()

verify(arrangement.messageRepository)
.suspendFunction(arrangement.messageRepository::getMessageById)
.with(eq(assetMessage.conversationId), eq(assetMessage.id))
.wasInvoked(exactly = once)
}

@Test
fun givenFileWithNullNameAndCompleteData_whenProcessingCheckAPreviousAssetWithTheSameIDIsMissing_thenStoreAsRestricted() = runTest {
// Given
val messageCOntant = MessageContent.Asset(
AssetContent(
sizeInBytes = 100,
name = null,
mimeType = "",
metadata = null,
remoteData = AssetContent.RemoteData(
otrKey = "otrKey".toByteArray(),
sha256 = "sha256".toByteArray(),
assetId = "some-asset-id",
assetDomain = "some-asset-domain",
assetToken = "some-asset-token",
encryptionAlgorithm = MessageEncryptionAlgorithm.AES_GCM
),
uploadStatus = Message.UploadStatus.NOT_UPLOADED,
downloadStatus = Message.DownloadStatus.NOT_DOWNLOADED
)

)
val assetMessage = COMPLETE_ASSET_MESSAGE.copy(content = messageCOntant)

val storedMessage = assetMessage.copy(content = MessageContent.RestrictedAsset(mimeType = "", sizeInBytes = 100, name = ""))
val isFileSharingEnabled = FileSharingStatus.Value.EnabledSome(listOf("txt", "png", "zip"))
val (arrangement, assetMessageHandler) = Arrangement()
.withSuccessfulFileSharingFlag(isFileSharingEnabled)
.withSuccessfulStoredMessage(null)
.withSuccessfulPersistMessageUseCase(storedMessage)
.withValidateAssetFileType(true)
.arrange()

// When
assetMessageHandler.handle(assetMessage)

// Then
verify(arrangement.persistMessage)
.suspendFunction(arrangement.persistMessage::invoke)
.with(any())
.wasInvoked(exactly = once)

verify(arrangement.messageRepository)
.suspendFunction(arrangement.messageRepository::getMessageById)
.with(eq(assetMessage.conversationId), eq(assetMessage.id))
.wasInvoked(exactly = once)
}

>>>>>>> 28a9dc301b (fix: images form iOS are blocked when restrictions are applied (#3006))
private class Arrangement {

@Mock
Expand All @@ -358,15 +493,27 @@ class AssetMessageHandlerTest {
val userConfigRepository = mock(UserConfigRepository::class)

@Mock
<<<<<<< HEAD
val validateAssetMimeType = mock(ValidateAssetFileTypeUseCase::class)
=======
val validateAssetFileTypeUseCase = mock(classOf<ValidateAssetFileTypeUseCase>())
>>>>>>> 28a9dc301b (fix: images form iOS are blocked when restrictions are applied (#3006))

private val assetMessageHandlerImpl =
AssetMessageHandlerImpl(messageRepository, persistMessage, userConfigRepository, validateAssetMimeType)
AssetMessageHandlerImpl(messageRepository, persistMessage, userConfigRepository, validateAssetFileTypeUseCase)

<<<<<<< HEAD
fun withValidateAssetMime(result: Boolean) = apply {
every {
validateAssetMimeType.invoke(any(), any())
}.returns(result)
=======
fun withValidateAssetFileType(result: Boolean) = apply {
given(validateAssetFileTypeUseCase)
.function(validateAssetFileTypeUseCase::invoke)
.whenInvokedWith(anything(), any(), any())
.thenReturn(result)
>>>>>>> 28a9dc301b (fix: images form iOS are blocked when restrictions are applied (#3006))
}

fun withSuccessfulFileSharingFlag(value: FileSharingStatus.Value) = apply {
Expand Down

0 comments on commit 94a6a38

Please sign in to comment.