diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java index f6bb0c5ab..3572ff299 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/IncomingMessageList.java @@ -4,21 +4,17 @@ */ package org.whispersystems.textsecuregcm.entities; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; - +import java.util.List; import javax.validation.Valid; import javax.validation.constraints.NotNull; -import java.util.List; public class IncomingMessageList { @JsonProperty @NotNull @Valid - @JsonInclude(Include.NON_NULL) - private List messages; + private List<@NotNull IncomingMessage> messages; @JsonProperty private long timestamp; diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java index 91d700146..53b8679e3 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java @@ -247,6 +247,19 @@ class MessageControllerTest { assertTrue(captor.getValue().hasSourceDevice()); } + @Test + void testNullMessageInList() throws Exception { + Response response = + resources.getJerseyTest() + .target(String.format("/v1/messages/%s", SINGLE_DEVICE_RECIPIENT)) + .request() + .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.VALID_PASSWORD)) + .put(Entity.entity(mapper.readValue(jsonFixture("fixtures/current_message_null_message_in_list.json"), IncomingMessageList.class), + MediaType.APPLICATION_JSON_TYPE)); + + assertThat("Bad request", response.getStatus(), is(equalTo(422))); + } + @Test void testInternationalUnsealedSenderFromRateLimitedHost() throws Exception { final String senderHost = "10.0.0.1"; diff --git a/service/src/test/resources/fixtures/current_message_null_message_in_list.json b/service/src/test/resources/fixtures/current_message_null_message_in_list.json new file mode 100644 index 000000000..501259ca7 --- /dev/null +++ b/service/src/test/resources/fixtures/current_message_null_message_in_list.json @@ -0,0 +1,8 @@ +{ + "messages" : [ { + "type" : 1, + "destinationDeviceId" : 1, + "body" : "Zm9vYmFyego", + "timestamp" : 1234 + }, null ] +}