diff --git a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java index 8bf4ce05b..e16cf632c 100644 --- a/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java +++ b/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/MessageControllerTest.java @@ -10,6 +10,7 @@ import org.whispersystems.textsecuregcm.entities.AccountAttributes; import org.whispersystems.textsecuregcm.entities.IncomingMessageList; import org.whispersystems.textsecuregcm.entities.MessageProtos; import org.whispersystems.textsecuregcm.entities.MismatchedDevices; +import org.whispersystems.textsecuregcm.entities.StaleDevices; import org.whispersystems.textsecuregcm.federation.FederatedClientManager; import org.whispersystems.textsecuregcm.limits.RateLimiter; import org.whispersystems.textsecuregcm.limits.RateLimiters; @@ -151,4 +152,23 @@ public class MessageControllerTest extends ResourceTest { verify(pushSender, times(2)).sendMessage(any(Account.class), any(Device.class), any(MessageProtos.OutgoingMessageSignal.class)); } + @Test + public void testRegistrationIdMismatch() throws Exception { + ClientResponse response = + client().resource(String.format("/v1/messages/%s", MULTI_DEVICE_RECIPIENT)) + .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.VALID_PASSWORD)) + .entity(mapper.readValue(jsonFixture("fixtures/current_message_registration_id.json"), IncomingMessageList.class)) + .type(MediaType.APPLICATION_JSON_TYPE) + .put(ClientResponse.class); + + assertThat("Good Response Code", response.getStatus(), is(equalTo(410))); + + assertThat("Good Response Body", + asJson(response.getEntity(StaleDevices.class)), + is(equalTo(jsonFixture("fixtures/mismatched_registration_id.json")))); + + verifyNoMoreInteractions(pushSender); + + } + } diff --git a/src/test/resources/fixtures/current_message_multi_device.json b/src/test/resources/fixtures/current_message_multi_device.json index 7061d7f3c..a04c8a3a7 100644 --- a/src/test/resources/fixtures/current_message_multi_device.json +++ b/src/test/resources/fixtures/current_message_multi_device.json @@ -2,12 +2,14 @@ "messages" : [{ "type" : 1, "destinationDeviceId" : 1, + "destinationRegistrationId" : 222, "body" : "Zm9vYmFyego", "timestamp" : 1234 }, { "type" : 1, "destinationDeviceId" : 2, + "destinationRegistrationId" : 333, "body" : "Zm9vYmFyego", "timestamp" : 1234 }] diff --git a/src/test/resources/fixtures/current_message_registration_id.json b/src/test/resources/fixtures/current_message_registration_id.json new file mode 100644 index 000000000..f86fcfc47 --- /dev/null +++ b/src/test/resources/fixtures/current_message_registration_id.json @@ -0,0 +1,16 @@ +{ + "messages" : [{ + "type" : 1, + "destinationDeviceId" : 1, + "destinationRegistrationId" : 222, + "body" : "Zm9vYmFyego", + "timestamp" : 1234 + }, + { + "type" : 1, + "destinationDeviceId" : 2, + "destinationRegistrationId" : 999, + "body" : "Zm9vYmFyego", + "timestamp" : 1234 + }] +} \ No newline at end of file diff --git a/src/test/resources/fixtures/mismatched_registration_id.json b/src/test/resources/fixtures/mismatched_registration_id.json new file mode 100644 index 000000000..273eea57d --- /dev/null +++ b/src/test/resources/fixtures/mismatched_registration_id.json @@ -0,0 +1,3 @@ +{ + "staleDevices" : [2] +} \ No newline at end of file