mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
Add PolicyInformation data structure (#846)
This commit is contained in:
committed by
Álison Fernandes
parent
91207df3fa
commit
39e37eb7c7
+49
@@ -1,8 +1,15 @@
|
||||
package com.x8bit.bitwarden.data.auth.repository.util
|
||||
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.Organization
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.PolicyInformation
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.PolicyTypeJson
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockOrganization
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockPolicy
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.put
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class SyncResponseJsonExtensionsTest {
|
||||
@@ -37,4 +44,46 @@ class SyncResponseJsonExtensionsTest {
|
||||
.toOrganizations(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
fun `policyInformation converts the Json data to policy information`() {
|
||||
val masterPasswordData = buildJsonObject {
|
||||
put(key = "minLength", value = 10)
|
||||
put(key = "minComplexity", value = 3)
|
||||
put(key = "requireUpper", value = null)
|
||||
put(key = "requireLower", value = null)
|
||||
put(key = "requireNumbers", value = true)
|
||||
put(key = "requireSpecial", value = null)
|
||||
put(key = "enforceOnLogin", value = true)
|
||||
}
|
||||
val masterPasswordPolicy = createMockPolicy(
|
||||
type = PolicyTypeJson.MASTER_PASSWORD,
|
||||
data = masterPasswordData,
|
||||
)
|
||||
val policyInformation = PolicyInformation.MasterPassword(
|
||||
minLength = 10,
|
||||
minComplexity = 3,
|
||||
requireUpper = null,
|
||||
requireLower = null,
|
||||
requireNumbers = true,
|
||||
requireSpecial = null,
|
||||
enforceOnLogin = true,
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
policyInformation,
|
||||
masterPasswordPolicy.policyInformation,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `policyInformation returns null policy information for null data`() {
|
||||
val masterPasswordPolicy = createMockPolicy(
|
||||
type = PolicyTypeJson.MASTER_PASSWORD,
|
||||
data = null,
|
||||
)
|
||||
|
||||
assertNull(masterPasswordPolicy.policyInformation)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -1,12 +1,19 @@
|
||||
package com.x8bit.bitwarden.data.vault.datasource.network.model
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
/**
|
||||
* Create a mock [SyncResponseJson.Policy] with a given [number].
|
||||
* Create a mock [SyncResponseJson.Policy] with the given [number], [type], and [data].
|
||||
*/
|
||||
fun createMockPolicy(number: Int): SyncResponseJson.Policy =
|
||||
fun createMockPolicy(
|
||||
number: Int = 1,
|
||||
type: PolicyTypeJson = PolicyTypeJson.MASTER_PASSWORD,
|
||||
data: JsonObject? = null,
|
||||
): SyncResponseJson.Policy =
|
||||
SyncResponseJson.Policy(
|
||||
organizationId = "mockOrganizationId-$number",
|
||||
id = "mockId-$number",
|
||||
type = PolicyTypeJson.MASTER_PASSWORD,
|
||||
type = type,
|
||||
isEnabled = false,
|
||||
data = data,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user