e2ee-openpgp: fix second-boundary flake in detached signature test
- Commit
ccf09d8982551f9484aa9137b575c2317f17290d- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 06:44 UTC (28 days ago)
- Parents
77e84b5
What: rewrite the determinism assertion in PgpApiTest (detachedSignaturesAreDeterministicAndDataDependent) to compare consecutive signature pairs with up to 5 bounded retries instead of asserting byte-equality of two back-to-back signDetached calls. Why: :library:e2ee-openpgp:testDebugUnitTest flaked in full-batch runs (passed in isolation and in single-module runs): the two signatures of identical data byte-differed. Root cause: rPGP's DetachedSignature::sign_binary_data embeds a seconds-resolution signature-creation time in the packet. Ed25519 signing is deterministic, so same-second calls are byte-identical, but two calls straddling a second boundary always differ. Under parallel-test load the gap between the two calls widens and the straddle becomes likely. Prod code is correct (creation time is meaningful OpenPGP data; the relay SUB-auth path signs once per payload and never byte-compares) — only the test over-asserted. Proven: inserting a temporary 1.1s sleep between the calls made the first pair differ (firstPairDifferAfterSleep=true in the result XML) while the retried consecutive pair matched and the test passed; TEMP lines removed afterwards. Rejected alternatives: hand-parsing the packet to mask the creation-time bytes (fragile across v4/v6 packet layouts); adding a verify-detached JNI binding so the test could verify instead of compare (new crypto surface needing adversarial review, disproportionate for a test issue); pinning the creation time in prod (breaks real signature semantics); asserting inequality only (loses the determinism property); lint-style suppression (n/a). User-visible effect: none; test-only change. Verification: :library:e2ee-openpgp:testDebugUnitTest 10/0/0 and :lint green; full 18-module library batch (incl. everysync-core jvmTest 32/0/0) green — biometric 16, carhost 59, downloadservice 58, e2ee-p2p 14, image 30, ink 4, locationprovider 5, log 3, media 83, ml 117, network 116, ocr 15, room 22, widgets 24, work 7, all 0 failures/errors.
Diff
library/e2ee-openpgp/src/test/java/com/vayunmathur/e2ee/PgpApiTest.kt
diff --git a/library/e2ee-openpgp/src/test/java/com/vayunmathur/e2ee/PgpApiTest.kt b/library/e2ee-openpgp/src/test/java/com/vayunmathur/e2ee/PgpApiTest.ktindex 980f5921d9..77c425680d 100644--- a/library/e2ee-openpgp/src/test/java/com/vayunmathur/e2ee/PgpApiTest.kt+++ b/library/e2ee-openpgp/src/test/java/com/vayunmathur/e2ee/PgpApiTest.kt@@ -153,9 +153,21 @@ class PgpApiTest { val data = "authenticate me".toByteArray(Charsets.UTF_8) val sig = Pgp.signDetached(alice.armoredSecret, ALICE_PW, data) assertTrue(sig.isNotEmpty())- assertContentEquals(sig, Pgp.signDetached(alice.armoredSecret, ALICE_PW, data))+ // Ed25519 signing itself is deterministic, but the packet embeds a+ // seconds-resolution creation time: two calls straddling a second+ // boundary byte-differ. Compare consecutive pairs (bounded retries)+ // so an attempt only fails if a boundary falls between its two calls.+ var prev = sig+ var resig = Pgp.signDetached(alice.armoredSecret, ALICE_PW, data)+ var attempts = 1+ while (!prev.contentEquals(resig) && attempts < 5) {+ prev = resig+ resig = Pgp.signDetached(alice.armoredSecret, ALICE_PW, data)+ attempts+++ }+ assertContentEquals(prev, resig) val other = Pgp.signDetached(alice.armoredSecret, ALICE_PW, "authenticate me!".toByteArray())- assertFalse(sig.contentEquals(other))+ assertFalse(prev.contentEquals(other)) assertFailsWith<IllegalStateException> { Pgp.signDetached(alice.armoredSecret, "wrong", data) } assertFailsWith<IllegalStateException> { Pgp.signDetached("garbage", ALICE_PW, data) } }