mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 02:18:08 +01:00
Remove machinery for setting/storing APNs VOIP tokens
This commit is contained in:
committed by
Jon Chambers
parent
b693cb98d0
commit
92698efd39
@@ -308,29 +308,11 @@ class AccountControllerTest {
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION,
|
||||
AuthHelper.getAuthHeader(AuthHelper.VALID_UUID_3, AuthHelper.VALID_PASSWORD_3_PRIMARY))
|
||||
.put(Entity.json(new ApnRegistrationId("first", "second")))) {
|
||||
.put(Entity.json(new ApnRegistrationId("first")))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
|
||||
verify(AuthHelper.VALID_DEVICE_3_PRIMARY, times(1)).setApnId(eq("first"));
|
||||
verify(AuthHelper.VALID_DEVICE_3_PRIMARY, times(1)).setVoipApnId(eq("second"));
|
||||
verify(accountsManager, times(1)).updateDevice(eq(AuthHelper.VALID_ACCOUNT_3), anyByte(), any());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetApnIdNoVoip() {
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/accounts/apn/")
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION,
|
||||
AuthHelper.getAuthHeader(AuthHelper.VALID_UUID_3, AuthHelper.VALID_PASSWORD_3_PRIMARY))
|
||||
.put(Entity.json(new ApnRegistrationId("first", null)))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
|
||||
verify(AuthHelper.VALID_DEVICE_3_PRIMARY, times(1)).setApnId(eq("first"));
|
||||
verify(AuthHelper.VALID_DEVICE_3_PRIMARY, times(1)).setVoipApnId(null);
|
||||
verify(accountsManager, times(1)).updateDevice(eq(AuthHelper.VALID_ACCOUNT_3), anyByte(), any());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,6 @@ class DeviceControllerTest {
|
||||
final Optional<ApnRegistrationId> apnRegistrationId,
|
||||
final Optional<GcmRegistrationId> gcmRegistrationId,
|
||||
final Optional<String> expectedApnsToken,
|
||||
final Optional<String> expectedApnsVoipToken,
|
||||
final Optional<String> expectedGcmToken) {
|
||||
|
||||
final Device existingDevice = mock(Device.class);
|
||||
@@ -240,9 +239,6 @@ class DeviceControllerTest {
|
||||
expectedApnsToken.ifPresentOrElse(expectedToken -> assertEquals(expectedToken, device.getApnId()),
|
||||
() -> assertNull(device.getApnId()));
|
||||
|
||||
expectedApnsVoipToken.ifPresentOrElse(expectedToken -> assertEquals(expectedToken, device.getVoipApnId()),
|
||||
() -> assertNull(device.getVoipApnId()));
|
||||
|
||||
expectedGcmToken.ifPresentOrElse(expectedToken -> assertEquals(expectedToken, device.getGcmId()),
|
||||
() -> assertNull(device.getGcmId()));
|
||||
|
||||
@@ -251,14 +247,13 @@ class DeviceControllerTest {
|
||||
|
||||
private static Stream<Arguments> linkDeviceAtomic() {
|
||||
final String apnsToken = "apns-token";
|
||||
final String apnsVoipToken = "apns-voip-token";
|
||||
final String gcmToken = "gcm-token";
|
||||
|
||||
return Stream.of(
|
||||
Arguments.of(true, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()),
|
||||
Arguments.of(false, Optional.of(new ApnRegistrationId(apnsToken, null)), Optional.empty(), Optional.of(apnsToken), Optional.empty(), Optional.empty()),
|
||||
Arguments.of(false, Optional.of(new ApnRegistrationId(apnsToken, apnsVoipToken)), Optional.empty(), Optional.of(apnsToken), Optional.of(apnsVoipToken), Optional.empty()),
|
||||
Arguments.of(false, Optional.empty(), Optional.of(new GcmRegistrationId(gcmToken)), Optional.empty(), Optional.empty(), Optional.of(gcmToken))
|
||||
Arguments.of(true, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()),
|
||||
Arguments.of(false, Optional.of(new ApnRegistrationId(apnsToken)), Optional.empty(), Optional.of(apnsToken), Optional.empty()),
|
||||
Arguments.of(false, Optional.of(new ApnRegistrationId(apnsToken)), Optional.empty(), Optional.of(apnsToken), Optional.empty()),
|
||||
Arguments.of(false, Optional.empty(), Optional.of(new GcmRegistrationId(gcmToken)), Optional.empty(), Optional.of(gcmToken))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -496,10 +491,10 @@ class DeviceControllerTest {
|
||||
|
||||
private static Stream<Arguments> linkDeviceAtomicConflictingChannel() {
|
||||
return Stream.of(
|
||||
Arguments.of(true, Optional.of(new ApnRegistrationId("apns-token", null)), Optional.of(new GcmRegistrationId("gcm-token"))),
|
||||
Arguments.of(true, Optional.of(new ApnRegistrationId("apns-token")), Optional.of(new GcmRegistrationId("gcm-token"))),
|
||||
Arguments.of(true, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-token"))),
|
||||
Arguments.of(true, Optional.of(new ApnRegistrationId("apns-token", null)), Optional.empty()),
|
||||
Arguments.of(false, Optional.of(new ApnRegistrationId("apns-token", null)), Optional.of(new GcmRegistrationId("gcm-token")))
|
||||
Arguments.of(true, Optional.of(new ApnRegistrationId("apns-token")), Optional.empty()),
|
||||
Arguments.of(false, Optional.of(new ApnRegistrationId("apns-token")), Optional.of(new GcmRegistrationId("gcm-token")))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -737,7 +732,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.verificationCode(),
|
||||
new AccountAttributes(false, registrationId, pniRegistrationId, null, null, true, new DeviceCapabilities(true, true, true, false, false)),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.of(new ApnRegistrationId("apn", null)), Optional.empty()));
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.of(new ApnRegistrationId("apn")), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
|
||||
@@ -543,7 +543,7 @@ class RegistrationControllerTest {
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(new ApnRegistrationId("apns-token", null)),
|
||||
Optional.of(new ApnRegistrationId("apns-token")),
|
||||
Optional.empty())),
|
||||
|
||||
// "Fetches messages" is true, but an FCM (GCM) token is provided
|
||||
@@ -571,7 +571,7 @@ class RegistrationControllerTest {
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(new ApnRegistrationId("apns-token", null)),
|
||||
Optional.of(new ApnRegistrationId("apns-token")),
|
||||
Optional.of(new GcmRegistrationId("gcm-token"))))
|
||||
);
|
||||
}
|
||||
@@ -795,7 +795,6 @@ class RegistrationControllerTest {
|
||||
new AccountAttributes(false, registrationId, pniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false, false));
|
||||
|
||||
final String apnsToken = "apns-token";
|
||||
final String apnsVoipToken = "apns-voip-token";
|
||||
final String gcmToken = "gcm-token";
|
||||
|
||||
return Stream.of(
|
||||
@@ -840,7 +839,7 @@ class RegistrationControllerTest {
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(new ApnRegistrationId(apnsToken, apnsVoipToken)),
|
||||
Optional.of(new ApnRegistrationId(apnsToken)),
|
||||
Optional.empty()),
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
@@ -852,7 +851,7 @@ class RegistrationControllerTest {
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
false,
|
||||
Optional.of(new ApnRegistrationId(apnsToken, apnsVoipToken)),
|
||||
Optional.of(new ApnRegistrationId(apnsToken)),
|
||||
Optional.empty(),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
|
||||
@@ -56,15 +56,6 @@ abstract class IdleDevicePushNotificationExperimentTest {
|
||||
arguments.add(Arguments.of(device, true));
|
||||
}
|
||||
|
||||
{
|
||||
// APNs VOIP token
|
||||
final Device device = mock(Device.class);
|
||||
when(device.getApnId()).thenReturn("apns-token");
|
||||
when(device.getVoipApnId()).thenReturn("apns-voip-token");
|
||||
|
||||
arguments.add(Arguments.of(device, false));
|
||||
}
|
||||
|
||||
return arguments;
|
||||
}
|
||||
|
||||
|
||||
@@ -217,7 +217,6 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
void setPushToken(final byte deviceId,
|
||||
final SetPushTokenRequest request,
|
||||
@Nullable final String expectedApnsToken,
|
||||
@Nullable final String expectedApnsVoipToken,
|
||||
@Nullable final String expectedFcmToken) {
|
||||
|
||||
mockAuthenticationInterceptor().setAuthenticatedDevice(AUTHENTICATED_ACI, deviceId);
|
||||
@@ -228,14 +227,12 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
final SetPushTokenResponse ignored = authenticatedServiceStub().setPushToken(request);
|
||||
|
||||
verify(device).setApnId(expectedApnsToken);
|
||||
verify(device).setVoipApnId(expectedApnsVoipToken);
|
||||
verify(device).setGcmId(expectedFcmToken);
|
||||
verify(device).setFetchesMessages(false);
|
||||
}
|
||||
|
||||
private static Stream<Arguments> setPushToken() {
|
||||
final String apnsToken = "apns-token";
|
||||
final String apnsVoipToken = "apns-voip-token";
|
||||
final String fcmToken = "fcm-token";
|
||||
|
||||
final Stream.Builder<Arguments> streamBuilder = Stream.builder();
|
||||
@@ -245,18 +242,9 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
SetPushTokenRequest.newBuilder()
|
||||
.setApnsTokenRequest(SetPushTokenRequest.ApnsTokenRequest.newBuilder()
|
||||
.setApnsToken(apnsToken)
|
||||
.setApnsVoipToken(apnsVoipToken)
|
||||
.build())
|
||||
.build(),
|
||||
apnsToken, apnsVoipToken, null));
|
||||
|
||||
streamBuilder.add(Arguments.of(deviceId,
|
||||
SetPushTokenRequest.newBuilder()
|
||||
.setApnsTokenRequest(SetPushTokenRequest.ApnsTokenRequest.newBuilder()
|
||||
.setApnsToken(apnsToken)
|
||||
.build())
|
||||
.build(),
|
||||
apnsToken, null, null));
|
||||
apnsToken, null));
|
||||
|
||||
streamBuilder.add(Arguments.of(deviceId,
|
||||
SetPushTokenRequest.newBuilder()
|
||||
@@ -264,7 +252,7 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
.setFcmToken(fcmToken)
|
||||
.build())
|
||||
.build(),
|
||||
null, null, fcmToken));
|
||||
null, fcmToken));
|
||||
}
|
||||
|
||||
return streamBuilder.build();
|
||||
@@ -274,12 +262,10 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
@MethodSource
|
||||
void setPushTokenUnchanged(final SetPushTokenRequest request,
|
||||
@Nullable final String apnsToken,
|
||||
@Nullable final String apnsVoipToken,
|
||||
@Nullable final String fcmToken) {
|
||||
|
||||
final Device device = mock(Device.class);
|
||||
when(device.getApnId()).thenReturn(apnsToken);
|
||||
when(device.getVoipApnId()).thenReturn(apnsVoipToken);
|
||||
when(device.getGcmId()).thenReturn(fcmToken);
|
||||
|
||||
when(authenticatedAccount.getDevice(AUTHENTICATED_DEVICE_ID)).thenReturn(Optional.of(device));
|
||||
@@ -291,31 +277,22 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
|
||||
private static Stream<Arguments> setPushTokenUnchanged() {
|
||||
final String apnsToken = "apns-token";
|
||||
final String apnsVoipToken = "apns-voip-token";
|
||||
final String fcmToken = "fcm-token";
|
||||
|
||||
return Stream.of(
|
||||
Arguments.of(SetPushTokenRequest.newBuilder()
|
||||
.setApnsTokenRequest(SetPushTokenRequest.ApnsTokenRequest.newBuilder()
|
||||
.setApnsToken(apnsToken)
|
||||
.setApnsVoipToken(apnsVoipToken)
|
||||
.build())
|
||||
.build(),
|
||||
apnsToken, apnsVoipToken, null, false),
|
||||
|
||||
Arguments.of(SetPushTokenRequest.newBuilder()
|
||||
.setApnsTokenRequest(SetPushTokenRequest.ApnsTokenRequest.newBuilder()
|
||||
.setApnsToken(apnsToken)
|
||||
.build())
|
||||
.build(),
|
||||
apnsToken, null, null, false),
|
||||
apnsToken, null, false),
|
||||
|
||||
Arguments.of(SetPushTokenRequest.newBuilder()
|
||||
.setFcmTokenRequest(SetPushTokenRequest.FcmTokenRequest.newBuilder()
|
||||
.setFcmToken(fcmToken)
|
||||
.build())
|
||||
.build(),
|
||||
null, null, fcmToken, false)
|
||||
null, fcmToken, false)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -346,7 +323,6 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
@MethodSource
|
||||
void clearPushToken(final byte deviceId,
|
||||
@Nullable final String apnsToken,
|
||||
@Nullable final String apnsVoipToken,
|
||||
@Nullable final String fcmToken,
|
||||
@Nullable final String expectedUserAgent) {
|
||||
|
||||
@@ -356,14 +332,12 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
when(device.getId()).thenReturn(deviceId);
|
||||
when(device.isPrimary()).thenReturn(deviceId == Device.PRIMARY_ID);
|
||||
when(device.getApnId()).thenReturn(apnsToken);
|
||||
when(device.getVoipApnId()).thenReturn(apnsVoipToken);
|
||||
when(device.getGcmId()).thenReturn(fcmToken);
|
||||
when(authenticatedAccount.getDevice(deviceId)).thenReturn(Optional.of(device));
|
||||
|
||||
final ClearPushTokenResponse ignored = authenticatedServiceStub().clearPushToken(ClearPushTokenRequest.newBuilder().build());
|
||||
|
||||
verify(device).setApnId(null);
|
||||
verify(device).setVoipApnId(null);
|
||||
verify(device).setGcmId(null);
|
||||
verify(device).setFetchesMessages(true);
|
||||
|
||||
@@ -376,16 +350,12 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||
|
||||
private static Stream<Arguments> clearPushToken() {
|
||||
return Stream.of(
|
||||
Arguments.of(Device.PRIMARY_ID, "apns-token", null, null, "OWI"),
|
||||
Arguments.of(Device.PRIMARY_ID, "apns-token", "apns-voip-token", null, "OWI"),
|
||||
Arguments.of(Device.PRIMARY_ID, null, "apns-voip-token", null, "OWI"),
|
||||
Arguments.of(Device.PRIMARY_ID, null, null, "fcm-token", "OWA"),
|
||||
Arguments.of(Device.PRIMARY_ID, null, null, null, null),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), "apns-token", null, null, "OWP"),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), "apns-token", "apns-voip-token", null, "OWP"),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), null, "apns-voip-token", null, "OWP"),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), null, null, "fcm-token", "OWA"),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), null, null, null, null)
|
||||
Arguments.of(Device.PRIMARY_ID, "apns-token", null, "OWI"),
|
||||
Arguments.of(Device.PRIMARY_ID, null, "fcm-token", "OWA"),
|
||||
Arguments.of(Device.PRIMARY_ID, null, null, null),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), "apns-token", null, "OWP"),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), null, "fcm-token", "OWA"),
|
||||
Arguments.of((byte) (Device.PRIMARY_ID + 1), null, null, null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,38 +58,6 @@ class APNSenderTest {
|
||||
when(destinationDevice.getApnId()).thenReturn(DESTINATION_DEVICE_TOKEN);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void testSendVoip(final boolean urgent) {
|
||||
PushNotificationResponse<SimpleApnsPushNotification> response = mock(PushNotificationResponse.class);
|
||||
when(response.isAccepted()).thenReturn(true);
|
||||
|
||||
when(apnsClient.sendNotification(any(SimpleApnsPushNotification.class)))
|
||||
.thenAnswer(
|
||||
(Answer) invocationOnMock -> new MockPushNotificationFuture<>(invocationOnMock.getArgument(0), response));
|
||||
|
||||
PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN_VOIP,
|
||||
PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, urgent);
|
||||
|
||||
final SendPushNotificationResult result = apnSender.sendNotification(pushNotification).join();
|
||||
|
||||
ArgumentCaptor<SimpleApnsPushNotification> notification = ArgumentCaptor.forClass(SimpleApnsPushNotification.class);
|
||||
verify(apnsClient).sendNotification(notification.capture());
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_DEVICE_TOKEN);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(APNSender.MAX_EXPIRATION);
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(APNSender.APN_VOIP_NOTIFICATION_PAYLOAD);
|
||||
// Delivery priority should always be `IMMEDIATE` for VOIP notifications
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
assertThat(notification.getValue().getTopic()).isEqualTo(BUNDLE_ID + ".voip");
|
||||
|
||||
assertThat(result.accepted()).isTrue();
|
||||
assertThat(result.errorCode()).isEmpty();
|
||||
assertThat(result.unregistered()).isFalse();
|
||||
|
||||
verifyNoMoreInteractions(apnsClient);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void testSendApns(final boolean urgent) {
|
||||
@@ -144,7 +112,7 @@ class APNSenderTest {
|
||||
.thenAnswer(
|
||||
(Answer) invocationOnMock -> new MockPushNotificationFuture<>(invocationOnMock.getArgument(0), response));
|
||||
|
||||
PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN_VOIP,
|
||||
PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN,
|
||||
PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true);
|
||||
|
||||
when(destinationDevice.getApnId()).thenReturn(DESTINATION_DEVICE_TOKEN);
|
||||
@@ -157,7 +125,7 @@ class APNSenderTest {
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_DEVICE_TOKEN);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(APNSender.MAX_EXPIRATION);
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(APNSender.APN_VOIP_NOTIFICATION_PAYLOAD);
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(APNSender.APN_NSE_NOTIFICATION_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
|
||||
assertThat(result.accepted()).isFalse();
|
||||
@@ -175,7 +143,7 @@ class APNSenderTest {
|
||||
.thenAnswer(
|
||||
(Answer) invocationOnMock -> new MockPushNotificationFuture<>(invocationOnMock.getArgument(0), response));
|
||||
|
||||
PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN_VOIP,
|
||||
PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN,
|
||||
PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true);
|
||||
|
||||
final SendPushNotificationResult result = apnSender.sendNotification(pushNotification).join();
|
||||
@@ -185,7 +153,7 @@ class APNSenderTest {
|
||||
|
||||
assertThat(notification.getValue().getToken()).isEqualTo(DESTINATION_DEVICE_TOKEN);
|
||||
assertThat(notification.getValue().getExpiration()).isEqualTo(APNSender.MAX_EXPIRATION);
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(APNSender.APN_VOIP_NOTIFICATION_PAYLOAD);
|
||||
assertThat(notification.getValue().getPayload()).isEqualTo(APNSender.APN_NSE_NOTIFICATION_PAYLOAD);
|
||||
assertThat(notification.getValue().getPriority()).isEqualTo(DeliveryPriority.IMMEDIATE);
|
||||
|
||||
assertThat(result.accepted()).isFalse();
|
||||
@@ -202,7 +170,7 @@ class APNSenderTest {
|
||||
.thenAnswer((Answer) invocationOnMock -> new MockPushNotificationFuture<>(invocationOnMock.getArgument(0),
|
||||
new IOException("lost connection")));
|
||||
|
||||
PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN_VOIP,
|
||||
PushNotification pushNotification = new PushNotification(DESTINATION_DEVICE_TOKEN, PushNotification.TokenType.APN,
|
||||
PushNotification.NotificationType.NOTIFICATION, null, destinationAccount, destinationDevice, true);
|
||||
|
||||
assertThatThrownBy(() -> apnSender.sendNotification(pushNotification).join())
|
||||
|
||||
@@ -77,8 +77,8 @@ class PushNotificationManagerTest {
|
||||
when(apnSender.sendNotification(any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty())));
|
||||
|
||||
pushNotificationManager.sendRegistrationChallengeNotification(deviceToken, PushNotification.TokenType.APN_VOIP, challengeToken);
|
||||
verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN_VOIP, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true));
|
||||
pushNotificationManager.sendRegistrationChallengeNotification(deviceToken, PushNotification.TokenType.APN, challengeToken);
|
||||
verify(apnSender).sendNotification(new PushNotification(deviceToken, PushNotification.TokenType.APN, PushNotification.NotificationType.CHALLENGE, challengeToken, null, null, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -220,13 +220,12 @@ class PushNotificationManagerTest {
|
||||
final UUID aci = UUID.randomUUID();
|
||||
when(device.getId()).thenReturn(Device.PRIMARY_ID);
|
||||
when(device.getApnId()).thenReturn("apns-token");
|
||||
when(device.getVoipApnId()).thenReturn("apns-voip-token");
|
||||
when(account.getDevice(Device.PRIMARY_ID)).thenReturn(Optional.of(device));
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
when(accountsManager.getByAccountIdentifier(aci)).thenReturn(Optional.of(account));
|
||||
|
||||
final PushNotification pushNotification = new PushNotification(
|
||||
"token", PushNotification.TokenType.APN_VOIP, PushNotification.NotificationType.NOTIFICATION, null, account, device, true);
|
||||
"token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, true);
|
||||
|
||||
when(apnSender.sendNotification(pushNotification))
|
||||
.thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(false, Optional.empty(), true, Optional.empty())));
|
||||
@@ -238,8 +237,7 @@ class PushNotificationManagerTest {
|
||||
|
||||
verifyNoInteractions(fcmSender);
|
||||
verify(accountsManager).updateDevice(eq(account), eq(Device.PRIMARY_ID), any());
|
||||
verify(device).setVoipApnId(null);
|
||||
verify(device, never()).setApnId(any());
|
||||
verify(device).setApnId(null);
|
||||
verify(pushNotificationScheduler).cancelScheduledNotifications(account, device);
|
||||
}
|
||||
|
||||
@@ -252,14 +250,13 @@ class PushNotificationManagerTest {
|
||||
final UUID aci = UUID.randomUUID();
|
||||
when(device.getId()).thenReturn(Device.PRIMARY_ID);
|
||||
when(device.getApnId()).thenReturn("apns-token");
|
||||
when(device.getVoipApnId()).thenReturn("apns-voip-token");
|
||||
when(device.getPushTimestamp()).thenReturn(tokenTimestamp.toEpochMilli());
|
||||
when(account.getDevice(Device.PRIMARY_ID)).thenReturn(Optional.of(device));
|
||||
when(account.getUuid()).thenReturn(aci);
|
||||
when(accountsManager.getByAccountIdentifier(aci)).thenReturn(Optional.of(account));
|
||||
|
||||
final PushNotification pushNotification = new PushNotification(
|
||||
"token", PushNotification.TokenType.APN_VOIP, PushNotification.NotificationType.NOTIFICATION, null, account, device, true);
|
||||
"token", PushNotification.TokenType.APN, PushNotification.NotificationType.NOTIFICATION, null, account, device, true);
|
||||
|
||||
when(apnSender.sendNotification(pushNotification))
|
||||
.thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(false, Optional.empty(), true, Optional.of(tokenTimestamp.minusSeconds(60)))));
|
||||
@@ -271,7 +268,6 @@ class PushNotificationManagerTest {
|
||||
|
||||
verifyNoInteractions(fcmSender);
|
||||
verify(accountsManager, never()).updateDevice(eq(account), eq(Device.PRIMARY_ID), any());
|
||||
verify(device, never()).setVoipApnId(any());
|
||||
verify(device, never()).setApnId(any());
|
||||
verify(pushNotificationScheduler, never()).cancelScheduledNotifications(account, device);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ class PushNotificationSchedulerTest {
|
||||
private static final String ACCOUNT_NUMBER = "+18005551234";
|
||||
private static final byte DEVICE_ID = 1;
|
||||
private static final String APN_ID = RandomStringUtils.randomAlphanumeric(32);
|
||||
private static final String VOIP_APN_ID = RandomStringUtils.randomAlphanumeric(32);
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
@@ -64,7 +63,6 @@ class PushNotificationSchedulerTest {
|
||||
device = mock(Device.class);
|
||||
when(device.getId()).thenReturn(DEVICE_ID);
|
||||
when(device.getApnId()).thenReturn(APN_ID);
|
||||
when(device.getVoipApnId()).thenReturn(VOIP_APN_ID);
|
||||
when(device.getLastSeen()).thenReturn(System.currentTimeMillis());
|
||||
|
||||
account = mock(Account.class);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
private KeysManager keysManager;
|
||||
private ClientPublicKeysManager clientPublicKeysManager;
|
||||
|
||||
record DeliveryChannels(boolean fetchesMessages, String apnsToken, String apnsVoipToken, String fcmToken) {}
|
||||
record DeliveryChannels(boolean fetchesMessages, String apnsToken, String fcmToken) {}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -212,8 +212,8 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final KEMSignedPreKey pniPqLastResortPreKey = KeysHelper.signedKEMPreKey(4, pniKeyPair);
|
||||
|
||||
final Optional<ApnRegistrationId> maybeApnRegistrationId =
|
||||
deliveryChannels.apnsToken() != null || deliveryChannels.apnsVoipToken() != null
|
||||
? Optional.of(new ApnRegistrationId(deliveryChannels.apnsToken(), deliveryChannels.apnsVoipToken()))
|
||||
deliveryChannels.apnsToken() != null
|
||||
? Optional.of(new ApnRegistrationId(deliveryChannels.apnsToken()))
|
||||
: Optional.empty();
|
||||
|
||||
final Optional<GcmRegistrationId> maybeGcmRegistrationId = deliveryChannels.fcmToken() != null
|
||||
@@ -271,10 +271,10 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
return ArgumentSets
|
||||
// deliveryChannels
|
||||
.argumentsForFirstParameter(
|
||||
new DeliveryChannels(true, null, null, null),
|
||||
new DeliveryChannels(false, "apns-token", null, null),
|
||||
new DeliveryChannels(false, "apns-token", "apns-voip-token", null),
|
||||
new DeliveryChannels(false, null, null, "fcm-token"))
|
||||
new DeliveryChannels(true, null, null),
|
||||
new DeliveryChannels(false, "apns-token", null),
|
||||
new DeliveryChannels(false, "apns-token", null),
|
||||
new DeliveryChannels(false, null, "fcm-token"))
|
||||
|
||||
// discoverableByPhoneNumber
|
||||
.argumentsForNextParameter(true, false);
|
||||
@@ -359,8 +359,8 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
final KEMSignedPreKey pniPqLastResortPreKey = KeysHelper.signedKEMPreKey(4, pniKeyPair);
|
||||
|
||||
final Optional<ApnRegistrationId> maybeApnRegistrationId =
|
||||
deliveryChannels.apnsToken() != null || deliveryChannels.apnsVoipToken() != null
|
||||
? Optional.of(new ApnRegistrationId(deliveryChannels.apnsToken(), deliveryChannels.apnsVoipToken()))
|
||||
deliveryChannels.apnsToken() != null
|
||||
? Optional.of(new ApnRegistrationId(deliveryChannels.apnsToken()))
|
||||
: Optional.empty();
|
||||
|
||||
final Optional<GcmRegistrationId> maybeGcmRegistrationId = deliveryChannels.fcmToken() != null
|
||||
@@ -519,19 +519,13 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
assertEquals(deviceCapabilities, primaryDevice.getCapabilities());
|
||||
assertEquals(badges, account.getBadges());
|
||||
|
||||
maybeApnRegistrationId.ifPresentOrElse(apnRegistrationId -> {
|
||||
assertEquals(apnRegistrationId.apnRegistrationId(), primaryDevice.getApnId());
|
||||
assertEquals(apnRegistrationId.voipRegistrationId(), primaryDevice.getVoipApnId());
|
||||
}, () -> {
|
||||
assertNull(primaryDevice.getApnId());
|
||||
assertNull(primaryDevice.getVoipApnId());
|
||||
});
|
||||
maybeApnRegistrationId.ifPresentOrElse(
|
||||
apnRegistrationId -> assertEquals(apnRegistrationId.apnRegistrationId(), primaryDevice.getApnId()),
|
||||
() -> assertNull(primaryDevice.getApnId()));
|
||||
|
||||
maybeGcmRegistrationId.ifPresentOrElse(gcmRegistrationId -> {
|
||||
assertEquals(deliveryChannels.fcmToken(), primaryDevice.getGcmId());
|
||||
}, () -> {
|
||||
assertNull(primaryDevice.getGcmId());
|
||||
});
|
||||
maybeGcmRegistrationId.ifPresentOrElse(
|
||||
gcmRegistrationId -> assertEquals(deliveryChannels.fcmToken(), primaryDevice.getGcmId()),
|
||||
() -> assertNull(primaryDevice.getGcmId()));
|
||||
|
||||
assertTrue(account.getRegistrationLock().verify(registrationLockSecret));
|
||||
assertTrue(primaryDevice.getAuthTokenHash().verify(password));
|
||||
|
||||
@@ -986,7 +986,6 @@ class AccountsManagerTest {
|
||||
assertEquals(pniRegistrationId, device.getPhoneNumberIdentityRegistrationId().getAsInt());
|
||||
assertTrue(device.getFetchesMessages());
|
||||
assertNull(device.getApnId());
|
||||
assertNull(device.getVoipApnId());
|
||||
assertNull(device.getGcmId());
|
||||
}
|
||||
|
||||
|
||||
@@ -364,15 +364,6 @@ class NotifyIdleDevicesCommandTest {
|
||||
arguments.add(Arguments.of(device, true));
|
||||
}
|
||||
|
||||
{
|
||||
// APNs VOIP token
|
||||
final Device device = mock(Device.class);
|
||||
when(device.getApnId()).thenReturn("apns-token");
|
||||
when(device.getVoipApnId()).thenReturn("apns-voip-token");
|
||||
|
||||
arguments.add(Arguments.of(device, false));
|
||||
}
|
||||
|
||||
return arguments;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user