package com.peachpasswords.ui.vault import com.peachpasswords.vault.PeachScript import com.peachpasswords.vault.VaultEntry import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test /** * Decode-path checks using a deterministic synthetic PeachScript backup. * * The fixture is generated through the production export API, so it exercises * the same encrypted envelope and PUA text decoding as a real backup without * depending on a developer's home directory. */ class RealBackupDecodeTest { private val password = "synthetic-backup-password" private fun backup(): String = PeachScriptExport.buildEncrypted( entries = listOf( VaultEntry( id = "11111111-2222-3333-4444-555555555555", type = "login", title = "Synthetic GitHub", username = "fixture-user", password = "fixture-secret", url = "https://github.com", notes = "generated test fixture", createdAt = 0, modifiedAt = 0, ), ), backupPassword = password, ) @Test fun synthetic_backup_is_recognised_and_decodes_to_bytes() { val text = backup() assertTrue(PeachScriptImport.looksLikePeachScript(text)) val normalised = PeachScript.normalise(text) assertTrue(PeachScript.isPeachScript(normalised)) val bytes = PeachScript.decode(normalised) assertTrue("decoded to nothing", bytes.isNotEmpty()) val result = PeachScriptImport.decryptAndParse(text, password) assertTrue(result is PeachScriptImport.DecryptResult.Success) result as PeachScriptImport.DecryptResult.Success assertEquals("fixture-secret", result.entries.single().password) } @Test fun wrong_password_is_reported_as_wrong_not_corrupted() { val result = PeachScriptImport.decryptAndParse(backup(), "definitely-not-the-password") assertTrue( "synthetic export with a bad password should report WrongPassword, got $result", result is PeachScriptImport.DecryptResult.WrongPassword, ) } }