Migrate to 429 for all ratelimit responses

This commit is contained in:
Katherine
2024-08-05 12:02:11 -07:00
committed by GitHub
parent 10d559bbb5
commit 0e4625ef88
33 changed files with 63 additions and 110 deletions

View File

@@ -912,7 +912,7 @@ class AccountControllerTest {
.request()
.head()) {
assertThat(response.getStatus()).isEqualTo(413);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaderString("Retry-After")).isEqualTo(String.valueOf(expectedRetryAfter.toSeconds()));
}
}
@@ -963,7 +963,7 @@ class AccountControllerTest {
.request()
.get();
assertThat(response.getStatus()).isEqualTo(413);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaderString("Retry-After")).isEqualTo(String.valueOf(expectedRetryAfter.toSeconds()));
}

View File

@@ -292,7 +292,7 @@ class AccountControllerV2Test {
@Test
void rateLimitedNumber() throws Exception {
doThrow(new RateLimitExceededException(null, true))
doThrow(new RateLimitExceededException(null))
.when(registrationLimiter).validate(anyString());
final Invocation.Builder request = resources.getJerseyTest()
@@ -364,7 +364,7 @@ class AccountControllerV2Test {
final Exception e = switch (error) {
case MISMATCH -> new WebApplicationException(error.getExpectedStatus());
case RATE_LIMITED -> new RateLimitExceededException(null, true);
case RATE_LIMITED -> new RateLimitExceededException(null);
};
doThrow(e)
.when(registrationLockVerificationManager).verifyRegistrationLock(any(), any(), any(), any(), any());

View File

@@ -252,7 +252,7 @@ public class ArchiveControllerTest {
public static Stream<Arguments> setBackupIdException() {
return Stream.of(
Arguments.of(new RateLimitExceededException(null, false), false, 429),
Arguments.of(new RateLimitExceededException(null), false, 429),
Arguments.of(Status.INVALID_ARGUMENT.withDescription("async").asRuntimeException(), false, 400),
Arguments.of(Status.INVALID_ARGUMENT.withDescription("sync").asRuntimeException(), true, 400)
);
@@ -529,7 +529,7 @@ public class ArchiveControllerTest {
// rate limit
when(backupManager.createTemporaryAttachmentUploadDescriptor(any()))
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null, false)));
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null)));
final Response response = resources.getJerseyTest()
.target("v1/archives/media/upload/form")
.request()

View File

@@ -122,7 +122,7 @@ public class CallLinkControllerTest {
@Test
void testGetCreateAuthRatelimited() throws RateLimitExceededException{
doThrow(new RateLimitExceededException(null, false))
doThrow(new RateLimitExceededException(null))
.when(createCallLinkLimiter).validate(AuthHelper.VALID_UUID);
try (Response response = resources.getJerseyTest()

View File

@@ -170,7 +170,7 @@ class CallRoutingControllerTest {
@Test
void testGetTurnEndpointRateLimited() throws RateLimitExceededException {
doThrow(new RateLimitExceededException(null, false))
doThrow(new RateLimitExceededException(null))
.when(getCallEndpointLimiter).validate(AuthHelper.VALID_UUID);
try (final Response response = resources.getJerseyTest()

View File

@@ -100,7 +100,7 @@ class ChallengeControllerTest {
""";
final Duration retryAfter = Duration.ofMinutes(17);
doThrow(new RateLimitExceededException(retryAfter, true)).when(rateLimitChallengeManager)
doThrow(new RateLimitExceededException(retryAfter)).when(rateLimitChallengeManager)
.answerPushChallenge(any(), any());
final Response response = EXTENSION.target("/v1/challenge")
@@ -108,7 +108,7 @@ class ChallengeControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.put(Entity.json(pushChallengeJson));
assertEquals(413, response.getStatus());
assertEquals(429, response.getStatus());
assertEquals(String.valueOf(retryAfter.toSeconds()), response.getHeaderString("Retry-After"));
}
@@ -175,7 +175,7 @@ class ChallengeControllerTest {
""";
final Duration retryAfter = Duration.ofMinutes(17);
doThrow(new RateLimitExceededException(retryAfter, true)).when(rateLimitChallengeManager)
doThrow(new RateLimitExceededException(retryAfter)).when(rateLimitChallengeManager)
.answerCaptchaChallenge(any(), any(), any(), any(), any());
final Response response = EXTENSION.target("/v1/challenge")
@@ -183,7 +183,7 @@ class ChallengeControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.put(Entity.json(captchaChallengeJson));
assertEquals(413, response.getStatus());
assertEquals(429, response.getStatus());
assertEquals(String.valueOf(retryAfter.toSeconds()), response.getHeaderString("Retry-After"));
}

View File

@@ -462,7 +462,7 @@ class KeysControllerTest {
@Test
void testGetKeysRateLimited() throws RateLimitExceededException {
Duration retryAfter = Duration.ofSeconds(31);
doThrow(new RateLimitExceededException(retryAfter, true)).when(rateLimiter).validate(anyString());
doThrow(new RateLimitExceededException(retryAfter)).when(rateLimiter).validate(anyString());
Response result = resources.getJerseyTest()
.target(String.format("/v2/keys/PNI:%s/*", EXISTS_PNI))
@@ -470,7 +470,7 @@ class KeysControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get();
assertThat(result.getStatus()).isEqualTo(413);
assertThat(result.getStatus()).isEqualTo(429);
assertThat(result.getHeaderString("Retry-After")).isEqualTo(String.valueOf(retryAfter.toSeconds()));
}

View File

@@ -1695,10 +1695,10 @@ class MessageControllerTest {
.header(HeaderUtils.UNIDENTIFIED_ACCESS_KEY, Base64.getEncoder().encodeToString(UNIDENTIFIED_ACCESS_BYTES));
when(rateLimiter.validateAsync(any(UUID.class)))
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(Duration.ofSeconds(77), true)));
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(Duration.ofSeconds(77))));
try (final Response response = invocationBuilder.put(entity)) {
assertEquals(413, response.getStatus());
assertEquals(429, response.getStatus());
}
}

View File

@@ -263,7 +263,7 @@ class ProfileControllerTest {
@Test
void testProfileGetByAciRateLimited() throws RateLimitExceededException {
doThrow(new RateLimitExceededException(Duration.ofSeconds(13), true)).when(rateLimiter)
doThrow(new RateLimitExceededException(Duration.ofSeconds(13))).when(rateLimiter)
.validate(AuthHelper.VALID_UUID);
final Response response = resources.getJerseyTest()
@@ -272,7 +272,7 @@ class ProfileControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get();
assertThat(response.getStatus()).isEqualTo(413);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaderString("Retry-After")).isEqualTo(String.valueOf(Duration.ofSeconds(13).toSeconds()));
}
@@ -392,7 +392,7 @@ class ProfileControllerTest {
@Test
void testProfileGetByPniRateLimited() throws RateLimitExceededException {
doThrow(new RateLimitExceededException(Duration.ofSeconds(13), true)).when(rateLimiter)
doThrow(new RateLimitExceededException(Duration.ofSeconds(13))).when(rateLimiter)
.validate(AuthHelper.VALID_UUID);
final Response response = resources.getJerseyTest()
@@ -401,7 +401,7 @@ class ProfileControllerTest {
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
.get();
assertThat(response.getStatus()).isEqualTo(413);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaderString("Retry-After")).isEqualTo(String.valueOf(Duration.ofSeconds(13).toSeconds()));
}

View File

@@ -101,7 +101,7 @@ class ProvisioningControllerTest {
final String destination = UUID.randomUUID().toString();
final byte[] messageBody = "test".getBytes(StandardCharsets.UTF_8);
doThrow(new RateLimitExceededException(Duration.ZERO, true))
doThrow(new RateLimitExceededException(Duration.ZERO))
.when(messagesRateLimiter).validate(AuthHelper.VALID_UUID);
try (final Response response = RESOURCE_EXTENSION.getJerseyTest()
@@ -111,7 +111,7 @@ class ProvisioningControllerTest {
.put(Entity.entity(new ProvisioningMessage(Base64.getMimeEncoder().encodeToString(messageBody)),
MediaType.APPLICATION_JSON))) {
assertEquals(413, response.getStatus());
assertEquals(429, response.getStatus());
verify(provisioningManager, never()).sendProvisioningMessage(any(), any());
}

View File

@@ -339,7 +339,7 @@ class RegistrationControllerTest {
} else if (error != null) {
final Exception e = switch (error) {
case MISMATCH -> new WebApplicationException(error.getExpectedStatus());
case RATE_LIMITED -> new RateLimitExceededException(null, true);
case RATE_LIMITED -> new RateLimitExceededException(null);
};
doThrow(e)
.when(registrationLockVerificationManager).verifyRegistrationLock(any(), any(), any(), any(), any());

View File

@@ -180,7 +180,7 @@ class VerificationControllerTest {
@Test
void createSessionRateLimited() {
when(registrationServiceClient.createRegistrationSession(any(), anyBoolean(), any()))
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null, true)));
.thenReturn(CompletableFuture.failedFuture(new RateLimitExceededException(null)));
final Invocation.Builder request = resources.getJerseyTest()
.target("/v1/verification/session")