SourceConsentGateTest.kt

1.4 KB · raw

1package com.peachpasswords.sync23import kotlinx.coroutines.async4import kotlinx.coroutines.test.runCurrent5import kotlinx.coroutines.test.runTest6import org.junit.Assert.assertFalse7import org.junit.Assert.assertTrue8import org.junit.Test910/**11 * PB-26-116: the vault-owning device must approve a pairing before the root key12 * is read. The historical defect was a consent callback that returned true as13 * soon as the SAS had been displayed, so nothing on the source side ever asked.14 */15class SourceConsentGateTest {1617    @Test fun a_grant_waits_until_someone_decides() = runTest {18        val gate = SourceConsentGate()19        val decision = async { gate.await() }20        runCurrent()2122        assertFalse("must not approve before a decision exists", decision.isCompleted)2324        gate.resolve(true)25        assertTrue(decision.await())26    }2728    @Test fun leaving_the_screen_denies_rather_than_hanging() = runTest {29        val gate = SourceConsentGate()30        val decision = async { gate.await() }31        runCurrent()3233        gate.resolve(false)34        assertFalse(decision.await())35    }3637    @Test fun an_answer_with_no_live_prompt_is_ignored() = runTest {38        val gate = SourceConsentGate()39        gate.resolve(true)4041        val decision = async { gate.await() }42        runCurrent()43        assertFalse("a stale answer must not pre-approve a later prompt", decision.isCompleted)44        decision.cancel()45    }46}