mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-26 15:13:18 +01:00
Support for vpush only retries
This commit is contained in:
@@ -20,6 +20,7 @@ import org.whispersystems.textsecuregcm.entities.SignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.federation.FederatedClientManager;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
@@ -56,13 +57,14 @@ public class FederatedControllerTest {
|
||||
private MessagesManager messagesManager = mock(MessagesManager.class);
|
||||
private RateLimiters rateLimiters = mock(RateLimiters.class );
|
||||
private RateLimiter rateLimiter = mock(RateLimiter.class );
|
||||
private ApnFallbackManager apnFallbackManager = mock(ApnFallbackManager.class);
|
||||
|
||||
private final SignedPreKey signedPreKey = new SignedPreKey(3333, "foo", "baar");
|
||||
private final PreKeyResponse preKeyResponseV2 = new PreKeyResponse("foo", new LinkedList<PreKeyResponseItem>());
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private final MessageController messageController = new MessageController(rateLimiters, pushSender, receiptSender, accountsManager, messagesManager, federatedClientManager);
|
||||
private final MessageController messageController = new MessageController(rateLimiters, pushSender, receiptSender, accountsManager, messagesManager, federatedClientManager, apnFallbackManager);
|
||||
private final KeysController keysControllerV2 = mock(KeysController.class);
|
||||
|
||||
@Rule
|
||||
@@ -112,7 +114,7 @@ public class FederatedControllerTest {
|
||||
|
||||
assertThat("Good Response", response.getStatus(), is(equalTo(204)));
|
||||
|
||||
verify(pushSender).sendMessage(any(Account.class), any(Device.class), any(MessageProtos.Envelope.class), eq(false));
|
||||
verify(pushSender).sendMessage(any(Account.class), any(Device.class), any(MessageProtos.Envelope.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.whispersystems.textsecuregcm.entities.StaleDevices;
|
||||
import org.whispersystems.textsecuregcm.federation.FederatedClientManager;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
@@ -58,6 +59,7 @@ public class MessageControllerTest {
|
||||
private final MessagesManager messagesManager = mock(MessagesManager.class);
|
||||
private final RateLimiters rateLimiters = mock(RateLimiters.class );
|
||||
private final RateLimiter rateLimiter = mock(RateLimiter.class );
|
||||
private final ApnFallbackManager apnFallbackManager = mock(ApnFallbackManager.class);
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@@ -67,7 +69,7 @@ public class MessageControllerTest {
|
||||
.addProvider(new AuthValueFactoryProvider.Binder())
|
||||
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
|
||||
.addResource(new MessageController(rateLimiters, pushSender, receiptSender, accountsManager,
|
||||
messagesManager, federatedClientManager))
|
||||
messagesManager, federatedClientManager, apnFallbackManager))
|
||||
.build();
|
||||
|
||||
|
||||
@@ -104,7 +106,7 @@ public class MessageControllerTest {
|
||||
|
||||
assertThat("Good Response", response.getStatus(), is(equalTo(200)));
|
||||
|
||||
verify(pushSender, times(1)).sendMessage(any(Account.class), any(Device.class), any(Envelope.class), eq(false));
|
||||
verify(pushSender, times(1)).sendMessage(any(Account.class), any(Device.class), any(Envelope.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +159,7 @@ public class MessageControllerTest {
|
||||
|
||||
assertThat("Good Response Code", response.getStatus(), is(equalTo(200)));
|
||||
|
||||
verify(pushSender, times(2)).sendMessage(any(Account.class), any(Device.class), any(Envelope.class), eq(false));
|
||||
verify(pushSender, times(2)).sendMessage(any(Account.class), any(Device.class), any(Envelope.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.tests.util.SynchronousExecutorService;
|
||||
import org.whispersystems.textsecuregcm.websocket.WebsocketAddress;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -64,7 +63,7 @@ public class APNSenderTest {
|
||||
.thenReturn(result);
|
||||
|
||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, true);
|
||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
|
||||
apnSender.setApnFallbackManager(fallbackManager);
|
||||
@@ -75,8 +74,8 @@ public class APNSenderTest {
|
||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(ApnMessage.MAX_EXPIRATION));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(ApnMessage.APN_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
assertThat(notification.getValue().getTopic()).isEqualTo("foo.voip");
|
||||
|
||||
@@ -101,7 +100,7 @@ public class APNSenderTest {
|
||||
.thenReturn(result);
|
||||
|
||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", false, 30);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, false);
|
||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
apnSender.setApnFallbackManager(fallbackManager);
|
||||
|
||||
@@ -112,8 +111,8 @@ public class APNSenderTest {
|
||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(ApnMessage.MAX_EXPIRATION));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(ApnMessage.APN_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
assertThat(notification.getValue().getTopic()).isEqualTo("foo");
|
||||
|
||||
@@ -124,57 +123,57 @@ public class APNSenderTest {
|
||||
verifyNoMoreInteractions(fallbackManager);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testUnregisteredUser() throws Exception {
|
||||
// ApnsClient apnsClient = mock(ApnsClient.class);
|
||||
//
|
||||
// PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||
// when(response.isAccepted()).thenReturn(false);
|
||||
// when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||
//
|
||||
// DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||
// result.setSuccess(response);
|
||||
//
|
||||
// when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||
// .thenReturn(result);
|
||||
//
|
||||
// RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
// ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||
// APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
// apnSender.setApnFallbackManager(fallbackManager);
|
||||
//
|
||||
// when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
||||
// when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
|
||||
//
|
||||
// ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||
// ApnResult apnResult = sendFuture.get();
|
||||
//
|
||||
// Thread.sleep(1000); // =(
|
||||
//
|
||||
// ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||
// verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||
//
|
||||
// assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
// assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||
// assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||
// assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
//
|
||||
// assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||
//
|
||||
// verifyNoMoreInteractions(apnsClient);
|
||||
// verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||
// verify(destinationAccount, times(1)).getDevice(1);
|
||||
// verify(destinationDevice, times(1)).getApnId();
|
||||
// verify(destinationDevice, times(1)).getPushTimestamp();
|
||||
@Test
|
||||
public void testUnregisteredUser() throws Exception {
|
||||
ApnsClient apnsClient = mock(ApnsClient.class);
|
||||
|
||||
PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||
when(response.isAccepted()).thenReturn(false);
|
||||
when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||
|
||||
DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||
result.setSuccess(response);
|
||||
|
||||
when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||
.thenReturn(result);
|
||||
|
||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, true);
|
||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
apnSender.setApnFallbackManager(fallbackManager);
|
||||
|
||||
when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
||||
when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
|
||||
|
||||
ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||
ApnResult apnResult = sendFuture.get();
|
||||
|
||||
Thread.sleep(1000); // =(
|
||||
|
||||
ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(ApnMessage.MAX_EXPIRATION));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(ApnMessage.APN_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
|
||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||
|
||||
verifyNoMoreInteractions(apnsClient);
|
||||
verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||
verify(destinationAccount, times(1)).getDevice(1);
|
||||
verify(destinationDevice, times(1)).getApnId();
|
||||
verify(destinationDevice, times(1)).getPushTimestamp();
|
||||
// verify(destinationDevice, times(1)).setApnId(eq((String)null));
|
||||
// verify(destinationDevice, times(1)).setVoipApnId(eq((String)null));
|
||||
// verify(destinationDevice, times(1)).setFetchesMessages(eq(false));
|
||||
// verify(accountsManager, times(1)).update(eq(destinationAccount));
|
||||
// verify(fallbackManager, times(1)).cancel(eq(new WebsocketAddress(DESTINATION_NUMBER, 1)));
|
||||
//
|
||||
// verifyNoMoreInteractions(accountsManager);
|
||||
// verifyNoMoreInteractions(fallbackManager);
|
||||
// }
|
||||
verify(fallbackManager, times(1)).cancel(eq(destinationAccount), eq(destinationDevice));
|
||||
|
||||
verifyNoMoreInteractions(accountsManager);
|
||||
verifyNoMoreInteractions(fallbackManager);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testVoipUnregisteredUser() throws Exception {
|
||||
@@ -230,54 +229,54 @@ public class APNSenderTest {
|
||||
// verifyNoMoreInteractions(fallbackManager);
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void testRecentUnregisteredUser() throws Exception {
|
||||
// ApnsClient apnsClient = mock(ApnsClient.class);
|
||||
//
|
||||
// PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||
// when(response.isAccepted()).thenReturn(false);
|
||||
// when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||
//
|
||||
// DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||
// result.setSuccess(response);
|
||||
//
|
||||
// when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||
// .thenReturn(result);
|
||||
//
|
||||
// RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
// ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||
// APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
// apnSender.setApnFallbackManager(fallbackManager);
|
||||
//
|
||||
// when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
||||
// when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis());
|
||||
//
|
||||
// ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||
// ApnResult apnResult = sendFuture.get();
|
||||
//
|
||||
// Thread.sleep(1000); // =(
|
||||
//
|
||||
// ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||
// verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||
//
|
||||
// assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
// assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||
// assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||
// assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
//
|
||||
// assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||
//
|
||||
// verifyNoMoreInteractions(apnsClient);
|
||||
// verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||
// verify(destinationAccount, times(1)).getDevice(1);
|
||||
// verify(destinationDevice, times(1)).getApnId();
|
||||
// verify(destinationDevice, times(1)).getPushTimestamp();
|
||||
//
|
||||
// verifyNoMoreInteractions(destinationDevice);
|
||||
// verifyNoMoreInteractions(destinationAccount);
|
||||
// verifyNoMoreInteractions(accountsManager);
|
||||
// verifyNoMoreInteractions(fallbackManager);
|
||||
// }
|
||||
@Test
|
||||
public void testRecentUnregisteredUser() throws Exception {
|
||||
ApnsClient apnsClient = mock(ApnsClient.class);
|
||||
|
||||
PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||
when(response.isAccepted()).thenReturn(false);
|
||||
when(response.getRejectionReason()).thenReturn("Unregistered");
|
||||
|
||||
DefaultPromise<PushNotificationResponse<SimpleApnsPushNotification>> result = new DefaultPromise<>(executor);
|
||||
result.setSuccess(response);
|
||||
|
||||
when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||
.thenReturn(result);
|
||||
|
||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, true);
|
||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
apnSender.setApnFallbackManager(fallbackManager);
|
||||
|
||||
when(destinationDevice.getApnId()).thenReturn(DESTINATION_APN_ID);
|
||||
when(destinationDevice.getPushTimestamp()).thenReturn(System.currentTimeMillis());
|
||||
|
||||
ListenableFuture<ApnResult> sendFuture = apnSender.sendMessage(message);
|
||||
ApnResult apnResult = sendFuture.get();
|
||||
|
||||
Thread.sleep(1000); // =(
|
||||
|
||||
ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(ApnMessage.MAX_EXPIRATION));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(ApnMessage.APN_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
|
||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.NO_SUCH_USER);
|
||||
|
||||
verifyNoMoreInteractions(apnsClient);
|
||||
verify(accountsManager, times(1)).get(eq(DESTINATION_NUMBER));
|
||||
verify(destinationAccount, times(1)).getDevice(1);
|
||||
verify(destinationDevice, times(1)).getApnId();
|
||||
verify(destinationDevice, times(1)).getPushTimestamp();
|
||||
|
||||
verifyNoMoreInteractions(destinationDevice);
|
||||
verifyNoMoreInteractions(destinationAccount);
|
||||
verifyNoMoreInteractions(accountsManager);
|
||||
verifyNoMoreInteractions(fallbackManager);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testUnregisteredUserOldApnId() throws Exception {
|
||||
@@ -343,7 +342,7 @@ public class APNSenderTest {
|
||||
.thenReturn(result);
|
||||
|
||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, true);
|
||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
apnSender.setApnFallbackManager(fallbackManager);
|
||||
|
||||
@@ -354,8 +353,8 @@ public class APNSenderTest {
|
||||
verify(apnsClient, times(1)).sendNotification(notification.capture());
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(ApnMessage.MAX_EXPIRATION));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(ApnMessage.APN_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
|
||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.GENERIC_FAILURE);
|
||||
@@ -384,7 +383,7 @@ public class APNSenderTest {
|
||||
.thenReturn(connectedResult);
|
||||
|
||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 10);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, true);
|
||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
apnSender.setApnFallbackManager(fallbackManager);
|
||||
|
||||
@@ -409,8 +408,8 @@ public class APNSenderTest {
|
||||
verify(apnsClient, times(1)).getReconnectionFuture();
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(ApnMessage.MAX_EXPIRATION));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(ApnMessage.APN_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
|
||||
assertThat(apnResult.getStatus()).isEqualTo(ApnResult.Status.SUCCESS);
|
||||
@@ -434,7 +433,7 @@ public class APNSenderTest {
|
||||
.thenReturn(result);
|
||||
|
||||
RetryingApnsClient retryingApnsClient = new RetryingApnsClient(apnsClient, 3);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, "message", true, 30);
|
||||
ApnMessage message = new ApnMessage(DESTINATION_APN_ID, DESTINATION_NUMBER, 1, true);
|
||||
APNSender apnSender = new APNSender(new SynchronousExecutorService(), accountsManager, retryingApnsClient, "foo", false);
|
||||
apnSender.setApnFallbackManager(fallbackManager);
|
||||
|
||||
@@ -451,8 +450,8 @@ public class APNSenderTest {
|
||||
verify(apnsClient, times(4)).sendNotification(notification.capture());
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_APN_ID);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(30));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo("message");
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(new Date(ApnMessage.MAX_EXPIRATION));
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(ApnMessage.APN_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
|
||||
verifyNoMoreInteractions(apnsClient);
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
package org.whispersystems.textsecuregcm.tests.push;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.whispersystems.textsecuregcm.push.APNSender;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager.ApnFallbackTask;
|
||||
import org.whispersystems.textsecuregcm.push.ApnMessage;
|
||||
import org.whispersystems.textsecuregcm.storage.PubSubManager;
|
||||
import org.whispersystems.textsecuregcm.storage.PubSubProtos;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
import org.whispersystems.textsecuregcm.websocket.WebSocketConnectionInfo;
|
||||
import org.whispersystems.textsecuregcm.websocket.WebsocketAddress;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class ApnFallbackManagerTest {
|
||||
|
||||
@Test
|
||||
public void testFullFallback() throws Exception {
|
||||
APNSender apnSender = mock(APNSender.class );
|
||||
PubSubManager pubSubManager = mock(PubSubManager.class);
|
||||
WebsocketAddress address = new WebsocketAddress("+14152222223", 1L);
|
||||
WebSocketConnectionInfo info = new WebSocketConnectionInfo(address);
|
||||
ApnMessage message = new ApnMessage("bar", "123", 1, "hmm", true, 1111);
|
||||
ApnFallbackTask task = new ApnFallbackTask("foo", "voipfoo", message, 500, 0);
|
||||
|
||||
ApnFallbackManager apnFallbackManager = new ApnFallbackManager(apnSender, pubSubManager);
|
||||
apnFallbackManager.start();
|
||||
|
||||
apnFallbackManager.schedule(address, task);
|
||||
|
||||
Util.sleep(1100);
|
||||
|
||||
ArgumentCaptor<ApnMessage> captor = ArgumentCaptor.forClass(ApnMessage.class);
|
||||
verify(apnSender, times(2)).sendMessage(captor.capture());
|
||||
verify(pubSubManager).unsubscribe(eq(info), eq(apnFallbackManager));
|
||||
|
||||
List<ApnMessage> arguments = captor.getAllValues();
|
||||
|
||||
assertEquals(arguments.get(0).getMessage(), message.getMessage());
|
||||
assertEquals(arguments.get(0).getApnId(), task.getVoipApnId());
|
||||
// assertEquals(arguments.get(0).getExpirationTime(), Integer.MAX_VALUE * 1000L);
|
||||
|
||||
assertEquals(arguments.get(1).getMessage(), message.getMessage());
|
||||
assertEquals(arguments.get(1).getApnId(), task.getApnId());
|
||||
assertEquals(arguments.get(1).getExpirationTime(), Integer.MAX_VALUE * 1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFallback() throws Exception {
|
||||
APNSender pushServiceClient = mock(APNSender.class);
|
||||
PubSubManager pubSubManager = mock(PubSubManager.class);
|
||||
WebsocketAddress address = new WebsocketAddress("+14152222222", 1);
|
||||
WebSocketConnectionInfo info = new WebSocketConnectionInfo(address);
|
||||
ApnMessage message = new ApnMessage("bar", "123", 1, "hmm", true, 5555);
|
||||
ApnFallbackTask task = new ApnFallbackTask ("foo", "voipfoo", message, 500, 0);
|
||||
|
||||
ApnFallbackManager apnFallbackManager = new ApnFallbackManager(pushServiceClient, pubSubManager);
|
||||
apnFallbackManager.start();
|
||||
|
||||
apnFallbackManager.schedule(address, task);
|
||||
apnFallbackManager.onDispatchMessage(info.serialize(),
|
||||
PubSubProtos.PubSubMessage.newBuilder()
|
||||
.setType(PubSubProtos.PubSubMessage.Type.CONNECTED)
|
||||
.build().toByteArray());
|
||||
|
||||
verify(pubSubManager).unsubscribe(eq(info), eq(apnFallbackManager));
|
||||
|
||||
Util.sleep(1100);
|
||||
|
||||
verifyNoMoreInteractions(pushServiceClient);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package org.whispersystems.textsecuregcm.tests.push;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager.ApnFallbackTask;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager.ApnFallbackTaskQueue;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
import org.whispersystems.textsecuregcm.websocket.WebsocketAddress;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ApnFallbackTaskQueueTest {
|
||||
|
||||
@Test
|
||||
public void testBlocking() {
|
||||
final ApnFallbackTaskQueue taskQueue = new ApnFallbackTaskQueue();
|
||||
|
||||
final WebsocketAddress address = mock(WebsocketAddress.class);
|
||||
final ApnFallbackTask task = mock(ApnFallbackTask.class );
|
||||
|
||||
when(task.getExecutionTime()).thenReturn(System.currentTimeMillis() - 1000);
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Util.sleep(500);
|
||||
taskQueue.put(address, task);
|
||||
}
|
||||
}.start();
|
||||
|
||||
Map.Entry<WebsocketAddress, ApnFallbackTask> result = taskQueue.get();
|
||||
|
||||
assertEquals(result.getKey(), address);
|
||||
assertEquals(result.getValue(), task);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testElapsedTime() {
|
||||
final ApnFallbackTaskQueue taskQueue = new ApnFallbackTaskQueue();
|
||||
final WebsocketAddress address = mock(WebsocketAddress.class);
|
||||
final ApnFallbackTask task = mock(ApnFallbackTask.class );
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
when(task.getExecutionTime()).thenReturn(currentTime + 1000);
|
||||
|
||||
taskQueue.put(address, task);
|
||||
Map.Entry<WebsocketAddress, ApnFallbackTask> result = taskQueue.get();
|
||||
|
||||
assertTrue(System.currentTimeMillis() >= currentTime + 1000);
|
||||
assertEquals(result.getKey(), address);
|
||||
assertEquals(result.getValue(), task);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanceled() {
|
||||
final ApnFallbackTaskQueue taskQueue = new ApnFallbackTaskQueue();
|
||||
final WebsocketAddress addressOne = mock(WebsocketAddress.class);
|
||||
final ApnFallbackTask taskOne = mock(ApnFallbackTask.class );
|
||||
final WebsocketAddress addressTwo = mock(WebsocketAddress.class);
|
||||
final ApnFallbackTask taskTwo = mock(ApnFallbackTask.class );
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
when(taskOne.getExecutionTime()).thenReturn(currentTime + 1000);
|
||||
when(taskTwo.getExecutionTime()).thenReturn(currentTime + 2000);
|
||||
|
||||
taskQueue.put(addressOne, taskOne);
|
||||
taskQueue.put(addressTwo, taskTwo);
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Util.sleep(300);
|
||||
taskQueue.remove(addressOne);
|
||||
}
|
||||
}.start();
|
||||
|
||||
Map.Entry<WebsocketAddress, ApnFallbackTask> result = taskQueue.get();
|
||||
|
||||
assertTrue(System.currentTimeMillis() >= currentTime + 2000);
|
||||
assertEquals(result.getKey(), addressTwo);
|
||||
assertEquals(result.getValue(), taskTwo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import org.mockito.stubbing.Answer;
|
||||
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
|
||||
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntity;
|
||||
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntityList;
|
||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
import org.whispersystems.textsecuregcm.push.WebsocketSender;
|
||||
@@ -58,12 +59,13 @@ public class WebSocketConnectionTest {
|
||||
private static final UpgradeRequest upgradeRequest = mock(UpgradeRequest.class );
|
||||
private static final PushSender pushSender = mock(PushSender.class);
|
||||
private static final ReceiptSender receiptSender = mock(ReceiptSender.class);
|
||||
private static final ApnFallbackManager apnFallbackManager = mock(ApnFallbackManager.class);
|
||||
|
||||
@Test
|
||||
public void testCredentials() throws Exception {
|
||||
MessagesManager storedMessages = mock(MessagesManager.class);
|
||||
WebSocketAccountAuthenticator webSocketAuthenticator = new WebSocketAccountAuthenticator(accountAuthenticator);
|
||||
AuthenticatedConnectListener connectListener = new AuthenticatedConnectListener(accountsManager, pushSender, receiptSender, storedMessages, pubSubManager);
|
||||
AuthenticatedConnectListener connectListener = new AuthenticatedConnectListener(pushSender, receiptSender, storedMessages, pubSubManager, apnFallbackManager);
|
||||
WebSocketSessionContext sessionContext = mock(WebSocketSessionContext.class);
|
||||
|
||||
when(accountAuthenticator.authenticate(eq(new BasicCredentials(VALID_USER, VALID_PASSWORD))))
|
||||
@@ -250,7 +252,7 @@ public class WebSocketConnectionTest {
|
||||
|
||||
verify(receiptSender, times(1)).sendReceipt(eq(account), eq("sender2"), eq(secondMessage.getTimestamp()), eq(Optional.<String>absent()));
|
||||
verify(websocketSender, times(1)).queueMessage(eq(account), eq(device), any(Envelope.class));
|
||||
verify(pushSender, times(1)).sendQueuedNotification(eq(account), eq(device), eq(true));
|
||||
verify(pushSender, times(1)).sendQueuedNotification(eq(account), eq(device));
|
||||
|
||||
connection.onDispatchUnsubscribed(websocketAddress.serialize());
|
||||
verify(client).close(anyInt(), anyString());
|
||||
|
||||
Reference in New Issue
Block a user