mirror of
https://github.com/signalapp/Signal-Server
synced 2026-10-05 21:37:47 +01:00
Allow ignoring the return value of status asserts
This commit is contained in:
1 parent
45dab47ea8
commit
242a5f6a78
13 files changed
+68
-129
No files matched your search
-1
@@ -41,7 +41,6 @@ import org.whispersystems.textsecuregcm.identity.IdentityType;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
@Path("/v1/certificate")
|
||||
@Tag(name = "Certificate")
|
||||
public class CertificateController {
|
||||
|
||||
-3
@@ -112,7 +112,6 @@ class AccountsAnonymousGrpcServiceTest extends
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void checkAccountExistenceIllegalRequest(final CheckAccountExistenceRequest request) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().checkAccountExistence(request));
|
||||
}
|
||||
@@ -174,7 +173,6 @@ class AccountsAnonymousGrpcServiceTest extends
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void lookupUsernameHashIllegalHash(final LookupUsernameHashRequest request) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().lookupUsernameHash(request));
|
||||
}
|
||||
@@ -248,7 +246,6 @@ class AccountsAnonymousGrpcServiceTest extends
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void lookupUsernameLinkIllegalHandle(final LookupUsernameLinkRequest request) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().lookupUsernameLink(request));
|
||||
}
|
||||
|
||||
-11
@@ -205,7 +205,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
void deleteAccountLinkedDevice() {
|
||||
getMockAuthenticationInterceptor().setAuthenticatedDevice(AUTHENTICATED_ACI, (byte) (Device.PRIMARY_ID + 1));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
final DeleteAccountResponse ignored =
|
||||
authenticatedServiceStub().deleteAccount(DeleteAccountRequest.newBuilder().build());
|
||||
|
||||
@@ -240,7 +239,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
|
||||
@Test
|
||||
void setRegistrationLockEmptySecret() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().setRegistrationLock(SetRegistrationLockRequest.newBuilder()
|
||||
.build()));
|
||||
@@ -315,7 +313,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
|
||||
@Test
|
||||
void reserveUsernameHashNoHashes() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().reserveUsernameHash(ReserveUsernameHashRequest.newBuilder().build()));
|
||||
}
|
||||
@@ -329,7 +326,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
requestBuilder.addUsernameHashes(ByteString.copyFrom(usernameHash));
|
||||
}
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().reserveUsernameHash(requestBuilder.build()));
|
||||
}
|
||||
@@ -343,7 +339,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
|
||||
final byte[] usernameHash = TestRandomUtil.nextBytes(AccountController.USERNAME_HASH_LENGTH + 1);
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().reserveUsernameHash(ReserveUsernameHashRequest.newBuilder()
|
||||
.addUsernameHashes(ByteString.copyFrom(usernameHash))
|
||||
@@ -462,7 +457,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
|
||||
doThrow(BaseUsernameException.class).when(usernameHashZkProofVerifier).verifyProof(any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().confirmUsernameHash(ConfirmUsernameHashRequest.newBuilder()
|
||||
.setUsernameHash(ByteString.copyFrom(usernameHash))
|
||||
@@ -474,7 +468,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void confirmUsernameHashInvalidArgument(final ConfirmUsernameHashRequest request) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().confirmUsernameHash(request));
|
||||
}
|
||||
@@ -582,7 +575,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void setUsernameLinkIllegalCiphertext(final SetUsernameLinkRequest request) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().setUsernameLink(request));
|
||||
}
|
||||
@@ -667,7 +659,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void configureUnidentifiedAccessIllegalArguments(final ConfigureUnidentifiedAccessRequest request) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().configureUnidentifiedAccess(request));
|
||||
}
|
||||
@@ -722,7 +713,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
|
||||
@Test
|
||||
void setRegistrationRecoveryPasswordMissingPassword() {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().setRegistrationRecoveryPassword(
|
||||
SetRegistrationRecoveryPasswordRequest.newBuilder().build()));
|
||||
@@ -915,7 +905,6 @@ class AccountsGrpcServiceTest extends SimpleBaseGrpcTest<AccountsGrpcService, Ac
|
||||
when(changeNumberManager.changeNumber(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenThrow(exceptionToThrow);
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.UNAVAILABLE,
|
||||
() -> authenticatedServiceStub().changeNumber(createChangeNumberRequest()));
|
||||
}
|
||||
|
||||
-1
@@ -77,7 +77,6 @@ class CallQualitySurveyGrpcServiceTest extends SimpleBaseGrpcTest<CallQualitySur
|
||||
doThrow(new CallQualityInvalidArgumentsException("test"))
|
||||
.when(callQualitySurveyManager).submitCallQualitySurvey(request, REMOTE_ADDRESS, USER_AGENT);
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().submitCallQualitySurvey(request));
|
||||
}
|
||||
|
||||
-1
@@ -84,7 +84,6 @@ class CallingGrpcServiceTest extends SimpleBaseGrpcTest<CallingGrpcService, Call
|
||||
when(cloudflareTurnCredentialsManager.retrieveFromCloudflare(any()))
|
||||
.thenThrow(IOException.class);
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.UNAVAILABLE,
|
||||
() -> authenticatedServiceStub().getCallingRelays(GetCallingRelaysRequest.getDefaultInstance()));
|
||||
}
|
||||
|
||||
+5
-9
@@ -334,14 +334,11 @@ public class CredentialsGrpcServiceTest
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void getGroupCredentialsIllegalRedemptionTimes(final Instant redemptionStart, final Instant redemptionEnd) {
|
||||
//noinspection ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
authenticatedServiceStub().getGroupCredentials(GetGroupCredentialsRequest.newBuilder()
|
||||
.setRedemptionStartSeconds(redemptionStart.getEpochSecond())
|
||||
.setRedemptionEndSeconds(redemptionEnd.getEpochSecond())
|
||||
.build());
|
||||
});
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().getGroupCredentials(GetGroupCredentialsRequest.newBuilder()
|
||||
.setRedemptionStartSeconds(redemptionStart.getEpochSecond())
|
||||
.setRedemptionEndSeconds(redemptionEnd.getEpochSecond())
|
||||
.build()));
|
||||
}
|
||||
|
||||
private static Collection<Arguments> getGroupCredentialsIllegalRedemptionTimes() {
|
||||
@@ -394,7 +391,6 @@ public class CredentialsGrpcServiceTest
|
||||
void getCreateCallLinkCredentialsInvalidRequest() {
|
||||
when(rateLimiters.getCreateCallLinkLimiter()).thenReturn(mock(RateLimiter.class));
|
||||
|
||||
//noinspection ThrowableNotThrown,ResultOfMethodCallIgnored
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().getCreateCallLinkCredentials(GetCreateCallLinkCredentialsRequest.newBuilder()
|
||||
.setCredentialRequest(ByteString.copyFrom(TestRandomUtil.nextBytes(16)))
|
||||
|
||||
@@ -11,6 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import com.google.protobuf.Message;
|
||||
import com.google.rpc.ErrorInfo;
|
||||
import com.google.rpc.RetryInfo;
|
||||
@@ -20,6 +21,7 @@ import java.time.Duration;
|
||||
import io.grpc.protobuf.StatusProto;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.jupiter.api.function.ThrowingSupplier;
|
||||
|
||||
public final class GrpcTestUtils {
|
||||
|
||||
@@ -27,8 +29,9 @@ public final class GrpcTestUtils {
|
||||
// noop
|
||||
}
|
||||
|
||||
public static StatusRuntimeException assertStatusException(final Status expected, final Executable serviceCall) {
|
||||
final StatusRuntimeException exception = Assertions.assertThrows(StatusRuntimeException.class, serviceCall);
|
||||
@CanIgnoreReturnValue
|
||||
public static StatusRuntimeException assertStatusException(final Status expected, final ThrowingSupplier<?> serviceCall) {
|
||||
final StatusRuntimeException exception = Assertions.assertThrows(StatusRuntimeException.class, serviceCall::get);
|
||||
assertEquals(expected.getCode(), exception.getStatus().getCode());
|
||||
|
||||
return exception;
|
||||
@@ -40,13 +43,14 @@ public final class GrpcTestUtils {
|
||||
assertEquals(expectedReason, extractErrorInfo(exception).getReason());
|
||||
}
|
||||
|
||||
public static void assertStatusException(final Status expected, final String expectedReason, final Executable serviceCall) {
|
||||
final StatusRuntimeException exception = Assertions.assertThrows(StatusRuntimeException.class, serviceCall);
|
||||
public static void assertStatusException(final Status expected, final String expectedReason, final ThrowingSupplier<?> serviceCall) {
|
||||
final StatusRuntimeException exception = Assertions.assertThrows(StatusRuntimeException.class, serviceCall::get);
|
||||
assertEquals(expected.getCode(), exception.getStatus().getCode());
|
||||
assertEquals(expectedReason, extractErrorInfo(exception).getReason());
|
||||
}
|
||||
|
||||
public static StatusRuntimeException assertStatusInvalidArgument(final Executable serviceCall) {
|
||||
@CanIgnoreReturnValue
|
||||
public static StatusRuntimeException assertStatusInvalidArgument(final ThrowingSupplier<?> serviceCall) {
|
||||
return assertStatusException(Status.INVALID_ARGUMENT, serviceCall);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ import static org.whispersystems.textsecuregcm.grpc.GrpcTestUtils.assertRateLimi
|
||||
import static org.whispersystems.textsecuregcm.grpc.GrpcTestUtils.assertStatusException;
|
||||
import static org.whispersystems.textsecuregcm.grpc.KeyTransparencyGrpcService.COMMITMENT_INDEX_LENGTH;
|
||||
|
||||
@SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "ThrowableNotThrown", "ResultOfMethodCallIgnored"})
|
||||
@SuppressWarnings({"OptionalUsedAsFieldOrParameterType", "ResultOfMethodCallIgnored"})
|
||||
public class KeyTransparencyGrpcServiceTest extends SimpleBaseGrpcTest<KeyTransparencyGrpcService, KeyTransparencyQueryServiceGrpc.KeyTransparencyQueryServiceBlockingStub>{
|
||||
@Mock
|
||||
private KeyTransparencyServiceClient keyTransparencyServiceClient;
|
||||
|
||||
-25
@@ -246,7 +246,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
.setPayload(ByteString.copyFrom(payload))
|
||||
.build());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().sendSingleRecipientMessage(
|
||||
generateRequest(serviceIdentifier, false, true, messages, UNIDENTIFIED_ACCESS_KEY, null)));
|
||||
@@ -414,7 +413,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
final SendSealedSenderMessageRequest request =
|
||||
generateRequest(pniIdentifier, false, true, messages, UNIDENTIFIED_ACCESS_KEY, null);
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(
|
||||
Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().sendSingleRecipientMessage(request));
|
||||
@@ -477,7 +475,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
doThrow(new MessageTooLargeException())
|
||||
.when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().sendSingleRecipientMessage(
|
||||
generateRequest(serviceIdentifier, false, true, messages, UNIDENTIFIED_ACCESS_KEY, null)));
|
||||
@@ -510,7 +507,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
Optional.of(GrpcChallengeResponse.withStatusException(GrpcExceptions.rateLimitExceeded(null))),
|
||||
Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED,
|
||||
() -> unauthenticatedServiceStub().sendSingleRecipientMessage(
|
||||
generateRequest(serviceIdentifier, false, true, messages, UNIDENTIFIED_ACCESS_KEY, null)));
|
||||
@@ -554,7 +550,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
final SendSealedSenderMessageRequest request =
|
||||
generateRequest(serviceIdentifier, false, true, messages, UNIDENTIFIED_ACCESS_KEY, null);
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED, () ->
|
||||
unauthenticatedServiceStub().sendSingleRecipientMessage(request));
|
||||
|
||||
@@ -594,7 +589,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
doThrow(MessageDeliveryNotAllowedException.class)
|
||||
.when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.UNAVAILABLE,
|
||||
() -> unauthenticatedServiceStub().sendSingleRecipientMessage(
|
||||
generateRequest(serviceIdentifier, false, false, messages,
|
||||
@@ -788,7 +782,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
.setUrgent(true)
|
||||
.build()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientMessage(SendMultiRecipientMessageRequest.newBuilder()
|
||||
.setMessage(MultiRecipientMessage.newBuilder()
|
||||
@@ -806,7 +799,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
@Test
|
||||
void badPayload()
|
||||
throws MessageTooLargeException, MultiRecipientMismatchedDevicesException, MessageDeliveryNotAllowedException {
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientMessage(SendMultiRecipientMessageRequest.newBuilder()
|
||||
.setMessage(MultiRecipientMessage.newBuilder()
|
||||
@@ -815,7 +807,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
.build())
|
||||
.build()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientMessage(SendMultiRecipientMessageRequest.newBuilder().build()));
|
||||
|
||||
@@ -841,7 +832,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
|
||||
final byte[] payload = MultiRecipientMessageHelper.generateMultiRecipientMessage(List.of(recipient, recipient));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientMessage(SendMultiRecipientMessageRequest.newBuilder()
|
||||
.setGroupSendToken(ByteString.copyFrom(GROUP_SEND_TOKEN))
|
||||
@@ -883,7 +873,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
doThrow(new MessageTooLargeException())
|
||||
.when(messageSender).sendMultiRecipientMessage(any(), any(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> unauthenticatedServiceStub().sendMultiRecipientMessage(request));
|
||||
}
|
||||
@@ -925,7 +914,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
Optional.of(GrpcChallengeResponse.withStatusException(GrpcExceptions.rateLimitExceeded(null))),
|
||||
Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED,
|
||||
() -> unauthenticatedServiceStub().sendMultiRecipientMessage(request));
|
||||
|
||||
@@ -972,7 +960,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
when(spamChecker.checkForMultiRecipientSpamGrpc(any()))
|
||||
.thenReturn(new SpamCheckResult<>(Optional.of(GrpcChallengeResponse.withResponse(challengeResponse)), Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED,
|
||||
() -> unauthenticatedServiceStub().sendMultiRecipientMessage(request));
|
||||
|
||||
@@ -1012,7 +999,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
doThrow(MessageDeliveryNotAllowedException.class)
|
||||
.when(messageSender).sendMultiRecipientMessage(any(), any(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.UNAVAILABLE,
|
||||
() -> unauthenticatedServiceStub().sendMultiRecipientMessage(request));
|
||||
}
|
||||
@@ -1198,7 +1184,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
|
||||
doThrow(new MessageTooLargeException()).when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusInvalidArgument(
|
||||
() -> unauthenticatedServiceStub().sendStory(generateRequest(serviceIdentifier, false, messages)));
|
||||
}
|
||||
@@ -1230,7 +1215,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
Optional.of(GrpcChallengeResponse.withStatusException(GrpcExceptions.rateLimitExceeded(null))),
|
||||
Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED,
|
||||
() -> unauthenticatedServiceStub().sendStory(generateRequest(serviceIdentifier, true, messages)));
|
||||
|
||||
@@ -1269,7 +1253,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
when(spamChecker.checkForIndividualRecipientSpamGrpc(any(), any(), any(), any()))
|
||||
.thenReturn(new SpamCheckResult<>(Optional.of(GrpcChallengeResponse.withResponse(challengeResponse)), Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED, () ->
|
||||
unauthenticatedServiceStub().sendStory(generateRequest(serviceIdentifier, true, messages)));
|
||||
|
||||
@@ -1308,7 +1291,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
doThrow(MessageDeliveryNotAllowedException.class)
|
||||
.when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.UNAVAILABLE,
|
||||
() -> unauthenticatedServiceStub().sendStory(generateRequest(serviceIdentifier, false, messages)));
|
||||
}
|
||||
@@ -1438,7 +1420,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
@Test
|
||||
void badPayload()
|
||||
throws MessageTooLargeException, MultiRecipientMismatchedDevicesException, MessageDeliveryNotAllowedException {
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientStory(SendMultiRecipientStoryRequest.newBuilder()
|
||||
.setMessage(MultiRecipientMessage.newBuilder()
|
||||
@@ -1447,7 +1428,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
.build())
|
||||
.build()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientMessage(
|
||||
SendMultiRecipientMessageRequest.newBuilder().build()));
|
||||
@@ -1474,7 +1454,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
|
||||
final byte[] payload = MultiRecipientMessageHelper.generateMultiRecipientMessage(List.of(recipient, recipient));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientStory(SendMultiRecipientStoryRequest.newBuilder()
|
||||
.setMessage(MultiRecipientMessage.newBuilder()
|
||||
@@ -1512,7 +1491,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
doThrow(new MessageTooLargeException())
|
||||
.when(messageSender).sendMultiRecipientMessage(any(), any(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusInvalidArgument(() -> unauthenticatedServiceStub().sendMultiRecipientStory(request));
|
||||
}
|
||||
|
||||
@@ -1551,7 +1529,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
Optional.of(GrpcChallengeResponse.withStatusException(GrpcExceptions.rateLimitExceeded(null))),
|
||||
Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED,
|
||||
() -> unauthenticatedServiceStub().sendMultiRecipientStory(request));
|
||||
|
||||
@@ -1596,7 +1573,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
when(spamChecker.checkForMultiRecipientSpamGrpc(any()))
|
||||
.thenReturn(new SpamCheckResult<>(Optional.of(GrpcChallengeResponse.withResponse(challengeResponse)), Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.RESOURCE_EXHAUSTED, () ->
|
||||
unauthenticatedServiceStub().sendMultiRecipientStory(request));
|
||||
|
||||
@@ -1643,7 +1619,6 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
.build())
|
||||
.build();
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
GrpcTestUtils.assertStatusException(Status.UNAVAILABLE,
|
||||
() -> unauthenticatedServiceStub().sendMultiRecipientStory(request));
|
||||
}
|
||||
|
||||
+9
-18
@@ -12,7 +12,6 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyByte;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
@@ -25,6 +24,7 @@ import static org.mockito.Mockito.when;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.Empty;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.Grpc;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.StatusException;
|
||||
import io.grpc.StatusRuntimeException;
|
||||
@@ -38,7 +38,6 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Stream;
|
||||
@@ -47,6 +46,7 @@ import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.jupiter.api.function.ThrowingSupplier;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
@@ -82,15 +82,12 @@ import org.whispersystems.textsecuregcm.spam.SpamChecker;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.MessageStreamEntry;
|
||||
import org.whispersystems.textsecuregcm.tests.util.DevicesHelper;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.TestClock;
|
||||
import org.whispersystems.textsecuregcm.util.TestRandomUtil;
|
||||
import org.whispersystems.textsecuregcm.util.UUIDUtil;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
import reactor.test.publisher.TestPublisher;
|
||||
|
||||
class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, MessagesGrpc.MessagesBlockingV2Stub> {
|
||||
|
||||
@@ -293,7 +290,6 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
.setType(SendMessageType.UNIDENTIFIED_SENDER)
|
||||
.build());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> authenticatedServiceStub()
|
||||
.sendMessage(generateRequest(serviceIdentifier, false, true, messages)));
|
||||
|
||||
@@ -415,7 +411,6 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
doThrow(new MessageTooLargeException())
|
||||
.when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
assertStatusException(Status.INVALID_ARGUMENT,
|
||||
() -> authenticatedServiceStub().sendMessage(
|
||||
generateRequest(serviceIdentifier, false, true, messages)));
|
||||
@@ -448,7 +443,6 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
Optional.of(GrpcChallengeResponse.withStatusException(GrpcExceptions.rateLimitExceeded(null))),
|
||||
Optional.empty()));
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
assertStatusException(Status.RESOURCE_EXHAUSTED, () -> authenticatedServiceStub()
|
||||
.sendMessage(generateRequest(serviceIdentifier, false, true, messages)));
|
||||
|
||||
@@ -530,7 +524,6 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
doThrow(MessageDeliveryNotAllowedException.class)
|
||||
.when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
assertStatusException(Status.UNAVAILABLE,
|
||||
() -> authenticatedServiceStub().sendMessage(generateRequest(serviceIdentifier, false, false, messages)));
|
||||
}
|
||||
@@ -721,7 +714,6 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
doThrow(new MessageTooLargeException())
|
||||
.when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> authenticatedServiceStub()
|
||||
.sendSyncMessage( generateRequest( true, messages)));
|
||||
}
|
||||
@@ -748,7 +740,6 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
doThrow(MessageDeliveryNotAllowedException.class)
|
||||
.when(messageSender).sendMessages(any(), any(), any(), any(), any(), any());
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored,ThrowableNotThrown
|
||||
assertStatusException(Status.UNAVAILABLE,
|
||||
() -> authenticatedServiceStub().sendSyncMessage(generateRequest(false, messages)));
|
||||
}
|
||||
@@ -778,7 +769,7 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
public void invalidFirstRequest() throws InterruptedException, StatusException {
|
||||
final BlockingClientCall<GetMessagesRequest, GetMessagesResponse> blockingCall = authenticatedServiceStub().getMessages();
|
||||
blockingCall.write(GetMessagesRequest.newBuilder().setServerGuidAck(UUIDUtil.toByteString(UUID.randomUUID())).build());
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> blockingCall.read());
|
||||
assertStatusException(Status.INVALID_ARGUMENT, blockingCall::read);
|
||||
}
|
||||
|
||||
|
||||
@@ -825,22 +816,22 @@ class MessagesGrpcServiceTest extends SimpleBaseGrpcTest<MessagesGrpcService, Me
|
||||
}
|
||||
}
|
||||
|
||||
private static Executable convertStatusException(final Executable serviceCall) {
|
||||
private static ThrowingSupplier<?> convertStatusException(final ThrowingSupplier<?> serviceCall) {
|
||||
return () -> {
|
||||
try {
|
||||
serviceCall.execute();
|
||||
return serviceCall.get();
|
||||
} catch (final StatusException e) {
|
||||
throw new StatusRuntimeException(e.getStatus(), e.getTrailers());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static StatusRuntimeException assertStatusException(final Status expected, final Executable serviceCall) {
|
||||
return GrpcTestUtils.assertStatusException(expected, convertStatusException(serviceCall));
|
||||
private static void assertRateLimitExceeded(final Duration expectedRetryAfter, final ThrowingSupplier<?> serviceCall) {
|
||||
GrpcTestUtils.assertRateLimitExceeded(expectedRetryAfter, convertStatusException(serviceCall)::get);
|
||||
}
|
||||
|
||||
private static void assertRateLimitExceeded(final Duration expectedRetryAfter, final Executable serviceCall) {
|
||||
GrpcTestUtils.assertRateLimitExceeded(expectedRetryAfter, convertStatusException(serviceCall));
|
||||
private static void assertStatusException(final Status expected, final ThrowingSupplier<?> serviceCall) {
|
||||
GrpcTestUtils.assertStatusException(expected, convertStatusException(serviceCall));
|
||||
}
|
||||
|
||||
}
|
||||
-2
@@ -428,7 +428,6 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
.build())
|
||||
.build();
|
||||
|
||||
//noinspection ThrowableNotThrown
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> unauthenticatedServiceStub().getProfile(request));
|
||||
}
|
||||
|
||||
@@ -439,7 +438,6 @@ public class ProfileAnonymousGrpcServiceTest extends SimpleBaseGrpcTest<ProfileA
|
||||
.setAccountIdentifier(GrpcServiceIdentifierUtil.toGrpcServiceIdentifier(new AciServiceIdentifier(UUID.randomUUID()))))
|
||||
.build();
|
||||
|
||||
//noinspection ThrowableNotThrown
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> unauthenticatedServiceStub().getProfile(request));
|
||||
}
|
||||
|
||||
|
||||
+44
-51
@@ -23,11 +23,9 @@ import java.util.stream.Stream;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
@@ -101,7 +99,7 @@ public class ValidatingInterceptorTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"15551234567", "", "123", "+1 555 1234567", "asdf"})
|
||||
public void testE164ValidationFailure(final String invalidNumber) throws Exception {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setNumber(invalidNumber)
|
||||
.build()
|
||||
@@ -111,7 +109,7 @@ public class ValidatingInterceptorTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"1====", "zzz?", "123/", "123+"})
|
||||
public void testBase64UrlValidationFailure(final String invalidBase64Url) {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setBase64Url(invalidBase64Url)
|
||||
.build()
|
||||
@@ -154,7 +152,7 @@ public class ValidatingInterceptorTest {
|
||||
@EnumSource(value = org.signal.chat.common.IdentityType.class, names = {"IDENTITY_TYPE_UNSPECIFIED", "IDENTITY_TYPE_PNI"})
|
||||
public void testServiceIdentifierIdentityTypeAciValidationFailure(final IdentityType identityType) {
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.setAciServiceIdentifier(ServiceIdentifier.newBuilder()
|
||||
.setIdentityType(identityType)
|
||||
.setUuid(UUIDUtil.toByteString(UUID.randomUUID())))
|
||||
@@ -165,7 +163,7 @@ public class ValidatingInterceptorTest {
|
||||
@EnumSource(value = org.signal.chat.common.IdentityType.class, names = {"IDENTITY_TYPE_UNSPECIFIED", "IDENTITY_TYPE_ACI"})
|
||||
public void testServiceIdentifierIdentityTypePniValidationFailure(final IdentityType identityType) {
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.setPniServiceIdentifier(ServiceIdentifier.newBuilder()
|
||||
.setIdentityType(identityType)
|
||||
.setUuid(UUIDUtil.toByteString(UUID.randomUUID())))
|
||||
@@ -176,14 +174,14 @@ public class ValidatingInterceptorTest {
|
||||
@ValueSource(ints = {0, 1, 2, 3, 4, 6, 1000})
|
||||
public void testExactlySizeValidationFailure(final int size) throws Exception {
|
||||
final String stringValue = RandomStringUtils.secure().nextAlphanumeric(size);
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setFixedSizeString(stringValue)
|
||||
.build()
|
||||
));
|
||||
|
||||
final ByteString byteValue = ByteString.copyFrom(TestRandomUtil.nextBytes(size));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setFixedSizeBytes(byteValue)
|
||||
.build()
|
||||
@@ -192,7 +190,7 @@ public class ValidatingInterceptorTest {
|
||||
final List<String> listValue = IntStream.range(0, size)
|
||||
.mapToObj(i -> RandomStringUtils.secure().nextAlphabetic(10))
|
||||
.toList();
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearFixedSizeList()
|
||||
.addAllFixedSizeList(listValue)
|
||||
@@ -202,17 +200,17 @@ public class ValidatingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testExactlySizeMultiplePermittedValues() throws Exception {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setExactlySizeVariants("abc")
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setExactlySizeVariants("")
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearExactlySizeVariants()
|
||||
.build()
|
||||
@@ -293,12 +291,12 @@ public class ValidatingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testNotOptionalWithMinLimit() throws Exception {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearWithMinBytes()
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearWithMinString()
|
||||
.build()
|
||||
@@ -323,49 +321,49 @@ public class ValidatingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testNonEmpty() throws Exception {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearNonEmptyList()
|
||||
.build()
|
||||
));
|
||||
// check not setting a value
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearNonEmptyBytes()
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearNonEmptyBytesOptional()
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearNonEmptyString()
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearNonEmptyStringOptional()
|
||||
.build()
|
||||
));
|
||||
// now check explicitly setting an empty value
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setNonEmptyBytes(ByteString.EMPTY)
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setNonEmptyBytesOptional(ByteString.EMPTY)
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setNonEmptyString("")
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setNonEmptyStringOptional("")
|
||||
.build()
|
||||
@@ -374,22 +372,22 @@ public class ValidatingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testEnumSpecified() throws Exception {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearColor()
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setColor(Color.COLOR_UNSPECIFIED)
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearColorOptional()
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setColorOptional(Color.COLOR_UNSPECIFIED)
|
||||
.build()
|
||||
@@ -398,27 +396,27 @@ public class ValidatingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testRange() throws Exception {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setI32(1000)
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setUi32(-1)
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearI32Range()
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setI32OptRange(5)
|
||||
.build()
|
||||
));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.setI32OptRange(1000)
|
||||
.build()
|
||||
@@ -427,13 +425,13 @@ public class ValidatingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testPresent() throws Exception {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearPresentMessage()
|
||||
.build()
|
||||
));
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(
|
||||
builderWithValidDefaults()
|
||||
.clearOptionalPresentMessage()
|
||||
.build()
|
||||
@@ -455,7 +453,7 @@ public class ValidatingInterceptorTest {
|
||||
.build()));
|
||||
|
||||
// second element is the wrong length
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.addEachExactlyBytes(ByteString.copyFrom(new byte[4]))
|
||||
.addEachExactlyBytes(ByteString.copyFrom(new byte[3]))
|
||||
.build()));
|
||||
@@ -468,10 +466,10 @@ public class ValidatingInterceptorTest {
|
||||
.addEachRange(127)
|
||||
.build()));
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.addEachRange(0)
|
||||
.build()));
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.addEachRange(128)
|
||||
.build()));
|
||||
}
|
||||
@@ -482,7 +480,7 @@ public class ValidatingInterceptorTest {
|
||||
.addEachNonEmpty("a")
|
||||
.build()));
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.addEachNonEmpty("a")
|
||||
.addEachNonEmpty("")
|
||||
.build()));
|
||||
@@ -491,12 +489,12 @@ public class ValidatingInterceptorTest {
|
||||
@Test
|
||||
public void eachCombinedWithCollectionConstraint() {
|
||||
// empty list fails the collection-level `size {min:1}` constraint
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.clearEachCombined()
|
||||
.build()));
|
||||
|
||||
// too many elements (collection-level `size {max:3}`)
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.clearEachCombined()
|
||||
.addEachCombined(ByteString.copyFrom(new byte[4]))
|
||||
.addEachCombined(ByteString.copyFrom(new byte[4]))
|
||||
@@ -505,7 +503,7 @@ public class ValidatingInterceptorTest {
|
||||
.build()));
|
||||
|
||||
// count is in range but an element is the wrong length
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.clearEachCombined()
|
||||
.addEachCombined(ByteString.copyFrom(new byte[3]))
|
||||
.build()));
|
||||
@@ -520,15 +518,15 @@ public class ValidatingInterceptorTest {
|
||||
|
||||
@Test
|
||||
public void testFailedValidationOnNestedMessage() {
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
stub.validationsEndpoint(builderWithValidDefaults().setNested(NestedMessage.newBuilder().setI32(101)).build()));
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.clearRepeatedNested()
|
||||
.addRepeatedNested(NestedMessage.newBuilder().setI32(101)).build()));
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
stub.validationsEndpoint(builderWithValidDefaults()
|
||||
.clearMapNested()
|
||||
.putMapNested("foo", NestedMessage.newBuilder().setI32(101).build()).build()));
|
||||
@@ -545,7 +543,7 @@ public class ValidatingInterceptorTest {
|
||||
curr = pred;
|
||||
}
|
||||
final RecursiveMessage recursiveMessage = curr.build();
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () ->
|
||||
stub.validationsEndpoint(builderWithValidDefaults().setRecursiveMessage(recursiveMessage).build()));
|
||||
}
|
||||
|
||||
@@ -562,7 +560,7 @@ public class ValidatingInterceptorTest {
|
||||
.setOneOfMessage(ValidationsRequest.RequirePresentMessage.getDefaultInstance())
|
||||
.build()));
|
||||
|
||||
assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(ValidationsRequest.newBuilder().setOneOfNonEmptyBytes(ByteString.EMPTY).build()));
|
||||
GrpcTestUtils.assertStatusException(Status.INVALID_ARGUMENT, () -> stub.validationsEndpoint(ValidationsRequest.newBuilder().setOneOfNonEmptyBytes(ByteString.EMPTY).build()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -605,11 +603,6 @@ public class ValidatingInterceptorTest {
|
||||
.addEachCombined(ByteString.copyFrom(new byte[4]));
|
||||
}
|
||||
|
||||
private static void assertStatusException(final Status expected, final Executable serviceCall) {
|
||||
final StatusRuntimeException exception = Assertions.assertThrows(StatusRuntimeException.class, serviceCall);
|
||||
assertEquals(expected.getCode(), exception.getStatus().getCode());
|
||||
}
|
||||
|
||||
private static Status requestStatus(final Runnable runnable) {
|
||||
try {
|
||||
runnable.run();
|
||||
|
||||
-1
@@ -151,7 +151,6 @@ class MetricsHttpEventHandlerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
@SuppressWarnings("unchecked")
|
||||
void testRequestsByVersion(final boolean versionActive) {
|
||||
when(clientReleaseManager.isVersionActive(any(), any())).thenReturn(versionActive);
|
||||
final String path = "/test";
|
||||
|
||||
Reference in new issue
Block a user