AssistStructureOtpRegexTest.kt

1.9 KB · raw

1package com.peachpasswords.autofill23import org.junit.Assert.assertFalse4import org.junit.Assert.assertTrue5import org.junit.Test67/**8 * OTP / 2FA field detection. The autofill framework only sets the `otp`9 * hint when the developer opts in; most don\'t, so the parser falls back to10 * a regex over the field\'s id/hint/text. The regex has to catch the labels11 * real 2FA forms actually use without mis-matching promo / coupon / discount12 * code fields.13 */14class AssistStructureOtpRegexTest {1516    private val rx = AssistStructureParser.OTP_HAYSTACK_RX1718    @Test fun matches_textbook_2fa_labels() {19        // The original textbook set the regex already covered.20        assertTrue(rx.containsMatchIn("otp"))21        assertTrue(rx.containsMatchIn("2fa"))22        assertTrue(rx.containsMatchIn("mfa"))23        assertTrue(rx.containsMatchIn("one-time password"))24        assertTrue(rx.containsMatchIn("verification code"))25        assertTrue(rx.containsMatchIn("auth code"))26    }2728    @Test fun matches_labels_real_forms_use() {29        // These were silent misses before the widening.30        assertTrue(rx.containsMatchIn("verification"))31        assertTrue(rx.containsMatchIn("authentication"))32        assertTrue(rx.containsMatchIn("security code"))33        assertTrue(rx.containsMatchIn("token"))34        assertTrue(rx.containsMatchIn("confirm"))35    }3637    @Test fun does_not_match_unrelated_code_fields() {38        // A standalone "code" alone is intentionally absent: promo / coupon39        // / discount fields all use it. Matching them would mis-fill with a40        // TOTP on signup / checkout forms.41        assertFalse(rx.containsMatchIn("code"))42        assertFalse(rx.containsMatchIn("promo code"))43        assertFalse(rx.containsMatchIn("coupon code"))44        assertFalse(rx.containsMatchIn("discount code"))45        assertFalse(rx.containsMatchIn("zip code"))46        assertFalse(rx.containsMatchIn("area code"))47    }48}