package com.peachpasswords.autofill import org.junit.Assert.assertFalse import org.junit.Assert.assertNotEquals import org.junit.Assert.assertTrue import org.junit.Test /** * F3: the picker→MainActivity new-entry handoff is authenticated with a * one-time in-memory token. MainActivity is exported, so any app can raise * EXTRA_OPEN_NEW_ENTRY; only the token holder's payload may pre-fill. */ class AutofillNewEntryTokenTest { @Test fun issued_token_is_accepted_exactly_once() { val token = AutofillIntents.issueNewEntryToken() assertTrue(AutofillIntents.consumeNewEntryToken(token)) assertFalse("token must be single-use", AutofillIntents.consumeNewEntryToken(token)) } @Test fun wrong_or_missing_tokens_are_rejected_without_burning_the_pending_one() { val token = AutofillIntents.issueNewEntryToken() assertFalse(AutofillIntents.consumeNewEntryToken(null)) assertFalse(AutofillIntents.consumeNewEntryToken("attacker-guess")) // The real handoff still succeeds after spoofed attempts. assertTrue(AutofillIntents.consumeNewEntryToken(token)) } @Test fun fresh_issue_supersedes_the_previous_token() { val first = AutofillIntents.issueNewEntryToken() val second = AutofillIntents.issueNewEntryToken() assertNotEquals(first, second) assertFalse(AutofillIntents.consumeNewEntryToken(first)) assertTrue(AutofillIntents.consumeNewEntryToken(second)) } }