[PM-44810] fix: Ignore "Vault Items" send type parsing [bug-factory poc] (#7488)

Co-authored-by: bug-factory <bug-factory@bitwarden.com>
This commit is contained in:
André Bispo
2026-10-23 13:53:35 +00:00
committed by GitHub
co-authored by bug-factory
parent 69fa0814c8
commit 928ec4830e
3 changed files with 67 additions and 1 deletions
@@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.auth.repository.model
import com.bitwarden.network.model.SendAccessTypeJson
import com.bitwarden.network.model.SendTypeJson
import com.bitwarden.network.model.SyncResponseJson
import kotlinx.serialization.Contextual
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@@ -128,7 +129,8 @@ sealed class PolicyInformation {
* when [whoCanAccess] is [SendAccessTypeJson.SPECIFIC_PEOPLE].
* @property deletionHours The number of hours until a Send is deleted, if enforced.
* @property allowedSendTypes The types of Sends that are allowed to be created, if
* restricted.
* restricted. Send types unknown to this client are dropped rather than failing the decode of
* the whole policy.
*/
@Serializable
data class SendControls(
@@ -147,6 +149,7 @@ sealed class PolicyInformation {
@SerialName("deletionHours")
val deletionHours: Int?,
@Contextual
@SerialName("allowedSendTypes")
val allowedSendTypes: List<SendTypeJson>?,
) : PolicyInformation()
@@ -1,5 +1,6 @@
package com.x8bit.bitwarden.data.auth.repository.util
import com.bitwarden.core.data.serializer.SafeListSerializer
import com.bitwarden.core.data.util.decodeFromStringOrNull
import com.bitwarden.network.model.MemberDecryptionType
import com.bitwarden.network.model.OrganizationStatusType
@@ -23,6 +24,7 @@ import com.bitwarden.policies.PolicyType
import com.x8bit.bitwarden.data.auth.repository.model.Organization
import com.x8bit.bitwarden.data.auth.repository.model.PolicyInformation
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule
import com.bitwarden.organizations.MemberDecryptionType as SdkMemberDecryptionType
import com.bitwarden.organizations.ProductTierType as SdkProductTierType
import com.bitwarden.organizations.ProviderType as SdkProviderType
@@ -30,6 +32,9 @@ import com.bitwarden.organizations.ProviderType as SdkProviderType
private val JSON = Json {
ignoreUnknownKeys = true
explicitNulls = false
serializersModule = SerializersModule {
contextual(List::class) { args -> SafeListSerializer(args.first()) }
}
}
/**
@@ -207,6 +207,64 @@ class SyncResponseJsonExtensionsTest {
)
}
@Test
fun `policyInformation drops unknown allowedSendTypes and keeps the SendControls policy`() {
val policy = createMockSdkPolicy(
type = PolicyType.SEND_CONTROLS,
data = """
{
"disableSend": false,
"disableHideEmail": true,
"whoCanAccess": 2,
"allowedDomains": "bitwarden.com",
"deletionHours": 168,
"allowedSendTypes": [0, 2]
}
""".trimIndent(),
)
assertEquals(
PolicyInformation.SendControls(
disableSend = false,
disableHideEmail = true,
whoCanAccess = SendAccessTypeJson.SPECIFIC_PEOPLE,
allowedDomains = "bitwarden.com",
deletionHours = 168,
allowedSendTypes = listOf(SendTypeJson.TEXT),
),
policy.policyInformation,
)
}
@Test
fun `policyInformation maps allowedSendTypes with only unknown types to an empty list`() {
val policy = createMockSdkPolicy(
type = PolicyType.SEND_CONTROLS,
data = """
{
"disableSend": false,
"disableHideEmail": true,
"whoCanAccess": 2,
"allowedDomains": "bitwarden.com",
"deletionHours": 168,
"allowedSendTypes": [2]
}
""".trimIndent(),
)
assertEquals(
PolicyInformation.SendControls(
disableSend = false,
disableHideEmail = true,
whoCanAccess = SendAccessTypeJson.SPECIFIC_PEOPLE,
allowedDomains = "bitwarden.com",
deletionHours = 168,
allowedSendTypes = emptyList(),
),
policy.policyInformation,
)
}
@Test
@Suppress("MaxLineLength")
fun `policyInformation converts the OrganizationUserNotification Json data to policy information`() {