RealBackupDecodeTest.kt

1.9 KB · raw

1package com.peachpasswords.ui.vault23import org.junit.Assume.assumeTrue4import com.peachpasswords.vault.PeachScript5import org.junit.Test6import java.io.File7import org.junit.Assert.assertTrue89/**10 * Decode-path check against a real, full-size PeachScript backup rather than a11 * toy fixture. The small round-trip fixtures all passed while a real export12 * (262k PUA characters) failed in the app, so size itself is the variable13 * worth covering.14 *15 * Skips when the file isn't present — it's a local artifact, never committed16 * (it's an encrypted vault backup).17 */18class RealBackupDecodeTest {1920    private val backup = File(System.getProperty("user.home"), "Downloads/peach-backup-2026-07-24.peach")2122    @Test fun real_backup_is_recognised_and_decodes_to_bytes() {23        assumeTrue("no local backup artifact", backup.exists())24        val text = backup.readText()25        println("chars=${text.length}")2627        assertTrue("looksLikePeachScript rejected a real export", PeachScriptImport.looksLikePeachScript(text))2829        val normalised = PeachScript.normalise(text)30        assertTrue("normalise broke the sniff", PeachScript.isPeachScript(normalised))3132        // Decrypting needs the backup password, which we don't have — but33        // decode() is the whole pre-crypto path and is where size would bite.34        val bytes = PeachScript.decode(normalised)35        println("decoded bytes=${bytes.size}")36        assertTrue("decoded to nothing", bytes.isNotEmpty())37    }3839    @Test fun wrong_password_is_reported_as_wrong_not_corrupted() {40        assumeTrue("no local backup artifact", backup.exists())41        val result = PeachScriptImport.decryptAndParse(backup.readText(), "definitely-not-the-password")42        println("result=$result")43        assertTrue(44            "a real export with a bad password should report WrongPassword, got $result",45            result is PeachScriptImport.DecryptResult.WrongPassword,46        )47    }48}