PairedDeviceRevocationTest.kt

1.7 KB · raw

1package com.peachpasswords.sync23import org.junit.Assert.assertEquals4import org.junit.Assert.assertNull5import org.junit.Test67class PairedDeviceRevocationTest {8    private val browser = PairedDevice(9        deviceId = "browser-1",10        deviceName = "Chrome",11        deviceType = "extension",12        longTermPublicKeyHex = "ab".repeat(32),13        pairedAt = 1L,14    )1516    @Test17    fun `new revocation records the key and removes the paired row`() {18        val mutation = planDeviceRevocation(19            devices = listOf(browser),20            revocations = emptyList(),21            deviceId = browser.deviceId,22            revokedByDeviceId = "phone-1",23            nowMs = 42L,24        )2526        assertEquals(emptyList<PairedDevice>(), mutation.devices)27        assertEquals(1, mutation.revocations.size)28        assertEquals(browser.longTermPublicKeyHex, mutation.added?.longTermPublicKeyHex)29        assertEquals(42L, mutation.added?.revokedAt)30    }3132    @Test33    fun `existing revocation still removes a stale overlapping paired row`() {34        val existing = DeviceRevocation(35            deviceId = browser.deviceId,36            longTermPublicKeyHex = browser.longTermPublicKeyHex!!,37            revokedAt = 1L,38            revokedByDeviceId = "phone-1",39        )4041        val mutation = planDeviceRevocation(42            devices = listOf(browser),43            revocations = listOf(existing),44            deviceId = browser.deviceId,45            revokedByDeviceId = "phone-1",46            nowMs = 99L,47        )4849        assertEquals(emptyList<PairedDevice>(), mutation.devices)50        assertEquals(listOf(existing), mutation.revocations)51        assertNull(mutation.added)52    }53}