ImportSettingsClassificationTest.kt

1.8 KB · raw

1package com.peachpasswords.vault23import org.junit.Assert.assertEquals4import org.junit.Assert.assertFalse5import org.junit.Test67/**8 * PB-26-118: a PeachScript backup carries a settings record, and importing one9 * used to apply the whole record — including the screen-capture control and the10 * favicon consent flag, which the app elsewhere obtains only from the user.11 *12 * The two lists are the classification. This pins them so a new setting cannot13 * be added without deciding which side it belongs on.14 */15class ImportSettingsClassificationTest {1617    @Test18    fun every_settings_field_is_classified() {19        val declared = VaultSettings::class.java.declaredFields20            .map { it.name }21            .filterNot { it.startsWith("$") || it == "Companion" }22            .toSet()23        val classified = (IMPORT_PRESENTATION_FIELDS + IMPORT_SECURITY_POLICY_FIELDS).toSet()2425        assertEquals(26            "every VaultSettings field must be presentation-data or security-policy",27            declared,28            classified,29        )30    }3132    @Test33    fun an_imported_file_cannot_change_capture_or_consent_policy() {34        val local = VaultSettings(allowScreenshots = false, faviconsEnabled = false, faviconConsentVersion = 0)35        val hostile = VaultSettings(36            accentColor = "plum",37            allowScreenshots = true,38            faviconsEnabled = true,39            faviconConsentVersion = 1,40        )4142        val applied = applyImportedPresentationSettings(local, hostile)4344        assertEquals("presentation settings still transfer", "plum", applied.accentColor)45        assertFalse("capture protection is local policy", applied.allowScreenshots)46        assertFalse("third-party icon egress is local policy", applied.faviconsEnabled)47        assertEquals(0, applied.faviconConsentVersion)48    }49}