Modern Apps git

← Modern-Apps.git

build-logic: add shared FakeTokenSealing test logic

Commit
a2cf14b9eabd38f9ab66818880626fa17e39b5a8
Author
Vayun Mathur <[email protected]>
When
2026-12-01 22:48 UTC (4 days ago)
Parents
df56137
Adds the one shared host-test sealing implementation in build-logic/shared-test, the mechanism that already shares FakeAndroidKeyStore and DeterministicAwait with every app/library module's unit tests.

The per-app TokenSealer interfaces stay in their apps (code, fooddelivery and taxi each declare their own interface in main, so no single shared class can implement all three); those apps now keep a thin FakeTokenSealer adapter delegating here. The logic mirrors the real sealers' frozen contract: sealed values carry the v1: prefix, this fake's output carries v1:fake:, legacy values pass through, foreign sealed values fail with null.

Verified through the consumers: :code:testDevUnitTest, :fooddelivery:testDevUnitTest and :taxi:testDevUnitTest all green. Lint not run (see module commits).

Diff

build-logic/shared-test/java/com/vayunmathur/testsupport/FakeTokenSealing.kt
diff --git a/build-logic/shared-test/java/com/vayunmathur/testsupport/FakeTokenSealing.kt b/build-logic/shared-test/java/com/vayunmathur/testsupport/FakeTokenSealing.ktnew file mode 100644index 0000000000..af09692825--- /dev/null+++ b/build-logic/shared-test/java/com/vayunmathur/testsupport/FakeTokenSealing.kt@@ -0,0 +1,28 @@+package com.vayunmathur.testsupport++/**+ * Shared host-test sealing logic for the per-app `TokenSealer` interfaces+ * (code, fooddelivery, taxi each declare their own interface in main, so no+ * single shared class can implement all three; each app keeps a thin+ * `FakeTokenSealer : TokenSealer` adapter delegating here).+ *+ * Mirrors the real sealers' contract: sealed values carry the `v1:` prefix+ * (every app's `KeystoreTokenSealer.PREFIX`), this fake's own output carries+ * `v1:fake:`, legacy values pass through, and foreign sealed values fail+ * (null) rather than passing through. Robolectric has no AndroidKeyStore,+ * so tests seal with this reversible marker transform instead of AES-GCM.+ */+object FakeTokenSealing {+    private const val SEALED_PREFIX = "v1:fake:"+    private const val REAL_PREFIX = "v1:"++    fun seal(plain: String): String = SEALED_PREFIX + plain++    fun unseal(stored: String): String? = when {+        stored.startsWith(SEALED_PREFIX) -> stored.removePrefix(SEALED_PREFIX)+        isSealed(stored) -> null+        else -> stored+    }++    fun isSealed(stored: String): Boolean = stored.startsWith(REAL_PREFIX)+}