VaultSettingsDefaultsTest.kt

2.3 KB · raw

1package com.peachpasswords.vault23import org.junit.Assert.assertEquals4import org.junit.Assert.assertFalse5import org.junit.Assert.assertTrue6import org.junit.Test78/**9 * Gate for the new-install default. The Credential Manager provider is on by10 * default for fresh installs so users get passkey sign-in without having to11 * dig into Settings. Existing users who explicitly disabled it must stay12 * off — the stored value is preserved over the default (see [VaultStore]13 * which falls back to [VaultSettings] only when nothing is on disk).14 */15class VaultSettingsDefaultsTest {1617    @Test fun new_install_default_has_passkey_enabled() {18        assertTrue(19            "first-launch default must enable passkey provider — user said 'q2 is correct'",20            VaultSettings().passkeyProviderEnabled,21        )22    }2324    @Test fun explicitly_disabled_setting_round_trips_through_codec() {25        val original = VaultSettings(passkeyProviderEnabled = false)26        val encoded = VaultCodec.encodeSettings(original)27        val decoded = VaultCodec.decodeSettings(encoded)28        assertEquals(original, decoded)29        assertFalse("explicit off must not be auto-flipped to on by load", decoded!!.passkeyProviderEnabled)30    }3132    @Test fun explicitly_enabled_setting_round_trips_through_codec() {33        val original = VaultSettings(passkeyProviderEnabled = true)34        val encoded = VaultCodec.encodeSettings(original)35        val decoded = VaultCodec.decodeSettings(encoded)36        assertEquals(original, decoded)37    }3839    @Test fun legacy_enabled_favicons_doNotGainConsentByUpgrade() {40        val legacy = VaultCodec.decodeSettings("{\"faviconsEnabled\":true}")!!4142        assertEquals(0, legacy.faviconConsentVersion)43        assertFalse(faviconsAllowed(legacy))44    }4546    @Test fun currentExplicitConsentAllowsEnabledFavicons() {47        val consented = grantCurrentFaviconConsent(VaultSettings())4849        assertTrue(consented.faviconsEnabled)50        assertEquals(CURRENT_FAVICON_CONSENT_VERSION, consented.faviconConsentVersion)51        assertTrue(faviconsAllowed(consented))52    }5354    @Test fun disabledFaviconsStayOffAfterPriorConsent() {55        val disabled = grantCurrentFaviconConsent(VaultSettings()).copy(faviconsEnabled = false)5657        assertFalse(faviconsAllowed(disabled))58    }59}