AutofillNewEntryTokenTest.kt

1.5 KB · raw

1package com.peachpasswords.autofill23import org.junit.Assert.assertFalse4import org.junit.Assert.assertNotEquals5import org.junit.Assert.assertTrue6import org.junit.Test78/**9 * F3: the picker→MainActivity new-entry handoff is authenticated with a10 * one-time in-memory token. MainActivity is exported, so any app can raise11 * EXTRA_OPEN_NEW_ENTRY; only the token holder's payload may pre-fill.12 */13class AutofillNewEntryTokenTest {1415    @Test fun issued_token_is_accepted_exactly_once() {16        val token = AutofillIntents.issueNewEntryToken()17        assertTrue(AutofillIntents.consumeNewEntryToken(token))18        assertFalse("token must be single-use", AutofillIntents.consumeNewEntryToken(token))19    }2021    @Test fun wrong_or_missing_tokens_are_rejected_without_burning_the_pending_one() {22        val token = AutofillIntents.issueNewEntryToken()23        assertFalse(AutofillIntents.consumeNewEntryToken(null))24        assertFalse(AutofillIntents.consumeNewEntryToken("attacker-guess"))25        // The real handoff still succeeds after spoofed attempts.26        assertTrue(AutofillIntents.consumeNewEntryToken(token))27    }2829    @Test fun fresh_issue_supersedes_the_previous_token() {30        val first = AutofillIntents.issueNewEntryToken()31        val second = AutofillIntents.issueNewEntryToken()32        assertNotEquals(first, second)33        assertFalse(AutofillIntents.consumeNewEntryToken(first))34        assertTrue(AutofillIntents.consumeNewEntryToken(second))35    }36}