From 90b75cbf220c27c68c8ec44bff2370553fa0535c Mon Sep 17 00:00:00 2001 From: Ravi Khadiwala Date: Mon, 29 Jun 2026 18:52:41 -0500 Subject: [PATCH] Add a test for our Any typeUrls --- .../grpc/GrpcExceptionsTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 service/src/test/java/org/whispersystems/textsecuregcm/grpc/GrpcExceptionsTest.java diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/GrpcExceptionsTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/GrpcExceptionsTest.java new file mode 100644 index 000000000..d8c8a6144 --- /dev/null +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/GrpcExceptionsTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2026 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ +package org.whispersystems.textsecuregcm.grpc; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.google.protobuf.Any; +import com.google.rpc.ErrorInfo; +import io.grpc.StatusRuntimeException; +import io.grpc.protobuf.StatusProto; +import java.util.List; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.signal.chat.common.IdentityType; +import org.signal.chat.common.ServiceIdentifier; +import org.whispersystems.textsecuregcm.util.UUIDUtil; + +class GrpcExceptionsTest { + + @Test + void streamClosed() { + final ServiceIdentifier message = ServiceIdentifier.newBuilder().setIdentityType(IdentityType.IDENTITY_TYPE_ACI) + .setUuid(UUIDUtil.toByteString(UUID.randomUUID())) + .build(); + final StatusRuntimeException statusRuntimeException = GrpcExceptions.streamClosed(message); + final com.google.rpc.Status status = StatusProto.fromThrowable(statusRuntimeException); + final List details = status.getDetailsList(); + assertEquals(2, details.size()); + assertEquals(1, details.stream().filter(any -> any.is(ErrorInfo.class)).count()); + + final Any packed = details.stream().filter(any -> any.is(ServiceIdentifier.class)).findFirst().orElseThrow(); + assertEquals("type.googleapis.com/org.signal.chat.common.ServiceIdentifier", packed.getTypeUrl(), """ + The generated typeUrl for a packed Any message has changed. gRPC clients may rely on stable typeUrls + scheme to distinguish `details` in error metadata + """); + } +}