24a5f0ba28fb

test: Navigation flow + Security properties — NavigationFlowTest 11 (route construction, onboarding gate, list-tap, post-unlock) + SecurityPropertiesTest 8 (key null after lock, entries cleared, duress opens decoy not real, panic wipe + decoy clear, no-escrow recovery); v2.2.6 (357 tests)

time
2026-06-10 13:05 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
test coverage navigation security
parent
b93cadab38df
2 files app/src/test/java/com/peachpasswords/security/SecurityPropertiesTest.kt+127 −0app/src/test/java/com/peachpasswords/ui/NavigationFlowTest.kt+77 −0
app/src/test/java/com/peachpasswords/security/SecurityPropertiesTest.kt+127 −0
@@ -0,0 +1,127 @@1+package com.peachpasswords.security2+3+import com.peachpasswords.vault.StoredVault4+import com.peachpasswords.vault.UnlockResult5+import com.peachpasswords.vault.VaultEntry6+import com.peachpasswords.vault.VaultRepository7+import com.peachpasswords.vault.VaultSettings8+import com.peachpasswords.vault.VaultStorage9+import kotlinx.coroutines.runBlocking10+import org.junit.Assert.assertEquals11+import org.junit.Assert.assertFalse12+import org.junit.Assert.assertNull13+import org.junit.Assert.assertTrue14+import org.junit.Test15+16+/**17+ * Security-property suite (brief Suite 10): the repository-observable invariants —18+ * key material is gone after lock, the duress passphrase opens a decoy (never the19+ * real vault), and panic/destroy is irreversible. FLAG_SECURE and clipboard-clear20+ * timing are UI/instrumented concerns covered elsewhere.21+ */22+class SecurityPropertiesTest {23+24+    private class Storage : VaultStorage {25+        var slotA: StoredVault? = null26+        var slotB: String? = null27+        private var ver: Long = 028+        private var settings = VaultSettings()29+        override fun loadSlotA() = slotA30+        override fun hasVault() = slotA != null31+        override fun writeSlotA(slot: StoredVault): Boolean { slotA = slot; return true }32+        override fun writeSlotB(blobBase64: String): Boolean { slotB = blobBase64; return true }33+        var decoy: StoredVault? = null34+        override fun loadDecoySlot() = decoy35+        override fun writeDecoySlot(slot: StoredVault): Boolean { decoy = slot; return true }36+        override fun hasDecoySlot() = decoy != null37+        override fun clearDecoySlot() { decoy = null }38+        override fun version() = ver39+        override fun stampLocalMutation(): Long { ver = maxOf(System.currentTimeMillis(), ver + 1); return ver }40+        override fun loadSettings() = settings41+        override fun writeSettings(s: VaultSettings): Boolean { settings = s; return true }42+        override fun clearVault() { slotA = null; slotB = null; ver = 0; settings = VaultSettings() }43+    }44+45+    private fun repo() = VaultRepository(Storage()).also { runBlocking { it.createVault("real-master-pass") } }46+    private fun login(t: String) = VaultEntry(id = "", title = t, type = "login", password = "p", createdAt = 0, modifiedAt = 0)47+48+    // ── Key material cleared after lock ───────────────────────────────────────49+50+    @Test fun vault_key_is_null_after_lock() {51+        val r = repo()52+        assertTrue(r.currentVaultKey() != null)53+        r.lock()54+        assertNull(r.currentVaultKey())55+        assertNull(r.syncMasterKey())56+        assertFalse(r.isUnlocked.value)57+    }58+59+    @Test fun entries_are_cleared_from_memory_after_lock() = runBlocking {60+        val r = repo()61+        r.addEntry(login("Secret"))62+        r.lock()63+        assertTrue(r.getEntries().isEmpty())64+    }65+66+    // ── Duress isolation ──────────────────────────────────────────────────────67+68+    @Test fun duress_passphrase_opens_decoy_not_real_vault() = runBlocking {69+        val r = repo()70+        val real = r.addEntry(login("RealAccount"))71+        r.setDuressPassphrase("duress-pass-xyz")72+        r.lock()73+74+        val duress = r.tryUnlockDuress("duress-pass-xyz")!!75+        assertEquals(UnlockResult.Success, r.commitDuressUnlock(duress))76+        // The decoy session never exposes the real entry.77+        assertFalse(r.getEntries().any { it.id == real.id })78+        assertTrue(r.getEntries().isEmpty())79+    }80+81+    @Test fun real_password_does_not_match_duress_slot() = runBlocking {82+        val r = repo()83+        r.setDuressPassphrase("duress-pass-xyz")84+        r.lock()85+        // The real password must not decrypt the duress slot.86+        assertNull(r.tryUnlockDuress("real-master-pass"))87+    }88+89+    @Test fun duress_passphrase_does_not_open_real_slot() = runBlocking {90+        val r = repo()91+        r.setDuressPassphrase("duress-pass-xyz")92+        r.lock()93+        assertNull(r.tryUnlockSlotA("duress-pass-xyz"))94+    }95+96+    // ── Panic / destroy is irreversible ───────────────────────────────────────97+98+    @Test fun destroy_wipes_vault_and_blocks_old_password() = runBlocking {99+        val storage = Storage()100+        val r = VaultRepository(storage)101+        r.createVault("real-master-pass")102+        r.addEntry(login("Gone"))103+        r.destroyVault()104+        assertFalse(r.hasVault())105+        assertNull(storage.slotA)106+        assertNull(storage.decoy)107+        assertEquals(UnlockResult.Error("no_vault"), r.unlock("real-master-pass"))108+    }109+110+    @Test fun destroy_also_clears_the_decoy_slot() = runBlocking {111+        val storage = Storage()112+        val r = VaultRepository(storage)113+        r.createVault("real-master-pass")114+        r.setDuressPassphrase("duress-pass-xyz")115+        assertTrue(storage.decoy != null)116+        r.destroyVault()117+        assertNull(storage.decoy)118+    }119+120+    // ── Recovery is not offered without an escrow ─────────────────────────────121+122+    @Test fun recovery_not_available_without_escrow() = runBlocking {123+        val r = repo()124+        r.lock()125+        assertFalse(r.hasRecoveryEscrow())126+    }127+}

view file

app/src/test/java/com/peachpasswords/ui/NavigationFlowTest.kt+77 −0
@@ -0,0 +1,77 @@1+package com.peachpasswords.ui2+3+import com.peachpasswords.ui.lock.postUnlockDestination4+import com.peachpasswords.ui.onboarding.onboardingStartDestination5+import com.peachpasswords.ui.vault.entryTapDestination6+import com.peachpasswords.vault.VaultEntry7+import org.junit.Assert.assertEquals8+import org.junit.Test9+10+/**11+ * Navigation suite (brief Suite 9): route construction and the flow-decision12+ * functions that route the app — onboarding gate, list-tap, and post-unlock.13+ */14+class NavigationFlowTest {15+16+    private fun login(id: String) = VaultEntry(id = id, title = id, type = "login", createdAt = 0, modifiedAt = 0)17+    private fun note(id: String) = VaultEntry(id = id, title = id, type = "note", createdAt = 0, modifiedAt = 0)18+19+    // ── Route construction ────────────────────────────────────────────────────20+21+    @Test fun entry_detail_route_embeds_id() {22+        assertEquals("entry/abc", PeachNav.EntryDetail("abc").route)23+        assertEquals("entry/abc", PeachNav.EntryDetail.of("abc"))24+        assertEquals("entry/{id}", PeachNav.EntryDetail.ROUTE)25+    }26+27+    @Test fun notes_mode_route_embeds_id() {28+        assertEquals("notes/n1", PeachNav.NotesMode("n1").route)29+        assertEquals("notes/n1", PeachNav.NotesMode.of("n1"))30+        assertEquals("notes/{id}", PeachNav.NotesMode.ROUTE)31+    }32+33+    @Test fun entry_edit_route_handles_null_and_value() {34+        assertEquals("edit?id=", PeachNav.EntryEdit(null).route)35+        assertEquals("edit?id=x", PeachNav.EntryEdit("x").route)36+        assertEquals("edit?id=", PeachNav.EntryEdit.of(null))37+        assertEquals("edit?id=x", PeachNav.EntryEdit.of("x"))38+    }39+40+    @Test fun static_routes_are_stable() {41+        assertEquals("onboarding", PeachNav.Onboarding.route)42+        assertEquals("lock", PeachNav.Lock.route)43+        assertEquals("vault", PeachNav.VaultList.route)44+        assertEquals("settings", PeachNav.Settings.route)45+    }46+47+    // ── First-launch gate ─────────────────────────────────────────────────────48+49+    @Test fun first_launch_shows_onboarding() {50+        assertEquals(PeachNav.Onboarding, onboardingStartDestination(hasVault = false, onboarded = false))51+    }52+53+    @Test fun subsequent_launch_skips_onboarding() {54+        assertEquals(PeachNav.Lock, onboardingStartDestination(hasVault = true, onboarded = true))55+    }56+57+    // ── List tap ──────────────────────────────────────────────────────────────58+59+    @Test fun list_tap_login_opens_detail() {60+        assertEquals(PeachNav.EntryDetail("l"), entryTapDestination(login("l")))61+    }62+63+    @Test fun list_tap_note_opens_notes_mode() {64+        assertEquals(PeachNav.NotesMode("n"), entryTapDestination(note("n")))65+    }66+67+    // ── Post-unlock landing ───────────────────────────────────────────────────68+69+    @Test fun post_unlock_opens_last_viewed() {70+        val entries = mapOf("a" to login("a"), "b" to login("b"))71+        assertEquals(PeachNav.EntryDetail("b"), postUnlockDestination("b", entries::get, entries["a"]))72+    }73+74+    @Test fun post_unlock_empty_vault_falls_to_list() {75+        assertEquals(PeachNav.VaultList, postUnlockDestination(null, { null }, null))76+    }77+}

view file