AutofillMatchTest.kt

2.0 KB · raw

1package com.peachpasswords.autofill23import com.peachpasswords.vault.VaultEntry4import org.junit.Assert.assertEquals5import org.junit.Assert.assertFalse6import org.junit.Assert.assertTrue7import org.junit.Test89class AutofillMatchTest {10    private fun entry(title: String, url: String?) =11        VaultEntry(id = title, title = title, url = url, createdAt = 0, modifiedAt = 0)1213    @Test fun strict_domain_match_hits_only_the_matching_site() {14        val peach = entry("Peach", "https://peachpasswords.com/login")15        val mail = entry("Fastmail", "https://fastmail.com")16        val result = AutofillResponseBuilder.matchEntries(listOf(mail, peach), "peachpasswords.com")17        assertEquals(listOf(peach), result.hits)18        assertTrue("no unrelated entries leak for a web origin", result.rest.isEmpty())19    }2021    @Test fun no_false_positive_on_substring_lookalike() {22        val gh = entry("GitHub", "https://github.com/login")23        val result = AutofillResponseBuilder.matchEntries(listOf(gh), "notgithub.com")24        assertTrue("github.com must not match notgithub.com", result.hits.isEmpty())25        assertTrue(result.rest.isEmpty())26    }2728    @Test fun subdomain_origin_matches_registrable_domain() {29        val peach = entry("Peach", "https://peachpasswords.com")30        val result = AutofillResponseBuilder.matchEntries(listOf(peach), "app.peachpasswords.com")31        assertEquals(listOf(peach), result.hits)32    }3334    @Test fun null_origin_yields_no_hits_only_fallback() {35        val a = entry("A", "https://a.com")36        val b = entry("B", "https://b.com")37        val result = AutofillResponseBuilder.matchEntries(listOf(a, b), null)38        assertTrue(result.hits.isEmpty())39        assertEquals(listOf(a, b), result.rest)40    }4142    @Test fun trusted_browser_allowlist() {43        assertTrue(TrustedBrowsers.isTrusted("com.android.chrome"))44        assertTrue(TrustedBrowsers.isTrusted("org.mozilla.firefox"))45        assertFalse(TrustedBrowsers.isTrusted("com.evil.phisher"))46        assertFalse(TrustedBrowsers.isTrusted(null))47    }48}