Add registrationId tests.

This commit is contained in:
Moxie Marlinspike 2014-02-20 09:44:31 -08:00
parent f4ecb5d7be
commit 6aaca59020
4 changed files with 41 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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
}]

View File

@ -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
}]
}

View File

@ -0,0 +1,3 @@
{
"staleDevices" : [2]
}