package com.peachpasswords.qa import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import com.peachpasswords.di.VaultRepositoryEntryPoint import com.peachpasswords.vault.CreateVaultResult import com.peachpasswords.vault.UnlockResult import com.peachpasswords.vault.VaultEntry import dagger.hilt.android.EntryPointAccessors import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith /** * Emulator-QA harness: seeds a real vault in-process so autofill and * keyboard-row chip testing never depends on IME text injection (Gboard * corrupts `adb input text`). Idempotent — safe to re-run; existing vaults * and entries are left untouched. * * Deliberately activity-free: the onboarding screen runs an infinite Compose * animation, so `ActivityScenario.launch`'s waitForIdleSync never returns. * The repository is fetched straight from Hilt instead. * * The master password below is QA-only and lives solely on throwaway * emulator vaults. */ @RunWith(AndroidJUnit4::class) class VaultSeedTest { private val masterPassword = "Tulip9Marble42" @Test fun seedVaultWithLoginsForAutofillQA() { val context = ApplicationProvider.getApplicationContext() val vault = EntryPointAccessors .fromApplication(context, VaultRepositoryEntryPoint::class.java) .vaultRepository() runBlocking { if (!vault.hasVault()) { assertEquals(CreateVaultResult.Success, vault.createVault(masterPassword)) } if (!vault.isUnlocked.value) { assertEquals(UnlockResult.Success, vault.unlock(masterPassword)) } if (vault.getEntries().isEmpty()) { // GitHub gets TOTP for the OTP chip QA path (E2-fix). The seed // is the well-known "Hello!Þ­¾ï" base32 string // used in every TOTP unit test -- produces a deterministic // code that matches what the chip will render. vault.addEntry(login("GitHub", "https://github.com").copy(totp = "JBSWY3DPEHPK3PXP")) vault.addEntry(login("Proton Mail", "https://account.proton.me/login")) vault.addEntry(login("Vercel", "https://vercel.com/login")) } val entries = vault.getEntries() assertEquals(3, entries.size) assertTrue(entries.all { it.password != null && it.url != null }) } } private fun login(title: String, url: String) = VaultEntry( id = "", type = "login", title = title, username = "june", password = "Correct-Horse-$title-42", url = url, createdAt = 0, modifiedAt = 0, ) }