Add `versionedExpirationTimer` capability
This commit is contained in:
parent
fa51793379
commit
4c0a5ac3b2
|
@ -126,7 +126,7 @@ public class TestUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountAttributes accountAttributes() {
|
public AccountAttributes accountAttributes() {
|
||||||
return new AccountAttributes(true, registrationId, pniRegistrationId, "".getBytes(StandardCharsets.UTF_8), "", true, new Device.DeviceCapabilities(false, false, false, false))
|
return new AccountAttributes(true, registrationId, pniRegistrationId, "".getBytes(StandardCharsets.UTF_8), "", true, new Device.DeviceCapabilities(false, false, false, false, false))
|
||||||
.withUnidentifiedAccessKey(unidentifiedAccessKey)
|
.withUnidentifiedAccessKey(unidentifiedAccessKey)
|
||||||
.withRecoveryPassword(registrationPassword);
|
.withRecoveryPassword(registrationPassword);
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,10 @@ public class DeviceController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isCapabilityDowngrade(Account account, DeviceCapabilities capabilities) {
|
private static boolean isCapabilityDowngrade(Account account, DeviceCapabilities capabilities) {
|
||||||
return account.isDeleteSyncSupported() && !capabilities.deleteSync();
|
boolean isDowngrade = false;
|
||||||
|
isDowngrade |= account.isDeleteSyncSupported() && !capabilities.deleteSync();
|
||||||
|
isDowngrade |= account.isVersionedExpirationTimerSupported() && !capabilities.versionedExpirationTimer();
|
||||||
|
return isDowngrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getUsedTokenKey(final String token) {
|
private static String getUsedTokenKey(final String token) {
|
||||||
|
|
|
@ -8,11 +8,13 @@ package org.whispersystems.textsecuregcm.entities;
|
||||||
import org.whispersystems.textsecuregcm.storage.Account;
|
import org.whispersystems.textsecuregcm.storage.Account;
|
||||||
|
|
||||||
public record UserCapabilities(
|
public record UserCapabilities(
|
||||||
// TODO: Remove the paymentActivation capability entirely sometime soon after 2024-06-30
|
// TODO: Remove the paymentActivation capability entirely sometime soon after 2024-10-07
|
||||||
boolean paymentActivation,
|
boolean paymentActivation,
|
||||||
boolean deleteSync) {
|
boolean deleteSync,
|
||||||
|
boolean versionedExpirationTimer) {
|
||||||
|
|
||||||
public static UserCapabilities createForAccount(final Account account) {
|
public static UserCapabilities createForAccount(final Account account) {
|
||||||
return new UserCapabilities(true, account.isDeleteSyncSupported());
|
return new UserCapabilities(true, account.isDeleteSyncSupported(),
|
||||||
|
account.isVersionedExpirationTimerSupported());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,8 @@ public class DevicesGrpcService extends ReactorDevicesGrpc.DevicesImplBase {
|
||||||
request.getStorage(),
|
request.getStorage(),
|
||||||
request.getTransfer(),
|
request.getTransfer(),
|
||||||
request.getPaymentActivation(),
|
request.getPaymentActivation(),
|
||||||
request.getDeleteSync())))))
|
request.getDeleteSync(),
|
||||||
|
request.getVersionedExpirationTimer())))))
|
||||||
.thenReturn(SetCapabilitiesResponse.newBuilder().build());
|
.thenReturn(SetCapabilitiesResponse.newBuilder().build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ public class ProfileGrpcHelper {
|
||||||
return UserCapabilities.newBuilder()
|
return UserCapabilities.newBuilder()
|
||||||
.setPaymentActivation(capabilities.paymentActivation())
|
.setPaymentActivation(capabilities.paymentActivation())
|
||||||
.setDeleteSync(capabilities.deleteSync())
|
.setDeleteSync(capabilities.deleteSync())
|
||||||
|
.setVersionedExpirationTimer(capabilities.versionedExpirationTimer())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,6 +296,10 @@ public class Account {
|
||||||
return allDevicesHaveCapability(DeviceCapabilities::deleteSync);
|
return allDevicesHaveCapability(DeviceCapabilities::deleteSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isVersionedExpirationTimerSupported() {
|
||||||
|
return allDevicesHaveCapability(DeviceCapabilities::versionedExpirationTimer);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean allDevicesHaveCapability(final Predicate<DeviceCapabilities> predicate) {
|
private boolean allDevicesHaveCapability(final Predicate<DeviceCapabilities> predicate) {
|
||||||
requireNotStale();
|
requireNotStale();
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,7 @@ public class Device {
|
||||||
return this.userAgent;
|
return this.userAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public record DeviceCapabilities(boolean storage, boolean transfer, boolean paymentActivation, boolean deleteSync) {
|
public record DeviceCapabilities(boolean storage, boolean transfer, boolean paymentActivation, boolean deleteSync,
|
||||||
|
boolean versionedExpirationTimer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,7 @@ message SetCapabilitiesRequest {
|
||||||
bool transfer = 2;
|
bool transfer = 2;
|
||||||
bool paymentActivation = 3;
|
bool paymentActivation = 3;
|
||||||
bool deleteSync = 4;
|
bool deleteSync = 4;
|
||||||
|
bool versionedExpirationTimer = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetCapabilitiesResponse {}
|
message SetCapabilitiesResponse {}
|
||||||
|
|
|
@ -326,6 +326,10 @@ message UserCapabilities {
|
||||||
* Whether all devices linked to the account support delete syncing
|
* Whether all devices linked to the account support delete syncing
|
||||||
*/
|
*/
|
||||||
bool delete_sync = 2;
|
bool delete_sync = 2;
|
||||||
|
/**
|
||||||
|
* Whether all devices linked to the account support a versioned expiration timer
|
||||||
|
*/
|
||||||
|
bool versioned_expiration_timer = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Badge {
|
message Badge {
|
||||||
|
|
|
@ -216,7 +216,7 @@ class DeviceControllerTest {
|
||||||
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||||
|
|
||||||
final AccountAttributes accountAttributes = new AccountAttributes(fetchesMessages, 1234, 5678, null,
|
final AccountAttributes accountAttributes = new AccountAttributes(fetchesMessages, 1234, 5678, null,
|
||||||
null, true, new DeviceCapabilities(true, true, true, false));
|
null, true, new DeviceCapabilities(true, true, true, false, false));
|
||||||
|
|
||||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.verificationCode(),
|
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.verificationCode(),
|
||||||
accountAttributes,
|
accountAttributes,
|
||||||
|
@ -293,7 +293,7 @@ class DeviceControllerTest {
|
||||||
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||||
|
|
||||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceController.generateVerificationToken(AuthHelper.VALID_UUID),
|
final LinkDeviceRequest request = new LinkDeviceRequest(deviceController.generateVerificationToken(AuthHelper.VALID_UUID),
|
||||||
new AccountAttributes(false, 1234, 5678, null, null, true, new DeviceCapabilities(true, true, true, deviceSupportsDeleteSync)),
|
new AccountAttributes(false, 1234, 5678, null, null, true, new DeviceCapabilities(true, true, true, deviceSupportsDeleteSync, false)),
|
||||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||||
|
|
||||||
try (final Response response = resources.getJerseyTest()
|
try (final Response response = resources.getJerseyTest()
|
||||||
|
@ -314,6 +314,59 @@ class DeviceControllerTest {
|
||||||
Arguments.of(false, false, 200));
|
Arguments.of(false, false, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource
|
||||||
|
void deviceDowngradeVersionedExpirationTimer(final boolean accountSupportsVersionedExpirationTimer,
|
||||||
|
final boolean deviceSupportsVersionedExpirationTimer, final int expectedStatus) {
|
||||||
|
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account));
|
||||||
|
when(accountsManager.addDevice(any(), any()))
|
||||||
|
.thenReturn(CompletableFuture.completedFuture(new Pair<>(mock(Account.class), mock(Device.class))));
|
||||||
|
|
||||||
|
final Device primaryDevice = mock(Device.class);
|
||||||
|
when(primaryDevice.getId()).thenReturn(Device.PRIMARY_ID);
|
||||||
|
when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(primaryDevice));
|
||||||
|
|
||||||
|
final ECSignedPreKey aciSignedPreKey;
|
||||||
|
final ECSignedPreKey pniSignedPreKey;
|
||||||
|
final KEMSignedPreKey aciPqLastResortPreKey;
|
||||||
|
final KEMSignedPreKey pniPqLastResortPreKey;
|
||||||
|
|
||||||
|
final ECKeyPair aciIdentityKeyPair = Curve.generateKeyPair();
|
||||||
|
final ECKeyPair pniIdentityKeyPair = Curve.generateKeyPair();
|
||||||
|
|
||||||
|
aciSignedPreKey = KeysHelper.signedECPreKey(1, aciIdentityKeyPair);
|
||||||
|
pniSignedPreKey = KeysHelper.signedECPreKey(2, pniIdentityKeyPair);
|
||||||
|
aciPqLastResortPreKey = KeysHelper.signedKEMPreKey(3, aciIdentityKeyPair);
|
||||||
|
pniPqLastResortPreKey = KeysHelper.signedKEMPreKey(4, pniIdentityKeyPair);
|
||||||
|
|
||||||
|
when(account.getIdentityKey(IdentityType.ACI)).thenReturn(new IdentityKey(aciIdentityKeyPair.getPublicKey()));
|
||||||
|
when(account.getIdentityKey(IdentityType.PNI)).thenReturn(new IdentityKey(pniIdentityKeyPair.getPublicKey()));
|
||||||
|
when(account.isDeleteSyncSupported()).thenReturn(accountSupportsVersionedExpirationTimer);
|
||||||
|
|
||||||
|
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||||
|
|
||||||
|
final LinkDeviceRequest request = new LinkDeviceRequest(deviceController.generateVerificationToken(AuthHelper.VALID_UUID),
|
||||||
|
new AccountAttributes(false, 1234, 5678, null, null, true, new DeviceCapabilities(true, true, true, deviceSupportsVersionedExpirationTimer, false)),
|
||||||
|
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||||
|
|
||||||
|
try (final Response response = resources.getJerseyTest()
|
||||||
|
.target("/v1/devices/link")
|
||||||
|
.request()
|
||||||
|
.header("Authorization", AuthHelper.getProvisioningAuthHeader(AuthHelper.VALID_NUMBER, "password1"))
|
||||||
|
.put(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE))) {
|
||||||
|
|
||||||
|
assertEquals(expectedStatus, response.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Arguments> deviceDowngradeVersionedExpirationTimer() {
|
||||||
|
return List.of(
|
||||||
|
Arguments.of(true, true, 200),
|
||||||
|
Arguments.of(true, false, 409),
|
||||||
|
Arguments.of(false, true, 200),
|
||||||
|
Arguments.of(false, false, 200));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void linkDeviceAtomicBadCredentials() {
|
void linkDeviceAtomicBadCredentials() {
|
||||||
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account));
|
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account));
|
||||||
|
@ -683,7 +736,7 @@ class DeviceControllerTest {
|
||||||
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||||
|
|
||||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.verificationCode(),
|
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.verificationCode(),
|
||||||
new AccountAttributes(false, registrationId, pniRegistrationId, null, null, true, new DeviceCapabilities(true, true, true, false)),
|
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", null)), Optional.empty()));
|
||||||
|
|
||||||
try (final Response response = resources.getJerseyTest()
|
try (final Response response = resources.getJerseyTest()
|
||||||
|
@ -742,7 +795,7 @@ class DeviceControllerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void putCapabilitiesSuccessTest() {
|
void putCapabilitiesSuccessTest() {
|
||||||
final DeviceCapabilities deviceCapabilities = new DeviceCapabilities(true, true, true, false);
|
final DeviceCapabilities deviceCapabilities = new DeviceCapabilities(true, true, true, false, false);
|
||||||
final Response response = resources
|
final Response response = resources
|
||||||
.getJerseyTest()
|
.getJerseyTest()
|
||||||
.target("/v1/devices/capabilities")
|
.target("/v1/devices/capabilities")
|
||||||
|
|
|
@ -59,6 +59,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.signal.libsignal.protocol.IdentityKey;
|
import org.signal.libsignal.protocol.IdentityKey;
|
||||||
import org.signal.libsignal.protocol.ServiceId;
|
import org.signal.libsignal.protocol.ServiceId;
|
||||||
|
@ -439,10 +440,12 @@ class ProfileControllerTest {
|
||||||
assertThat(response.getStatus()).isEqualTo(401);
|
assertThat(response.getStatus()).isEqualTo(401);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@CartesianTest
|
||||||
@ValueSource(booleans = {true, false})
|
void testProfileCapabilities(
|
||||||
void testProfileCapabilities(final boolean isDeleteSyncSupported) {
|
@CartesianTest.Values(booleans = {true, false}) final boolean isDeleteSyncSupported,
|
||||||
|
@CartesianTest.Values(booleans = {true, false}) final boolean isVersionedExpirationTimerSupported) {
|
||||||
when(capabilitiesAccount.isDeleteSyncSupported()).thenReturn(isDeleteSyncSupported);
|
when(capabilitiesAccount.isDeleteSyncSupported()).thenReturn(isDeleteSyncSupported);
|
||||||
|
when(capabilitiesAccount.isVersionedExpirationTimerSupported()).thenReturn(isVersionedExpirationTimerSupported);
|
||||||
final BaseProfileResponse profile = resources.getJerseyTest()
|
final BaseProfileResponse profile = resources.getJerseyTest()
|
||||||
.target("/v1/profile/" + AuthHelper.VALID_UUID)
|
.target("/v1/profile/" + AuthHelper.VALID_UUID)
|
||||||
.request()
|
.request()
|
||||||
|
@ -450,6 +453,7 @@ class ProfileControllerTest {
|
||||||
.get(BaseProfileResponse.class);
|
.get(BaseProfileResponse.class);
|
||||||
|
|
||||||
assertEquals(isDeleteSyncSupported, profile.getCapabilities().deleteSync());
|
assertEquals(isDeleteSyncSupported, profile.getCapabilities().deleteSync());
|
||||||
|
assertEquals(isVersionedExpirationTimerSupported, profile.getCapabilities().versionedExpirationTimer());
|
||||||
assertThat(profile.getCapabilities().paymentActivation()).isTrue();
|
assertThat(profile.getCapabilities().paymentActivation()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -526,10 +526,10 @@ class RegistrationControllerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
final AccountAttributes fetchesMessagesAccountAttributes =
|
final AccountAttributes fetchesMessagesAccountAttributes =
|
||||||
new AccountAttributes(true, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false));
|
new AccountAttributes(true, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false, false));
|
||||||
|
|
||||||
final AccountAttributes pushAccountAttributes =
|
final AccountAttributes pushAccountAttributes =
|
||||||
new AccountAttributes(false, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false));
|
new AccountAttributes(false, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false, false));
|
||||||
|
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
// "Fetches messages" is true, but an APNs token is provided
|
// "Fetches messages" is true, but an APNs token is provided
|
||||||
|
@ -615,7 +615,7 @@ class RegistrationControllerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
final AccountAttributes accountAttributes =
|
final AccountAttributes accountAttributes =
|
||||||
new AccountAttributes(true, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false));
|
new AccountAttributes(true, 1, 1, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false, false));
|
||||||
|
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
// Signed PNI EC pre-key is missing
|
// Signed PNI EC pre-key is missing
|
||||||
|
@ -785,13 +785,13 @@ class RegistrationControllerTest {
|
||||||
final int registrationId = 1;
|
final int registrationId = 1;
|
||||||
final int pniRegistrationId = 2;
|
final int pniRegistrationId = 2;
|
||||||
|
|
||||||
final Device.DeviceCapabilities deviceCapabilities = new Device.DeviceCapabilities(false, false, false, false);
|
final Device.DeviceCapabilities deviceCapabilities = new Device.DeviceCapabilities(false, false, false, false, false);
|
||||||
|
|
||||||
final AccountAttributes fetchesMessagesAccountAttributes =
|
final AccountAttributes fetchesMessagesAccountAttributes =
|
||||||
new AccountAttributes(true, registrationId, pniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false));
|
new AccountAttributes(true, registrationId, pniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false, false));
|
||||||
|
|
||||||
final AccountAttributes pushAccountAttributes =
|
final AccountAttributes pushAccountAttributes =
|
||||||
new AccountAttributes(false, registrationId, pniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false));
|
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 apnsToken = "apns-token";
|
||||||
final String apnsVoipToken = "apns-voip-token";
|
final String apnsVoipToken = "apns-voip-token";
|
||||||
|
@ -906,7 +906,7 @@ class RegistrationControllerTest {
|
||||||
final IdentityKey pniIdentityKey = new IdentityKey(pniIdentityKeyPair.getPublicKey());
|
final IdentityKey pniIdentityKey = new IdentityKey(pniIdentityKeyPair.getPublicKey());
|
||||||
|
|
||||||
final AccountAttributes accountAttributes = new AccountAttributes(true, registrationId, pniRegistrationId, "name".getBytes(StandardCharsets.UTF_8), "reglock",
|
final AccountAttributes accountAttributes = new AccountAttributes(true, registrationId, pniRegistrationId, "name".getBytes(StandardCharsets.UTF_8), "reglock",
|
||||||
true, new Device.DeviceCapabilities(true, true, true, false));
|
true, new Device.DeviceCapabilities(true, true, true, false, false));
|
||||||
|
|
||||||
final RegistrationRequest request = new RegistrationRequest(
|
final RegistrationRequest request = new RegistrationRequest(
|
||||||
Base64.getEncoder().encodeToString(sessionId.getBytes(StandardCharsets.UTF_8)),
|
Base64.getEncoder().encodeToString(sessionId.getBytes(StandardCharsets.UTF_8)),
|
||||||
|
|
|
@ -395,7 +395,8 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||||
@CartesianTest.Values(booleans = {true, false}) final boolean storage,
|
@CartesianTest.Values(booleans = {true, false}) final boolean storage,
|
||||||
@CartesianTest.Values(booleans = {true, false}) final boolean transfer,
|
@CartesianTest.Values(booleans = {true, false}) final boolean transfer,
|
||||||
@CartesianTest.Values(booleans = {true, false}) final boolean paymentActivation,
|
@CartesianTest.Values(booleans = {true, false}) final boolean paymentActivation,
|
||||||
@CartesianTest.Values(booleans = {true, false}) final boolean deleteSync) {
|
@CartesianTest.Values(booleans = {true, false}) final boolean deleteSync,
|
||||||
|
@CartesianTest.Values(booleans = {true, false}) final boolean versionedExpirationTimer) {
|
||||||
|
|
||||||
mockAuthenticationInterceptor().setAuthenticatedDevice(AUTHENTICATED_ACI, deviceId);
|
mockAuthenticationInterceptor().setAuthenticatedDevice(AUTHENTICATED_ACI, deviceId);
|
||||||
|
|
||||||
|
@ -407,13 +408,15 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest<DevicesGrpcService, Devi
|
||||||
.setTransfer(transfer)
|
.setTransfer(transfer)
|
||||||
.setPaymentActivation(paymentActivation)
|
.setPaymentActivation(paymentActivation)
|
||||||
.setDeleteSync(deleteSync)
|
.setDeleteSync(deleteSync)
|
||||||
|
.setVersionedExpirationTimer(versionedExpirationTimer)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
final Device.DeviceCapabilities expectedCapabilities = new Device.DeviceCapabilities(
|
final Device.DeviceCapabilities expectedCapabilities = new Device.DeviceCapabilities(
|
||||||
storage,
|
storage,
|
||||||
transfer,
|
transfer,
|
||||||
paymentActivation,
|
paymentActivation,
|
||||||
deleteSync);
|
deleteSync,
|
||||||
|
versionedExpirationTimer);
|
||||||
|
|
||||||
verify(device).setCapabilities(expectedCapabilities);
|
verify(device).setCapabilities(expectedCapabilities);
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean());
|
ThreadLocalRandom.current().nextBoolean());
|
||||||
|
|
||||||
final AccountAttributes accountAttributes = new AccountAttributes(deliveryChannels.fetchesMessages(),
|
final AccountAttributes accountAttributes = new AccountAttributes(deliveryChannels.fetchesMessages(),
|
||||||
|
@ -297,14 +298,15 @@ public class AccountCreationDeletionIntegrationTest {
|
||||||
final KEMSignedPreKey pniPqLastResortPreKey = KeysHelper.signedKEMPreKey(4, pniKeyPair);
|
final KEMSignedPreKey pniPqLastResortPreKey = KeysHelper.signedKEMPreKey(4, pniKeyPair);
|
||||||
|
|
||||||
final Account originalAccount = accountsManager.create(number,
|
final Account originalAccount = accountsManager.create(number,
|
||||||
new AccountAttributes(true, 1, 1, "name".getBytes(StandardCharsets.UTF_8), "registration-lock", false, new Device.DeviceCapabilities(false, false, false, false)),
|
new AccountAttributes(true, 1, 1, "name".getBytes(StandardCharsets.UTF_8), "registration-lock", false,
|
||||||
|
new Device.DeviceCapabilities(false, false, false, false, false)),
|
||||||
Collections.emptyList(),
|
Collections.emptyList(),
|
||||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||||
new IdentityKey(pniKeyPair.getPublicKey()),
|
new IdentityKey(pniKeyPair.getPublicKey()),
|
||||||
new DeviceSpec(null,
|
new DeviceSpec(null,
|
||||||
"password?",
|
"password?",
|
||||||
"OWI",
|
"OWI",
|
||||||
new Device.DeviceCapabilities(false, false, false, false),
|
new Device.DeviceCapabilities(false, false, false, false, false),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
true,
|
true,
|
||||||
|
@ -329,6 +331,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean());
|
ThreadLocalRandom.current().nextBoolean());
|
||||||
|
|
||||||
final AccountAttributes accountAttributes = new AccountAttributes(deliveryChannels.fetchesMessages(),
|
final AccountAttributes accountAttributes = new AccountAttributes(deliveryChannels.fetchesMessages(),
|
||||||
|
@ -419,6 +422,7 @@ public class AccountCreationDeletionIntegrationTest {
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean(),
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
|
ThreadLocalRandom.current().nextBoolean(),
|
||||||
ThreadLocalRandom.current().nextBoolean());
|
ThreadLocalRandom.current().nextBoolean());
|
||||||
|
|
||||||
final AccountAttributes accountAttributes = new AccountAttributes(true,
|
final AccountAttributes accountAttributes = new AccountAttributes(true,
|
||||||
|
|
|
@ -46,6 +46,8 @@ class AccountTest {
|
||||||
private final Device paymentActivationIncapableDeviceWithoutDeliveryChannel = mock(Device.class);
|
private final Device paymentActivationIncapableDeviceWithoutDeliveryChannel = mock(Device.class);
|
||||||
private final Device deleteSyncCapableDevice = mock(Device.class);
|
private final Device deleteSyncCapableDevice = mock(Device.class);
|
||||||
private final Device deleteSyncIncapableDevice = mock(Device.class);
|
private final Device deleteSyncIncapableDevice = mock(Device.class);
|
||||||
|
private final Device versionedExpirationTimerCapableDevice = mock(Device.class);
|
||||||
|
private final Device versionedExpirationTimerIncapableDevice = mock(Device.class);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup() {
|
||||||
|
@ -66,19 +68,27 @@ class AccountTest {
|
||||||
when(oldSecondaryDevice.getId()).thenReturn(deviceId2);
|
when(oldSecondaryDevice.getId()).thenReturn(deviceId2);
|
||||||
|
|
||||||
when(paymentActivationCapableDevice.getCapabilities())
|
when(paymentActivationCapableDevice.getCapabilities())
|
||||||
.thenReturn(new DeviceCapabilities(true, true, true, false));
|
.thenReturn(new DeviceCapabilities(true, true, true, false, false));
|
||||||
|
|
||||||
when(paymentActivationIncapableDevice.getCapabilities())
|
when(paymentActivationIncapableDevice.getCapabilities())
|
||||||
.thenReturn(new DeviceCapabilities(true, true, false, false));
|
.thenReturn(new DeviceCapabilities(true, true, false, false, false));
|
||||||
|
|
||||||
when(paymentActivationIncapableDeviceWithoutDeliveryChannel.getCapabilities())
|
when(paymentActivationIncapableDeviceWithoutDeliveryChannel.getCapabilities())
|
||||||
.thenReturn(new DeviceCapabilities(true, true, false, false));
|
.thenReturn(new DeviceCapabilities(true, true, false, false, false));
|
||||||
|
|
||||||
when(deleteSyncCapableDevice.getCapabilities())
|
when(deleteSyncCapableDevice.getCapabilities())
|
||||||
.thenReturn(new DeviceCapabilities(true, true, true, true));
|
.thenReturn(new DeviceCapabilities(true, true, true, true, false));
|
||||||
|
|
||||||
when(deleteSyncIncapableDevice.getCapabilities())
|
when(deleteSyncIncapableDevice.getCapabilities())
|
||||||
.thenReturn(new DeviceCapabilities(true, true, true, false));
|
.thenReturn(new DeviceCapabilities(true, true, true, false, false));
|
||||||
|
|
||||||
|
when(versionedExpirationTimerCapableDevice.getId()).thenReturn((byte) 1);
|
||||||
|
when(versionedExpirationTimerCapableDevice.getCapabilities())
|
||||||
|
.thenReturn(new DeviceCapabilities(true, true, true, false, true));
|
||||||
|
|
||||||
|
when(versionedExpirationTimerIncapableDevice.getId()).thenReturn((byte) 2);
|
||||||
|
when(versionedExpirationTimerIncapableDevice.getCapabilities())
|
||||||
|
.thenReturn(new DeviceCapabilities(true, true, true, false, false));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +175,16 @@ class AccountTest {
|
||||||
"1234".getBytes(StandardCharsets.UTF_8)).isDeleteSyncSupported());
|
"1234".getBytes(StandardCharsets.UTF_8)).isDeleteSyncSupported());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void isVersionedExpirationTimerSupported() {
|
||||||
|
assertTrue(AccountsHelper.generateTestAccount("+18005551234", UUID.randomUUID(), UUID.randomUUID(),
|
||||||
|
List.of(versionedExpirationTimerCapableDevice),
|
||||||
|
"1234".getBytes(StandardCharsets.UTF_8)).isVersionedExpirationTimerSupported());
|
||||||
|
assertFalse(AccountsHelper.generateTestAccount("+18005551234", UUID.randomUUID(), UUID.randomUUID(),
|
||||||
|
List.of(versionedExpirationTimerIncapableDevice, versionedExpirationTimerCapableDevice),
|
||||||
|
"1234".getBytes(StandardCharsets.UTF_8)).isVersionedExpirationTimerSupported());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void stale() {
|
void stale() {
|
||||||
final Account account = AccountsHelper.generateTestAccount("+14151234567", UUID.randomUUID(), UUID.randomUUID(), Collections.emptyList(),
|
final Account account = AccountsHelper.generateTestAccount("+14151234567", UUID.randomUUID(), UUID.randomUUID(), Collections.emptyList(),
|
||||||
|
|
|
@ -193,7 +193,7 @@ class AccountsManagerChangeNumberIntegrationTest {
|
||||||
final int rotatedPniRegistrationId = 17;
|
final int rotatedPniRegistrationId = 17;
|
||||||
final ECKeyPair rotatedPniIdentityKeyPair = Curve.generateKeyPair();
|
final ECKeyPair rotatedPniIdentityKeyPair = Curve.generateKeyPair();
|
||||||
final ECSignedPreKey rotatedSignedPreKey = KeysHelper.signedECPreKey(1L, rotatedPniIdentityKeyPair);
|
final ECSignedPreKey rotatedSignedPreKey = KeysHelper.signedECPreKey(1L, rotatedPniIdentityKeyPair);
|
||||||
final AccountAttributes accountAttributes = new AccountAttributes(true, rotatedPniRegistrationId + 1, rotatedPniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false));
|
final AccountAttributes accountAttributes = new AccountAttributes(true, rotatedPniRegistrationId + 1, rotatedPniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, new Device.DeviceCapabilities(false, false, false, false, false));
|
||||||
final Account account = AccountsHelper.createAccount(accountsManager, originalNumber, accountAttributes);
|
final Account account = AccountsHelper.createAccount(accountsManager, originalNumber, accountAttributes);
|
||||||
|
|
||||||
keysManager.storeEcSignedPreKeys(account.getIdentifier(IdentityType.ACI),
|
keysManager.storeEcSignedPreKeys(account.getIdentifier(IdentityType.ACI),
|
||||||
|
|
|
@ -156,7 +156,7 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||||
null,
|
null,
|
||||||
"password",
|
"password",
|
||||||
null,
|
null,
|
||||||
new Device.DeviceCapabilities(false, false, false, false),
|
new Device.DeviceCapabilities(false, false, false, false, false),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -876,7 +876,7 @@ class AccountsManagerTest {
|
||||||
@ValueSource(booleans = {true, false})
|
@ValueSource(booleans = {true, false})
|
||||||
void testCreateWithStorageCapability(final boolean hasStorage) throws InterruptedException {
|
void testCreateWithStorageCapability(final boolean hasStorage) throws InterruptedException {
|
||||||
final AccountAttributes attributes = new AccountAttributes(false, 1, 2, null, null,
|
final AccountAttributes attributes = new AccountAttributes(false, 1, 2, null, null,
|
||||||
true, new DeviceCapabilities(hasStorage, false, false, false));
|
true, new DeviceCapabilities(hasStorage, false, false, false, false));
|
||||||
|
|
||||||
final Account account = createAccount("+18005550123", attributes);
|
final Account account = createAccount("+18005550123", attributes);
|
||||||
|
|
||||||
|
@ -901,7 +901,7 @@ class AccountsManagerTest {
|
||||||
final byte[] deviceNameCiphertext = "device-name".getBytes(StandardCharsets.UTF_8);
|
final byte[] deviceNameCiphertext = "device-name".getBytes(StandardCharsets.UTF_8);
|
||||||
final String password = "password";
|
final String password = "password";
|
||||||
final String signalAgent = "OWT";
|
final String signalAgent = "OWT";
|
||||||
final DeviceCapabilities deviceCapabilities = new DeviceCapabilities(true, true, true, false);
|
final DeviceCapabilities deviceCapabilities = new DeviceCapabilities(true, true, true, false, false);
|
||||||
final int aciRegistrationId = 17;
|
final int aciRegistrationId = 17;
|
||||||
final int pniRegistrationId = 19;
|
final int pniRegistrationId = 19;
|
||||||
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciKeyPair);
|
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciKeyPair);
|
||||||
|
|
|
@ -172,7 +172,7 @@ public class AddRemoveDeviceIntegrationTest {
|
||||||
"device-name".getBytes(StandardCharsets.UTF_8),
|
"device-name".getBytes(StandardCharsets.UTF_8),
|
||||||
"password",
|
"password",
|
||||||
"OWT",
|
"OWT",
|
||||||
new Device.DeviceCapabilities(true, true, true, false),
|
new Device.DeviceCapabilities(true, true, true, false, false),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
true,
|
true,
|
||||||
|
@ -215,7 +215,7 @@ public class AddRemoveDeviceIntegrationTest {
|
||||||
"device-name".getBytes(StandardCharsets.UTF_8),
|
"device-name".getBytes(StandardCharsets.UTF_8),
|
||||||
"password",
|
"password",
|
||||||
"OWT",
|
"OWT",
|
||||||
new Device.DeviceCapabilities(true, true, true, false),
|
new Device.DeviceCapabilities(true, true, true, false, false),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
true,
|
true,
|
||||||
|
@ -268,7 +268,7 @@ public class AddRemoveDeviceIntegrationTest {
|
||||||
"device-name".getBytes(StandardCharsets.UTF_8),
|
"device-name".getBytes(StandardCharsets.UTF_8),
|
||||||
"password",
|
"password",
|
||||||
"OWT",
|
"OWT",
|
||||||
new Device.DeviceCapabilities(true, true, true, false),
|
new Device.DeviceCapabilities(true, true, true, false, false),
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -149,6 +149,7 @@ public class AccountsHelper {
|
||||||
case "getNextDeviceId" -> when(updatedAccount.getNextDeviceId()).thenAnswer(stubbing);
|
case "getNextDeviceId" -> when(updatedAccount.getNextDeviceId()).thenAnswer(stubbing);
|
||||||
case "isPaymentActivationSupported" -> when(updatedAccount.isPaymentActivationSupported()).thenAnswer(stubbing);
|
case "isPaymentActivationSupported" -> when(updatedAccount.isPaymentActivationSupported()).thenAnswer(stubbing);
|
||||||
case "isDeleteSyncSupported" -> when(updatedAccount.isDeleteSyncSupported()).thenAnswer(stubbing);
|
case "isDeleteSyncSupported" -> when(updatedAccount.isDeleteSyncSupported()).thenAnswer(stubbing);
|
||||||
|
case "isVersionedExpirationTimerSupported" -> when(updatedAccount.isVersionedExpirationTimerSupported()).thenAnswer(stubbing);
|
||||||
case "getRegistrationLock" -> when(updatedAccount.getRegistrationLock()).thenAnswer(stubbing);
|
case "getRegistrationLock" -> when(updatedAccount.getRegistrationLock()).thenAnswer(stubbing);
|
||||||
case "getIdentityKey" ->
|
case "getIdentityKey" ->
|
||||||
when(updatedAccount.getIdentityKey(stubbing.getInvocation().getArgument(0))).thenAnswer(stubbing);
|
when(updatedAccount.getIdentityKey(stubbing.getInvocation().getArgument(0))).thenAnswer(stubbing);
|
||||||
|
|
Loading…
Reference in New Issue