mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 19:56:00 +00:00
Add call link support to storage service.
This commit is contained in:
committed by
Cody Henthorne
parent
1f2b5e90a3
commit
e247d311d8
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.storage
|
||||
|
||||
import okio.ByteString.Companion.EMPTY
|
||||
import okio.ByteString.Companion.toByteString
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.service.webrtc.links.CallLinkCredentials
|
||||
import org.thoughtcrime.securesms.testutil.EmptyLogger
|
||||
import org.whispersystems.signalservice.api.storage.SignalCallLinkRecord
|
||||
import org.whispersystems.signalservice.api.storage.StorageId
|
||||
import org.whispersystems.signalservice.internal.storage.protos.CallLinkRecord
|
||||
|
||||
/**
|
||||
* See [CallLinkRecordProcessor]
|
||||
*/
|
||||
class CallLinkRecordProcessorTest {
|
||||
companion object {
|
||||
val STORAGE_ID: StorageId = StorageId.forCallLink(byteArrayOf(1, 2, 3, 4))
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUpClass() {
|
||||
Log.initialize(EmptyLogger())
|
||||
}
|
||||
}
|
||||
|
||||
private val testSubject = CallLinkRecordProcessor()
|
||||
private val mockCredentials = CallLinkCredentials(
|
||||
"root key".toByteArray(),
|
||||
"admin pass".toByteArray()
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `Given a valid proto with only an admin pass key and not a deletion timestamp, assert valid`() {
|
||||
// GIVEN
|
||||
val proto = CallLinkRecord.Builder().apply {
|
||||
rootKey = mockCredentials.linkKeyBytes.toByteString()
|
||||
adminPasskey = mockCredentials.adminPassBytes!!.toByteString()
|
||||
deletedAtTimestampMs = 0L
|
||||
}.build()
|
||||
|
||||
val record = SignalCallLinkRecord(STORAGE_ID, proto)
|
||||
|
||||
// WHEN
|
||||
val result = testSubject.isInvalid(record)
|
||||
|
||||
// THEN
|
||||
assertFalse(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a valid proto with only a deletion timestamp and not an admin pass key, assert valid`() {
|
||||
// GIVEN
|
||||
val proto = CallLinkRecord.Builder().apply {
|
||||
rootKey = mockCredentials.linkKeyBytes.toByteString()
|
||||
adminPasskey = EMPTY
|
||||
deletedAtTimestampMs = System.currentTimeMillis()
|
||||
}.build()
|
||||
|
||||
val record = SignalCallLinkRecord(STORAGE_ID, proto)
|
||||
|
||||
// WHEN
|
||||
val result = testSubject.isInvalid(record)
|
||||
|
||||
// THEN
|
||||
assertFalse(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a proto with both an admin pass key and a deletion timestamp, assert invalid`() {
|
||||
// GIVEN
|
||||
val proto = CallLinkRecord.Builder().apply {
|
||||
rootKey = mockCredentials.linkKeyBytes.toByteString()
|
||||
adminPasskey = mockCredentials.adminPassBytes!!.toByteString()
|
||||
deletedAtTimestampMs = System.currentTimeMillis()
|
||||
}.build()
|
||||
|
||||
assertThrows(IllegalStateException::class.java) {
|
||||
SignalCallLinkRecord(STORAGE_ID, proto)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a proto with neither an admin pass key nor a deletion timestamp, assert valid`() {
|
||||
// GIVEN
|
||||
val proto = CallLinkRecord.Builder().apply {
|
||||
rootKey = mockCredentials.linkKeyBytes.toByteString()
|
||||
adminPasskey = EMPTY
|
||||
deletedAtTimestampMs = 0L
|
||||
}.build()
|
||||
|
||||
val record = SignalCallLinkRecord(STORAGE_ID, proto)
|
||||
|
||||
// WHEN
|
||||
val result = testSubject.isInvalid(record)
|
||||
|
||||
// THEN
|
||||
assertFalse(result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user