mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 01:06:50 +00:00
Add a (failing!) test for rate-limiting multi-recipient story sends via gRPC
This commit is contained in:
1 parent
ef9df20be4
commit
3bac6e5fd3
1 file changed
+32
+32
@@ -1514,6 +1514,38 @@ class MessagesAnonymousGrpcServiceTest extends
|
||||
.sendMultiRecipientMessage(any(), any(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rateLimited()
|
||||
throws MessageTooLargeException, MessageDeliveryNotAllowedException, MultiRecipientMismatchedDevicesException {
|
||||
|
||||
final AciServiceIdentifier serviceIdentifier = new AciServiceIdentifier(UUID.randomUUID());
|
||||
final Account destinationAccount = mock(Account.class);
|
||||
when(destinationAccount.getAccountIdentifier()).thenReturn(serviceIdentifier.uuid());
|
||||
|
||||
when(accountsManager.getByServiceIdentifierAsync(serviceIdentifier))
|
||||
.thenReturn(CompletableFuture.completedFuture(Optional.of(destinationAccount)));
|
||||
|
||||
final byte[] payload = MultiRecipientMessageHelper.generateMultiRecipientMessage(List.of(
|
||||
new TestRecipient(serviceIdentifier, Device.PRIMARY_ID, 17, new byte[48])));
|
||||
|
||||
final SendMultiRecipientStoryRequest request = SendMultiRecipientStoryRequest.newBuilder()
|
||||
.setMessage(MultiRecipientMessage.newBuilder()
|
||||
.setTimestamp(CLOCK.millis())
|
||||
.setPayload(ByteString.copyFrom(payload))
|
||||
.build())
|
||||
.setUrgent(true)
|
||||
.build();
|
||||
|
||||
final Duration retryDuration = Duration.ofHours(7);
|
||||
when(rateLimiter.validateAsync(any(UUID.class)))
|
||||
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(retryDuration)));
|
||||
|
||||
GrpcTestUtils.assertRateLimitExceeded(retryDuration, () -> unauthenticatedServiceStub().sendMultiRecipientStory(request));
|
||||
|
||||
verify(messageSender, never())
|
||||
.sendMultiRecipientMessage(any(), any(), anyLong(), anyBoolean(), anyBoolean(), anyBoolean(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void oversizedMessage()
|
||||
throws MessageTooLargeException, MultiRecipientMismatchedDevicesException, MessageDeliveryNotAllowedException {
|
||||
|
||||
Reference in new issue
Block a user