mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 11:26:47 +00:00
Add annotation to catch empty request body
This commit is contained in:
1 parent
0706171264
commit
1b747d06df
3 files changed
+27
-3
No files matched your search
+2
-1
@@ -11,6 +11,7 @@ import org.whispersystems.textsecuregcm.auth.AuthenticatedAccount;
|
||||
import org.whispersystems.textsecuregcm.entities.CreateCallLinkCredential;
|
||||
import org.whispersystems.textsecuregcm.entities.GetCreateCallLinkCredentialsRequest;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.ws.rs.BadRequestException;
|
||||
import javax.ws.rs.POST;
|
||||
@@ -52,7 +53,7 @@ public class CallLinkController {
|
||||
@ApiResponse(responseCode = "429", description = "Ratelimited.")
|
||||
public CreateCallLinkCredential getCreateAuth(
|
||||
final @Auth AuthenticatedAccount auth,
|
||||
final @NotNull GetCreateCallLinkCredentialsRequest request
|
||||
final @NotNull @Valid GetCreateCallLinkCredentialsRequest request
|
||||
) throws RateLimitExceededException {
|
||||
|
||||
rateLimiters.getCreateCallLinkLimiter().validate(auth.getAccount().getUuid());
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package org.whispersystems.textsecuregcm.entities;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
public record GetCreateCallLinkCredentialsRequest(@NotNull byte[] createCallLinkCredentialRequest) {}
|
||||
|
||||
public record GetCreateCallLinkCredentialsRequest(@NotEmpty byte[] createCallLinkCredentialRequest) {}
|
||||
+22
@@ -100,6 +100,28 @@ public class CallLinkControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetCreateAuthInvalidInputEmptyRequestBody() {
|
||||
try (Response response = resources.getJerseyTest()
|
||||
.target("/v1/call-link/create-auth")
|
||||
.request()
|
||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.post(Entity.json("{}"))) {
|
||||
assertThat(response.getStatus()).isEqualTo(422);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetCreateAuthInvalidInputEmptyField() {
|
||||
try (Response response = resources.getJerseyTest()
|
||||
.target("/v1/call-link/create-auth")
|
||||
.request()
|
||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.post(Entity.json("{\"createCallLinkCredentialRequest\": \"\"}"))) {
|
||||
assertThat(response.getStatus()).isEqualTo(422);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetCreateAuthRatelimited() throws RateLimitExceededException{
|
||||
doThrow(new RateLimitExceededException(null, false))
|
||||
|
||||
Reference in new issue
Block a user