package com.cottondb.keys import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.jsonObject import org.junit.Assert.assertTrue import org.junit.Test import java.io.File /** The shapes the iPhone walk (launch-ios, 23bc8292f2) settled in the core, as Secrets Android reads them. */ class SecretsShapesTest { private val repo = generateSequence(File("").absoluteFile) { it.parentFile }.first { File(it, "apps/registry.json").isFile } private fun src(name: String) = File(repo, "apps/android/app/src/keys/kotlin/com/cottondb/keys/secrets/$name").readText() private val core = File(repo, "crates/cotton-ffi/src/phone/vault.rs").readText() + File(repo, "crates/cotton-ffi/src/phone/secrets_app.rs").readText() /** Leaving says so: the core holds the unlock as long as Lock after says, or drops it at once. */ @Test fun leaving_tells_the_core() { assertTrue(core.contains("\"leaving\"")) assertTrue(src("SecretsApp.kt").contains("""put("leaving", true)""")) } /** A save's ask is `{id, line, yes, no}`, answered by `secrets.reshare`. */ @Test fun the_saves_ask_is_answered_by_reshare() { assertTrue(core.contains("\"reshare.ask\"") && core.contains("\"secrets.reshare\"")) val edit = src("EditScreen.kt") listOf("""obj("ask")""", """str("line")""", "secrets.reshare").forEach { assertTrue(it, edit.contains(it)) } } /** A shared secret's user name and site come plain (`plain`), above its sealed fields. */ @Test fun a_shares_plain_fields_are_drawn() { assertTrue(core.contains("\"plain\": plain")) assertTrue(src("Sharing.kt").contains("""p.arr("plain")""")) } /** TalkBack says the field with Reveal, Hide and Copy, in the core's words. */ @Test fun the_spoken_words_exist() { val lines = Json.parseToJsonElement(File(repo, "crates/cotton-core/kits/shell/lines/secrets.json").readText()) as JsonObject val a11y = lines["a11y"]!!.jsonObject listOf("reveal", "hide", "copy").forEach { k -> assertTrue(k, a11y[k].toString().contains("{field}")) } val all = listOf("SecretScreen.kt", "Sharing.kt", "EditScreen.kt").joinToString { src(it) } listOf("a11y.reveal", "a11y.hide", "a11y.copy").forEach { assertTrue(it, all.contains(it)) } } }