From 1ab6bff54e3cad26ba3570ace5583226c5944b19 Mon Sep 17 00:00:00 2001 From: Jonathan Klabunde Tomer <125505367+jkt-signal@users.noreply.github.com> Date: Thu, 25 May 2023 07:57:06 -0700 Subject: [PATCH] add `@Produces` annotations to a few methods in DeviceController --- .../controllers/DeviceController.java | 3 +++ .../controllers/DeviceControllerTest.java | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java index edd144380..efb3db938 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java @@ -101,6 +101,7 @@ public class DeviceController { @Timed @DELETE + @Produces(MediaType.APPLICATION_JSON) @Path("/{device_id}") @ChangesDeviceEnabledState public void removeDevice(@Auth AuthenticatedAccount auth, @PathParam("device_id") long deviceId) { @@ -217,6 +218,7 @@ public class DeviceController { @Timed @PUT + @Produces(MediaType.APPLICATION_JSON) @Path("/unauthenticated_delivery") public void setUnauthenticatedDelivery(@Auth AuthenticatedAccount auth) { assert (auth.getAuthenticatedDevice() != null); @@ -225,6 +227,7 @@ public class DeviceController { @Timed @PUT + @Produces(MediaType.APPLICATION_JSON) @Path("/capabilities") public void setCapabilities(@Auth AuthenticatedAccount auth, @NotNull @Valid DeviceCapabilities capabilities) { assert (auth.getAuthenticatedDevice() != null); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java index 08739bc94..c7e1417cb 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DeviceControllerTest.java @@ -758,6 +758,32 @@ class DeviceControllerTest { assertThat(response.getStatus()).isEqualTo(200); } + @Test + void putCapabilitiesSuccessTest() { + final DeviceCapabilities deviceCapabilities = new DeviceCapabilities(true, true, true, true, true, true, true, true, true); + final Response response = resources + .getJerseyTest() + .target("/v1/devices/capabilities") + .request() + .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) + .header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30") + .put(Entity.entity(deviceCapabilities, MediaType.APPLICATION_JSON_TYPE)); + assertThat(response.getStatus()).isEqualTo(204); + assertThat(response.hasEntity()).isFalse(); + } + + @Test + void putCapabilitiesFailureTest() { + final Response response = resources + .getJerseyTest() + .target("/v1/devices/capabilities") + .request() + .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) + .header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30") + .put(Entity.json("")); + assertThat(response.getStatus()).isEqualTo(422); + } + @ParameterizedTest @ValueSource(booleans = {true, false}) void deviceDowngradePaymentActivationTest(boolean paymentActivation) { @@ -791,6 +817,7 @@ class DeviceControllerTest { .delete(); assertThat(response.getStatus()).isEqualTo(204); + assertThat(response.hasEntity()).isFalse(); verify(messagesManager, times(2)).clear(AuthHelper.VALID_UUID, deviceId); verify(accountsManager, times(1)).update(eq(AuthHelper.VALID_ACCOUNT), any());