mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 20:28:04 +01:00
Introduce "service identifiers"
This commit is contained in:
@@ -9,20 +9,24 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junitpioneer.jupiter.cartesian.ArgumentSets;
|
||||
import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.PniServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
|
||||
class OutgoingMessageEntityTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void roundTripThroughEnvelope(@Nullable final UUID sourceUuid, @Nullable final UUID updatedPni) {
|
||||
@CartesianTest
|
||||
@CartesianTest.MethodFactory("roundTripThroughEnvelope")
|
||||
void roundTripThroughEnvelope(@Nullable final ServiceIdentifier sourceIdentifier,
|
||||
final ServiceIdentifier destinationIdentifier,
|
||||
@Nullable final UUID updatedPni) {
|
||||
|
||||
final byte[] messageContent = new byte[16];
|
||||
new Random().nextBytes(messageContent);
|
||||
|
||||
@@ -35,9 +39,9 @@ class OutgoingMessageEntityTest {
|
||||
UUID.randomUUID(),
|
||||
MessageProtos.Envelope.Type.CIPHERTEXT_VALUE,
|
||||
messageTimestamp,
|
||||
UUID.randomUUID(),
|
||||
sourceUuid != null ? (int) Device.MASTER_ID : 0,
|
||||
UUID.randomUUID(),
|
||||
sourceIdentifier,
|
||||
sourceIdentifier != null ? (int) Device.MASTER_ID : 0,
|
||||
destinationIdentifier,
|
||||
updatedPni,
|
||||
messageContent,
|
||||
serverTimestamp,
|
||||
@@ -48,11 +52,14 @@ class OutgoingMessageEntityTest {
|
||||
assertEquals(outgoingMessageEntity, OutgoingMessageEntity.fromEnvelope(outgoingMessageEntity.toEnvelope()));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> roundTripThroughEnvelope() {
|
||||
return Stream.of(
|
||||
Arguments.of(UUID.randomUUID(), UUID.randomUUID()),
|
||||
Arguments.of(UUID.randomUUID(), null),
|
||||
Arguments.of(null, UUID.randomUUID()));
|
||||
@SuppressWarnings("unused")
|
||||
static ArgumentSets roundTripThroughEnvelope() {
|
||||
return ArgumentSets.argumentsForFirstParameter(new AciServiceIdentifier(UUID.randomUUID()),
|
||||
new PniServiceIdentifier(UUID.randomUUID()),
|
||||
null)
|
||||
.argumentsForNextParameter(new AciServiceIdentifier(UUID.randomUUID()),
|
||||
new PniServiceIdentifier(UUID.randomUUID()))
|
||||
.argumentsForNextParameter(UUID.randomUUID(), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,7 +78,7 @@ class OutgoingMessageEntityTest {
|
||||
IncomingMessage message = new IncomingMessage(1, 4444L, 55, "AAAAAA");
|
||||
|
||||
MessageProtos.Envelope baseEnvelope = message.toEnvelope(
|
||||
UUID.randomUUID(),
|
||||
new AciServiceIdentifier(UUID.randomUUID()),
|
||||
account,
|
||||
123L,
|
||||
System.currentTimeMillis(),
|
||||
|
||||
Reference in New Issue
Block a user