diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/model/PolicyInformation.kt b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/model/PolicyInformation.kt index dd2802e231..07298df0de 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/model/PolicyInformation.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/data/auth/repository/model/PolicyInformation.kt @@ -1,5 +1,6 @@ package com.x8bit.bitwarden.data.auth.repository.model +import com.bitwarden.core.data.serializer.SafeListSerializer import com.bitwarden.network.model.SendAccessTypeJson import com.bitwarden.network.model.SendTypeJson import com.bitwarden.network.model.SyncResponseJson @@ -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?, + @Serializable(with = SafeListSerializer::class) @SerialName("allowedSendTypes") val allowedSendTypes: List?, ) : PolicyInformation() diff --git a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/SyncResponseJsonExtensionsTest.kt b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/SyncResponseJsonExtensionsTest.kt index aab078a8ea..2ac6f41c71 100644 --- a/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/SyncResponseJsonExtensionsTest.kt +++ b/app/src/test/kotlin/com/x8bit/bitwarden/data/auth/repository/util/SyncResponseJsonExtensionsTest.kt @@ -195,6 +195,36 @@ class SyncResponseJsonExtensionsTest { ) } + @Test + @Suppress("MaxLineLength") + fun `policyInformation drops unknown allowedSendTypes and keeps the rest of 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 @Suppress("MaxLineLength") fun `policyInformation converts the OrganizationUserNotification Json data to policy information`() {