mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Don't assume the presence of phone number-related fields in account creation or reclamation
This commit is contained in:
1 parent
5eb1a76e99
commit
3201ab324e
23 files changed
+753
-450
No files matched your search
+17
-23
@@ -257,7 +257,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
deviceAttributes,
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, apnRegistrationId, gcmRegistrationId));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), apnRegistrationId, gcmRegistrationId));
|
||||
|
||||
final LinkDeviceResponse response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -336,7 +336,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(false, 1234, 5678, null, requestCapabilities),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
final int expectedStatus =
|
||||
capability.getAccountCapabilityMode() != DeviceCapability.AccountCapabilityMode.ALWAYS_CAPABLE
|
||||
@@ -389,7 +389,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(false, 1234, 5678, null, requestCapabilities),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -427,7 +427,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(false, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -473,7 +473,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
deviceAttributes,
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -514,7 +514,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(false, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -563,7 +563,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.token(),
|
||||
new DeviceAttributes(fetchesMessages, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, apnRegistrationId, gcmRegistrationId));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), apnRegistrationId, gcmRegistrationId));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -594,24 +594,18 @@ class DeviceControllerTest {
|
||||
final KEMSignedPreKey pniPqLastResortPreKey) {
|
||||
|
||||
when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account));
|
||||
when(accountsManager.generateLinkDeviceToken(any())).thenReturn("test");
|
||||
when(accountsManager.checkDeviceLinkingToken(anyString())).thenReturn(Optional.of(AuthHelper.VALID_UUID));
|
||||
|
||||
final Device existingDevice = mock(Device.class);
|
||||
when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID);
|
||||
when(account.getDevices()).thenReturn(List.of(existingDevice));
|
||||
|
||||
final LinkDeviceToken deviceCode = resources.getJerseyTest()
|
||||
.target("/v1/devices/provisioning/code")
|
||||
.request()
|
||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.get(LinkDeviceToken.class);
|
||||
|
||||
when(account.getIdentityKey(IdentityType.ACI)).thenReturn(aciIdentityKey);
|
||||
when(account.getIdentityKey(IdentityType.PNI)).thenReturn(pniIdentityKey);
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.token(),
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(true, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.ofNullable(pniSignedPreKey), aciPqLastResortPreKey, Optional.ofNullable(pniPqLastResortPreKey), Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -671,7 +665,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(true, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -704,7 +698,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(true, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -763,7 +757,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(false, 1234, 5678, TestRandomUtil.nextBytes(512), null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -808,7 +802,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new DeviceAttributes(false, registrationId, pniRegistrationId, null, DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.of(new ApnRegistrationId("apn")), Optional.empty()));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.of(new ApnRegistrationId("apn")), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -859,7 +853,7 @@ class DeviceControllerTest {
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
null,
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
new DeviceActivationRequest(aciSignedPreKey, Optional.of(pniSignedPreKey), aciPqLastResortPreKey, Optional.of(pniPqLastResortPreKey), Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
.target("/v1/devices/link")
|
||||
@@ -1470,9 +1464,9 @@ class DeviceControllerTest {
|
||||
deviceAttributes,
|
||||
new DeviceActivationRequest(
|
||||
KeysHelper.signedECPreKey(1, aciIdentityKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniIdentityKeyPair),
|
||||
Optional.of(KeysHelper.signedECPreKey(2, pniIdentityKeyPair)),
|
||||
KeysHelper.signedKEMPreKey(3, aciIdentityKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniIdentityKeyPair),
|
||||
Optional.of(KeysHelper.signedKEMPreKey(4, pniIdentityKeyPair)),
|
||||
Optional.empty(),
|
||||
Optional.empty()));
|
||||
|
||||
|
||||
+39
-49
@@ -83,6 +83,7 @@ import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.DeviceCapability;
|
||||
import org.whispersystems.textsecuregcm.storage.DeviceIdentityInfo;
|
||||
import org.whispersystems.textsecuregcm.storage.DeviceSpec;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
import org.whispersystems.textsecuregcm.tests.util.KeysHelper;
|
||||
@@ -168,7 +169,7 @@ class RegistrationControllerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void invalidRegistrationId(Optional<Integer> registrationId, Optional<Integer> pniRegistrationId, int statusCode) throws InterruptedException, JsonProcessingException {
|
||||
void invalidRegistrationId(Optional<Integer> registrationId, Optional<Integer> pniRegistrationId, int statusCode) {
|
||||
final Invocation.Builder request = resources.getJerseyTest()
|
||||
.target("/v1/registration")
|
||||
.request()
|
||||
@@ -180,7 +181,7 @@ class RegistrationControllerTest {
|
||||
when(accountsManager.create(any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(account);
|
||||
|
||||
final String json = requestJson("sessionId", new byte[0], true, registrationId.orElse(0), pniRegistrationId.orElse(0));
|
||||
final String json = requestJson("sessionId", new byte[0], true, registrationId.orElse(0), pniRegistrationId.orElse(null));
|
||||
|
||||
try (Response response = request.post(Entity.json(json))) {
|
||||
assertEquals(statusCode, response.getStatus());
|
||||
@@ -450,9 +451,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.of(new ApnRegistrationId("apns-token")),
|
||||
Optional.empty()))),
|
||||
|
||||
@@ -464,9 +465,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.of(new GcmRegistrationId("gcm-token"))))),
|
||||
|
||||
@@ -478,9 +479,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.of(new ApnRegistrationId("apns-token")),
|
||||
Optional.of(new GcmRegistrationId("gcm-token")))))
|
||||
);
|
||||
@@ -533,7 +534,7 @@ class RegistrationControllerTest {
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
null,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.empty()))),
|
||||
|
||||
@@ -545,9 +546,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(null,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.empty()))),
|
||||
|
||||
@@ -559,7 +560,7 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
null,
|
||||
Optional.empty(),
|
||||
@@ -573,9 +574,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
null,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.empty()))),
|
||||
|
||||
@@ -587,9 +588,9 @@ class RegistrationControllerTest {
|
||||
null,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.empty()))),
|
||||
|
||||
@@ -601,9 +602,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
null,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.empty())))
|
||||
);
|
||||
@@ -752,9 +753,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.empty())),
|
||||
aciIdentityKey,
|
||||
@@ -764,15 +765,12 @@ class RegistrationControllerTest {
|
||||
PASSWORD,
|
||||
null,
|
||||
deviceCapabilities,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey)),
|
||||
Optional.empty()
|
||||
)),
|
||||
|
||||
Arguments.argumentSet("Has APNs tokens",
|
||||
new RegistrationRequest("session-id",
|
||||
@@ -782,9 +780,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.of(new ApnRegistrationId(apnsToken)),
|
||||
Optional.empty())),
|
||||
aciIdentityKey,
|
||||
@@ -794,15 +792,11 @@ class RegistrationControllerTest {
|
||||
PASSWORD,
|
||||
null,
|
||||
deviceCapabilities,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
false,
|
||||
Optional.of(new ApnRegistrationId(apnsToken)),
|
||||
Optional.empty(),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey)),
|
||||
Optional.empty())),
|
||||
|
||||
Arguments.argumentSet("Has GCM token",
|
||||
new RegistrationRequest("session-id",
|
||||
@@ -812,9 +806,9 @@ class RegistrationControllerTest {
|
||||
aciIdentityKey,
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey,
|
||||
Optional.of(pniPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
Optional.of(new GcmRegistrationId(gcmToken)))),
|
||||
aciIdentityKey,
|
||||
@@ -824,15 +818,11 @@ class RegistrationControllerTest {
|
||||
PASSWORD,
|
||||
null,
|
||||
deviceCapabilities,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
false,
|
||||
Optional.empty(),
|
||||
Optional.of(new GcmRegistrationId(gcmToken)),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey))
|
||||
Optional.of(new GcmRegistrationId(gcmToken))))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -841,7 +831,7 @@ class RegistrationControllerTest {
|
||||
final byte[] recoveryPassword,
|
||||
final boolean skipDeviceTransfer,
|
||||
final int registrationId,
|
||||
int pniRegistrationId,
|
||||
final Integer pniRegistrationId,
|
||||
Set<DeviceCapability> deviceCapabilities) {
|
||||
final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate();
|
||||
final ECKeyPair pniIdentityKeyPair = ECKeyPair.generate();
|
||||
@@ -863,9 +853,9 @@ class RegistrationControllerTest {
|
||||
pniIdentityKey,
|
||||
new DeviceActivationRequest(
|
||||
KeysHelper.signedECPreKey(1, aciIdentityKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniIdentityKeyPair),
|
||||
Optional.of(KeysHelper.signedECPreKey(2, pniIdentityKeyPair)),
|
||||
KeysHelper.signedKEMPreKey(3, aciIdentityKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniIdentityKeyPair),
|
||||
Optional.of(KeysHelper.signedKEMPreKey(4, pniIdentityKeyPair)),
|
||||
Optional.empty(),
|
||||
Optional.empty()));
|
||||
}
|
||||
@@ -885,7 +875,7 @@ class RegistrationControllerTest {
|
||||
final byte[] recoveryPassword,
|
||||
final boolean skipDeviceTransfer,
|
||||
final int registrationId,
|
||||
final int pniRegistrationId) {
|
||||
final Integer pniRegistrationId) {
|
||||
return requestToJson(request(sessionId, recoveryPassword, skipDeviceTransfer, registrationId, pniRegistrationId, DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES));
|
||||
}
|
||||
|
||||
|
||||
+136
-65
@@ -33,8 +33,11 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junitpioneer.jupiter.cartesian.ArgumentSets;
|
||||
import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
@@ -232,52 +235,129 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
deliveryChannels.fetchesMessages(),
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey),
|
||||
maybeGcmRegistrationId),
|
||||
null);
|
||||
|
||||
assertExpectedStoredAccount(account,
|
||||
number,
|
||||
Optional.of(number),
|
||||
password,
|
||||
signalAgent,
|
||||
deliveryChannels,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
Optional.of(pniRegistrationId),
|
||||
deviceName,
|
||||
discoverableByPhoneNumber,
|
||||
deviceCapabilities,
|
||||
badges,
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
registrationLockSecret,
|
||||
Optional.of(registrationLockSecret),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey);
|
||||
Optional.of(pniPqLastResortPreKey));
|
||||
|
||||
assertEquals(Optional.of(aciSignedPreKey), keysManager.getEcSignedPreKey(account.getAccountIdentifier(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(pniSignedPreKey), keysManager.getEcSignedPreKey(account.getPhoneNumberIdentifier(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(pniSignedPreKey), keysManager.getEcSignedPreKey(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(aciPqLastResortPreKey), keysManager.getLastResort(account.getAccountIdentifier(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(pniPqLastResortPreKey), keysManager.getLastResort(account.getPhoneNumberIdentifier(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(pniPqLastResortPreKey), keysManager.getLastResort(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("deliveryChannels")
|
||||
@Disabled("creating numberless accounts is not supported yet")
|
||||
void createAccountWithoutNumber(final DeliveryChannels deliveryChannels) {
|
||||
final String password = RandomStringUtils.secure().nextAlphanumeric(16);
|
||||
final String signalAgent = RandomStringUtils.secure().nextAlphabetic(3);
|
||||
final int registrationId = ThreadLocalRandom.current().nextInt(Device.MAX_REGISTRATION_ID);
|
||||
final byte[] deviceName = RandomStringUtils.secure().nextAlphabetic(16).getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
final Set<DeviceCapability> deviceCapabilities = Set.of();
|
||||
|
||||
final AccountAttributes accountAttributes = new AccountAttributes(deliveryChannels.fetchesMessages(),
|
||||
registrationId,
|
||||
null,
|
||||
deviceName,
|
||||
null,
|
||||
false,
|
||||
deviceCapabilities);
|
||||
|
||||
final List<AccountBadge> badges = new ArrayList<>(List.of(new AccountBadge(
|
||||
RandomStringUtils.secure().nextAlphabetic(8),
|
||||
CLOCK.instant().plus(Duration.ofDays(7)),
|
||||
true)));
|
||||
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
|
||||
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciKeyPair);
|
||||
final KEMSignedPreKey aciPqLastResortPreKey = KeysHelper.signedKEMPreKey(3, aciKeyPair);
|
||||
|
||||
final Optional<ApnRegistrationId> maybeApnRegistrationId =
|
||||
deliveryChannels.apnsToken() != null
|
||||
? Optional.of(new ApnRegistrationId(deliveryChannels.apnsToken()))
|
||||
: Optional.empty();
|
||||
|
||||
final Optional<GcmRegistrationId> maybeGcmRegistrationId = deliveryChannels.fcmToken() != null
|
||||
? Optional.of(new GcmRegistrationId(deliveryChannels.fcmToken()))
|
||||
: Optional.empty();
|
||||
|
||||
final Account account = accountsManager.create(accountAttributes,
|
||||
badges,
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new DeviceSpec(
|
||||
deviceName,
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.empty(),
|
||||
deliveryChannels.fetchesMessages(),
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId),
|
||||
null);
|
||||
|
||||
assertExpectedStoredAccount(account,
|
||||
Optional.empty(),
|
||||
password,
|
||||
signalAgent,
|
||||
deliveryChannels,
|
||||
registrationId,
|
||||
Optional.empty(),
|
||||
deviceName,
|
||||
false,
|
||||
deviceCapabilities,
|
||||
badges,
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
Optional.empty(),
|
||||
aciSignedPreKey,
|
||||
Optional.empty(),
|
||||
aciPqLastResortPreKey,
|
||||
Optional.empty());
|
||||
|
||||
assertEquals(Optional.of(aciSignedPreKey), keysManager.getEcSignedPreKey(account.getAccountIdentifier(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(aciPqLastResortPreKey), keysManager.getLastResort(account.getAccountIdentifier(), Device.PRIMARY_ID).join());
|
||||
|
||||
assertTrue(account.getNumberOptional().isEmpty());
|
||||
assertTrue(account.getPhoneNumberIdentifierOptional().isEmpty());
|
||||
assertTrue(account.getPhoneNumberIdentityKey().isEmpty());
|
||||
}
|
||||
|
||||
private static List<DeliveryChannels> deliveryChannels() {
|
||||
return List.of(
|
||||
new DeliveryChannels(true, null, null),
|
||||
new DeliveryChannels(false, "apns-token", null),
|
||||
new DeliveryChannels(false, "apns-token", null),
|
||||
new DeliveryChannels(false, null, "fcm-token"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
static ArgumentSets createAccount() {
|
||||
return ArgumentSets
|
||||
// deliveryChannels
|
||||
.argumentsForFirstParameter(
|
||||
new DeliveryChannels(true, null, null),
|
||||
new DeliveryChannels(false, "apns-token", null),
|
||||
new DeliveryChannels(false, "apns-token", null),
|
||||
new DeliveryChannels(false, null, "fcm-token"))
|
||||
|
||||
return ArgumentSets.argumentsForFirstParameter(deliveryChannels())
|
||||
// discoverableByPhoneNumber
|
||||
.argumentsForNextParameter(true, false);
|
||||
}
|
||||
@@ -310,15 +390,11 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
"password?",
|
||||
"OWI",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(2, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey),
|
||||
Optional.empty()),
|
||||
null);
|
||||
|
||||
existingAccountUuid = existingAccount.getAccountIdentifier();
|
||||
@@ -372,44 +448,40 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
accountAttributes.getFetchesMessages(),
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey),
|
||||
maybeGcmRegistrationId),
|
||||
null);
|
||||
|
||||
assertExpectedStoredAccount(reregisteredAccount,
|
||||
number,
|
||||
Optional.of(number),
|
||||
password,
|
||||
signalAgent,
|
||||
deliveryChannels,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
Optional.of(pniRegistrationId),
|
||||
deviceName,
|
||||
discoverableByPhoneNumber,
|
||||
deviceCapabilities,
|
||||
badges,
|
||||
maybeApnRegistrationId,
|
||||
maybeGcmRegistrationId,
|
||||
registrationLockSecret,
|
||||
Optional.of(registrationLockSecret),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey);
|
||||
Optional.of(pniPqLastResortPreKey));
|
||||
|
||||
assertEquals(existingAccountUuid, reregisteredAccount.getAccountIdentifier());
|
||||
|
||||
verify(disconnectionRequestManager).requestDisconnection(argThat(account ->
|
||||
account.getIdentifier(IdentityType.ACI).equals(existingAccountUuid) && account != reregisteredAccount));
|
||||
account.getAccountIdentifier().equals(existingAccountUuid) && account != reregisteredAccount));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAccount() throws InterruptedException {
|
||||
void deleteAccountWithNumber() throws InterruptedException {
|
||||
final String number = PhoneNumberUtil.getInstance().format(
|
||||
PhoneNumberUtil.getInstance().getExampleNumber("US"),
|
||||
PhoneNumberUtil.PhoneNumberFormat.E164);
|
||||
@@ -456,15 +528,11 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
registrationId,
|
||||
pniRegistrationId,
|
||||
new DeviceIdentityInfo(registrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey),
|
||||
Optional.empty()),
|
||||
null);
|
||||
|
||||
final UUID aci = account.getIdentifier(IdentityType.ACI);
|
||||
@@ -477,9 +545,9 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
assertFalse(accountsManager.getByAccountIdentifier(aci).isPresent());
|
||||
assertFalse(keysManager.getEcSignedPreKey(account.getAccountIdentifier(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getEcSignedPreKey(account.getPhoneNumberIdentifier(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getEcSignedPreKey(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getLastResort(account.getAccountIdentifier(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getLastResort(account.getPhoneNumberIdentifier(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(keysManager.getLastResort(account.getPhoneNumberIdentifierOptional().orElseThrow(), Device.PRIMARY_ID).join().isPresent());
|
||||
assertFalse(phoneNumberRecoveryPasswordsManager.verify(account.getPhoneNumberIdentifierOptional().orElseThrow(),
|
||||
accountAttributes.recoveryPassword().orElseThrow()));
|
||||
|
||||
@@ -489,31 +557,31 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
private void assertExpectedStoredAccount(final Account account,
|
||||
final String number,
|
||||
final Optional<String> number,
|
||||
final String password,
|
||||
final String signalAgent,
|
||||
final DeliveryChannels deliveryChannels,
|
||||
final int registrationId,
|
||||
final int pniRegistrationId,
|
||||
final Optional<Integer> pniRegistrationId,
|
||||
final byte[] deviceName,
|
||||
final boolean discoverableByPhoneNumber,
|
||||
final Set<DeviceCapability> deviceCapabilities,
|
||||
final List<AccountBadge> badges,
|
||||
final Optional<ApnRegistrationId> maybeApnRegistrationId,
|
||||
final Optional<GcmRegistrationId> maybeGcmRegistrationId,
|
||||
final String registrationLockSecret,
|
||||
final Optional<String> registrationLockSecret,
|
||||
final ECSignedPreKey aciSignedPreKey,
|
||||
final ECSignedPreKey pniSignedPreKey,
|
||||
final Optional<ECSignedPreKey> pniSignedPreKey,
|
||||
final KEMSignedPreKey aciPqLastResortPreKey,
|
||||
final KEMSignedPreKey pniPqLastResortPreKey) {
|
||||
final Optional<KEMSignedPreKey> pniPqLastResortPreKey) {
|
||||
|
||||
final Device primaryDevice = account.getPrimaryDevice();
|
||||
|
||||
assertEquals(number, account.getNumber());
|
||||
assertEquals(number, account.getNumberOptional());
|
||||
assertEquals(signalAgent, primaryDevice.getUserAgent());
|
||||
assertEquals(deliveryChannels.fetchesMessages(), primaryDevice.getFetchesMessages());
|
||||
assertEquals(registrationId, primaryDevice.getRegistrationId(IdentityType.ACI));
|
||||
assertEquals(pniRegistrationId, primaryDevice.getRegistrationId(IdentityType.PNI));
|
||||
assertEquals(registrationId, primaryDevice.getAccountRegistrationId());
|
||||
assertEquals(pniRegistrationId, primaryDevice.getPhoneNumberIdentityRegistrationId());
|
||||
assertArrayEquals(deviceName, primaryDevice.getName());
|
||||
assertEquals(discoverableByPhoneNumber, account.isDiscoverableByPhoneNumber());
|
||||
assertEquals(deviceCapabilities, primaryDevice.getCapabilities());
|
||||
@@ -527,12 +595,15 @@ public class AccountCreationDeletionIntegrationTest {
|
||||
_ -> assertEquals(deliveryChannels.fcmToken(), primaryDevice.getGcmId()),
|
||||
() -> assertNull(primaryDevice.getGcmId()));
|
||||
|
||||
assertTrue(account.getRegistrationLock().verify(registrationLockSecret));
|
||||
registrationLockSecret.ifPresent(regLockSecret -> assertTrue(account.getRegistrationLock().verify(regLockSecret)));
|
||||
assertTrue(primaryDevice.getAuthTokenHash().verify(password));
|
||||
assertNotNull(primaryDevice.getCreatedAtCiphertext());
|
||||
assertEquals(Optional.of(aciSignedPreKey), keysManager.getEcSignedPreKey(account.getIdentifier(IdentityType.ACI), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(pniSignedPreKey), keysManager.getEcSignedPreKey(account.getIdentifier(IdentityType.PNI), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(aciPqLastResortPreKey), keysManager.getLastResort(account.getIdentifier(IdentityType.ACI), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(pniPqLastResortPreKey), keysManager.getLastResort(account.getIdentifier(IdentityType.PNI), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(aciSignedPreKey), keysManager.getEcSignedPreKey(account.getAccountIdentifier(), Device.PRIMARY_ID).join());
|
||||
assertEquals(Optional.of(aciPqLastResortPreKey), keysManager.getLastResort(account.getAccountIdentifier(), Device.PRIMARY_ID).join());
|
||||
account.getPhoneNumberIdentifierOptional().ifPresent(
|
||||
pni -> {
|
||||
assertEquals(pniSignedPreKey, keysManager.getEcSignedPreKey(pni, Device.PRIMARY_ID).join());
|
||||
assertEquals(pniPqLastResortPreKey, keysManager.getLastResort(pni, Device.PRIMARY_ID).join());
|
||||
});
|
||||
}
|
||||
}
|
||||
+4
-8
@@ -151,16 +151,12 @@ class AccountsManagerConcurrentModificationIntegrationTest {
|
||||
"password",
|
||||
null,
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
null).getIdentifier(IdentityType.ACI),
|
||||
Optional.empty()),
|
||||
null).getAccountIdentifier(),
|
||||
a -> {
|
||||
a.setUnidentifiedAccessKey(new byte[UnidentifiedAccessUtil.UNIDENTIFIED_ACCESS_KEY_LENGTH]);
|
||||
a.removeDevice(Device.PRIMARY_ID);
|
||||
|
||||
+108
-55
@@ -680,7 +680,7 @@ class AccountsManagerTest {
|
||||
assertFalse(account.getDevice(linkedDevice.getId()).isPresent());
|
||||
verify(messagesManager, times(2)).clear(account.getAccountIdentifier(), linkedDevice.getId());
|
||||
verify(keysManager, times(2)).deleteSingleUsePreKeys(account.getAccountIdentifier(), linkedDevice.getId());
|
||||
verify(keysManager).buildWriteItemsForRemovedDevice(account.getAccountIdentifier(), account.getPhoneNumberIdentifier(), linkedDevice.getId());
|
||||
verify(keysManager).buildWriteItemsForRemovedDevice(account.getAccountIdentifier(), account.getPhoneNumberIdentifierOptional(), linkedDevice.getId());
|
||||
verify(disconnectionRequestManager).requestDisconnection(account.getAccountIdentifier(), List.of(linkedDevice.getId()));
|
||||
}
|
||||
|
||||
@@ -703,24 +703,44 @@ class AccountsManagerTest {
|
||||
verify(disconnectionRequestManager, never()).requestDisconnection(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateFreshAccount() throws InterruptedException, AccountAlreadyExistsException {
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void testCreateFreshAccount(final boolean hasE164) throws AccountAlreadyExistsException {
|
||||
when(accounts.create(any(), any())).thenReturn(true);
|
||||
|
||||
final String e164 = "+18005550123";
|
||||
final AccountAttributes attributes = new AccountAttributes(false, 1, 2, null, null, true, null);
|
||||
final Optional<String> maybeE164 = hasE164 ? Optional.of("+18005550123") : Optional.empty();
|
||||
final Integer pniRegistrationId = hasE164 ? 2 : null;
|
||||
final AccountAttributes attributes = new AccountAttributes(false, 1, pniRegistrationId, null, null, hasE164, null);
|
||||
|
||||
final Account createdAccount = createAccount(e164, attributes);
|
||||
final Account createdAccount = maybeE164
|
||||
.map(e164 -> createAccount(e164, attributes))
|
||||
.orElseGet(() -> createAccount(attributes));
|
||||
|
||||
verify(accounts).create(argThat(account -> e164.equals(account.getNumber())), any());
|
||||
// Check existence (or lack thereof) of phone number, phone number identifier, phone number identity key,
|
||||
// and phone number identity registration ID
|
||||
final Device primaryDevice = createdAccount.getDevices().stream().findFirst().orElseThrow();
|
||||
assertEquals(maybeE164, createdAccount.getNumberOptional());
|
||||
maybeE164.ifPresentOrElse(
|
||||
number -> {
|
||||
assertTrue(phoneNumberIdentifiersByE164.containsKey(number));
|
||||
assertTrue(createdAccount.getPhoneNumberIdentityKey().isPresent());
|
||||
assertEquals(pniRegistrationId, primaryDevice.getPhoneNumberIdentityRegistrationId().orElseThrow());
|
||||
},
|
||||
() -> {
|
||||
assertTrue(phoneNumberIdentifiersByE164.isEmpty());
|
||||
assertTrue(createdAccount.getPhoneNumberIdentityKey().isEmpty());
|
||||
assertTrue(primaryDevice.getPhoneNumberIdentityRegistrationId().isEmpty());
|
||||
});
|
||||
|
||||
verify(accounts).create(argThat(account -> maybeE164.equals(account.getNumberOptional())), any());
|
||||
verify(keysManager).buildWriteItemsForNewDevice(
|
||||
eq(createdAccount.getAccountIdentifier()),
|
||||
eq(createdAccount.getPhoneNumberIdentifier()),
|
||||
eq(createdAccount.getPhoneNumberIdentifierOptional()),
|
||||
eq(Device.PRIMARY_ID),
|
||||
notNull(),
|
||||
maybeE164.isPresent() ? notNull() : eq(Optional.empty()),
|
||||
notNull(),
|
||||
notNull(),
|
||||
notNull());
|
||||
maybeE164.isPresent() ? notNull() : eq(Optional.empty()));
|
||||
|
||||
verify(changeNumberWaitingPeriodManager).handleAccountCreated(eq(createdAccount.getAccountIdentifier()), any(Instant.class));
|
||||
|
||||
@@ -729,17 +749,14 @@ class AccountsManagerTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"+18005550123, +18005550123",
|
||||
// the canonical form of numbers may change over time, so an existing account might have not-identical e164 that
|
||||
// maps to the same PNI, and the number used by the caller must be present on the re-registered account
|
||||
"+2290123456789, +22923456789"
|
||||
})
|
||||
void testReregisterAccount(final String e164, final String existingAccountE164)
|
||||
throws InterruptedException, AccountAlreadyExistsException {
|
||||
@MethodSource
|
||||
void testReregisterAccount(
|
||||
final Optional<String> maybeE164,
|
||||
final Optional<String> maybeExistingAccountE164)
|
||||
throws AccountAlreadyExistsException {
|
||||
final UUID existingUuid = UUID.randomUUID();
|
||||
|
||||
final AccountAttributes attributes = new AccountAttributes(false, 1, 2, null, null, true, null);
|
||||
final Integer pniRegistrationId = maybeE164.isPresent() ? 2 : null;
|
||||
final AccountAttributes attributes = new AccountAttributes(false, 1, pniRegistrationId, null, null, maybeE164.isPresent(), null);
|
||||
|
||||
when(accounts.create(any(), any()))
|
||||
.thenAnswer(invocation -> {
|
||||
@@ -747,10 +764,8 @@ class AccountsManagerTest {
|
||||
|
||||
final Account existingAccount = mock(Account.class);
|
||||
when(existingAccount.getAccountIdentifier()).thenReturn(existingUuid);
|
||||
when(existingAccount.getIdentifier(IdentityType.ACI)).thenReturn(existingUuid);
|
||||
when(existingAccount.getNumber()).thenReturn(existingAccountE164);
|
||||
when(existingAccount.getPhoneNumberIdentifier()).thenReturn(requestedAccount.getIdentifier(IdentityType.PNI));
|
||||
when(existingAccount.getIdentifier(IdentityType.PNI)).thenReturn(requestedAccount.getIdentifier(IdentityType.PNI));
|
||||
when(existingAccount.getNumberOptional()).thenReturn(maybeExistingAccountE164);
|
||||
when(existingAccount.getPhoneNumberIdentifierOptional()).thenReturn(requestedAccount.getPhoneNumberIdentifierOptional());
|
||||
when(existingAccount.getPrimaryDevice()).thenReturn(mock(Device.class));
|
||||
|
||||
throw new AccountAlreadyExistsException(existingAccount);
|
||||
@@ -758,32 +773,57 @@ class AccountsManagerTest {
|
||||
|
||||
when(accounts.reclaimAccount(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(null));
|
||||
|
||||
final Account reregisteredAccount = createAccount(e164, attributes);
|
||||
final Account reregisteredAccount = maybeE164
|
||||
.map(number -> createAccount(number, attributes))
|
||||
.orElseGet(() -> createAccount(attributes));
|
||||
|
||||
assertTrue(phoneNumberIdentifiersByE164.containsKey(e164));
|
||||
assertEquals(e164, reregisteredAccount.getNumber());
|
||||
// Check existence (or lack thereof) of phone number, phone number identifier, phone number identity key,
|
||||
// and phone number identity registration ID
|
||||
final Device primaryDevice = reregisteredAccount.getDevices().stream().findFirst().orElseThrow();
|
||||
|
||||
assertEquals(maybeE164, reregisteredAccount.getNumberOptional());
|
||||
maybeE164.ifPresentOrElse(
|
||||
number -> {
|
||||
assertTrue(phoneNumberIdentifiersByE164.containsKey(number));
|
||||
assertTrue(reregisteredAccount.getPhoneNumberIdentityKey().isPresent());
|
||||
assertEquals(pniRegistrationId, primaryDevice.getPhoneNumberIdentityRegistrationId().orElseThrow());
|
||||
},
|
||||
() -> {
|
||||
assertTrue(phoneNumberIdentifiersByE164.isEmpty());
|
||||
assertTrue(reregisteredAccount.getPhoneNumberIdentityKey().isEmpty());
|
||||
assertTrue(primaryDevice.getPhoneNumberIdentityRegistrationId().isEmpty());
|
||||
});
|
||||
|
||||
verify(accounts)
|
||||
.create(argThat(account -> e164.equals(account.getNumber()) && existingUuid.equals(account.getAccountIdentifier())), any());
|
||||
.create(argThat(account -> existingUuid.equals(account.getAccountIdentifier())), any());
|
||||
|
||||
verify(keysManager).buildWriteItemsForNewDevice(
|
||||
eq(reregisteredAccount.getAccountIdentifier()),
|
||||
eq(reregisteredAccount.getPhoneNumberIdentifier()),
|
||||
eq(reregisteredAccount.getPhoneNumberIdentifierOptional()),
|
||||
eq(Device.PRIMARY_ID),
|
||||
notNull(),
|
||||
maybeE164.isPresent() ? notNull() : eq(Optional.empty()),
|
||||
notNull(),
|
||||
notNull(),
|
||||
notNull());
|
||||
maybeE164.isPresent() ? notNull() : eq(Optional.empty()));
|
||||
|
||||
verify(keysManager, times(2)).deleteSingleUsePreKeys(existingUuid);
|
||||
verify(keysManager, times(2)).deleteSingleUsePreKeys(phoneNumberIdentifiersByE164.get(e164));
|
||||
maybeE164.ifPresent(number -> verify(keysManager, times(2)).deleteSingleUsePreKeys(phoneNumberIdentifiersByE164.get(number)));
|
||||
verify(messagesManager, times(2)).clear(existingUuid);
|
||||
verify(profilesManager, times(2)).deleteAll(existingUuid, false);
|
||||
verify(disconnectionRequestManager).requestDisconnection(argThat(account ->
|
||||
account.getIdentifier(IdentityType.ACI).equals(existingUuid) && account != reregisteredAccount));
|
||||
account.getAccountIdentifier().equals(existingUuid) && account != reregisteredAccount));
|
||||
verify(changeNumberWaitingPeriodManager).handleAccountCreated(eq(existingUuid), any(Instant.class));
|
||||
}
|
||||
|
||||
private static List<Arguments> testReregisterAccount() {
|
||||
return List.of(
|
||||
Arguments.argumentSet("Re-register with the same phone number", Optional.of("+18005550123"), Optional.of("+18005550123")),
|
||||
// the canonical form of numbers may change over time, so an existing account might have not-identical e164 that
|
||||
// maps to the same PNI, and the number used by the caller must be present on the re-registered account
|
||||
Arguments.argumentSet("Re-register with a phone number in the same equivalence class", Optional.of("+2290123456789"), Optional.of("+22923456789")),
|
||||
Arguments.argumentSet("Re-register a numberless account", Optional.empty(), Optional.empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAccountRecentlyDeleted() throws InterruptedException, AccountAlreadyExistsException {
|
||||
final UUID recentlyDeletedUuid = UUID.randomUUID();
|
||||
@@ -797,11 +837,11 @@ class AccountsManagerTest {
|
||||
final Account account = createAccount(e164, attributes);
|
||||
|
||||
verify(accounts).create(
|
||||
argThat(a -> e164.equals(a.getNumber()) && recentlyDeletedUuid.equals(a.getAccountIdentifier())),
|
||||
argThat(a -> e164.equals(a.getNumberOptional().get()) && recentlyDeletedUuid.equals(a.getAccountIdentifier())),
|
||||
any());
|
||||
|
||||
verify(keysManager).buildWriteItemsForNewDevice(eq(account.getIdentifier(IdentityType.ACI)),
|
||||
eq(account.getIdentifier(IdentityType.PNI)),
|
||||
verify(keysManager).buildWriteItemsForNewDevice(eq(account.getAccountIdentifier()),
|
||||
eq(account.getPhoneNumberIdentifierOptional()),
|
||||
eq(Device.PRIMARY_ID),
|
||||
any(),
|
||||
any(),
|
||||
@@ -871,15 +911,11 @@ class AccountsManagerTest {
|
||||
password,
|
||||
signalAgent,
|
||||
deviceCapabilities,
|
||||
aciRegistrationId,
|
||||
pniRegistrationId,
|
||||
new DeviceIdentityInfo(aciRegistrationId, aciSignedPreKey, aciPqLastResortPreKey),
|
||||
Optional.of(new DeviceIdentityInfo(pniRegistrationId, pniSignedPreKey, pniPqLastResortPreKey)),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey),
|
||||
Optional.empty()),
|
||||
accountsManager.generateLinkDeviceToken(aci));
|
||||
|
||||
verify(keysManager).deleteSingleUsePreKeys(aci, nextDeviceId);
|
||||
@@ -888,12 +924,12 @@ class AccountsManagerTest {
|
||||
|
||||
verify(keysManager).buildWriteItemsForNewDevice(
|
||||
aci,
|
||||
pni,
|
||||
Optional.of(pni),
|
||||
nextDeviceId,
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
Optional.of(pniSignedPreKey),
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey);
|
||||
Optional.of(pniPqLastResortPreKey));
|
||||
|
||||
final Device device = updatedAccountAndDevice.second();
|
||||
|
||||
@@ -1029,7 +1065,7 @@ class AccountsManagerTest {
|
||||
verify(keysManager).deleteSingleUsePreKeys(originalPni);
|
||||
verify(keysManager, atLeastOnce()).deleteSingleUsePreKeys(targetPni);
|
||||
verify(keysManager).deleteSingleUsePreKeys(newPni);
|
||||
verify(keysManager).buildWriteItemsForRemovedDevice(existingAccountUuid, targetPni, Device.PRIMARY_ID);
|
||||
verify(keysManager).buildWriteItemsForRemovedDevice(existingAccountUuid, Optional.of(targetPni), Device.PRIMARY_ID);
|
||||
verify(keysManager).buildWriteItemForEcSignedPreKey(newPni, Device.PRIMARY_ID, ecSignedPreKey);
|
||||
verify(keysManager).buildWriteItemForLastResortKey(newPni, Device.PRIMARY_ID, kemLastResoryPreKey);
|
||||
verifyNoMoreInteractions(keysManager);
|
||||
@@ -1329,7 +1365,26 @@ class AccountsManagerTest {
|
||||
return device;
|
||||
}
|
||||
|
||||
private Account createAccount(final String e164, final AccountAttributes accountAttributes) throws InterruptedException {
|
||||
private Account createAccount(final AccountAttributes accountAttributes) {
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
|
||||
return accountsManager.create(accountAttributes,
|
||||
new ArrayList<>(),
|
||||
new IdentityKey(aciKeyPair.getPublicKey()),
|
||||
new DeviceSpec(
|
||||
accountAttributes.getName(),
|
||||
"password",
|
||||
null,
|
||||
accountAttributes.getCapabilities(),
|
||||
new DeviceIdentityInfo(accountAttributes.getRegistrationId(), KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.empty(),
|
||||
accountAttributes.getFetchesMessages(),
|
||||
Optional.empty(),
|
||||
Optional.empty()),
|
||||
null);
|
||||
}
|
||||
|
||||
private Account createAccount(final String e164, final AccountAttributes accountAttributes) {
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
final ECKeyPair pniKeyPair = ECKeyPair.generate();
|
||||
|
||||
@@ -1343,15 +1398,13 @@ class AccountsManagerTest {
|
||||
"password",
|
||||
null,
|
||||
accountAttributes.getCapabilities(),
|
||||
accountAttributes.getRegistrationId(),
|
||||
accountAttributes.getPhoneNumberIdentityRegistrationId(),
|
||||
new DeviceIdentityInfo(accountAttributes.getRegistrationId(), KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(accountAttributes.getPhoneNumberIdentityRegistrationId().orElseThrow(() -> new AssertionError("PNI registration ID must be provided for an account with a phone number")),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
accountAttributes.getFetchesMessages(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
@@ -202,6 +203,13 @@ class AccountsTest {
|
||||
assertPhoneNumberIdentifierConstraintExists(account.getPhoneNumberIdentifier(), account.getAccountIdentifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStoreNumberlessAccount() {
|
||||
// Numberless account creation is not supported yet in the Accounts layer
|
||||
final Account account = generateNumberlessAccount(UUID.randomUUID());
|
||||
assertThrows(IllegalArgumentException.class, () -> createAccount(account));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStoreRecentlyDeleted() {
|
||||
final UUID originalUuid = UUID.randomUUID();
|
||||
@@ -459,7 +467,8 @@ class AccountsTest {
|
||||
accounts.confirmUsernameHash(existingAccount, usernameHash, encryptedUsername);
|
||||
final UUID usernameLinkHandle = existingAccount.getUsernameLinkHandle();
|
||||
|
||||
verifyStoredState(e164, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifier(), usernameHash, existingAccount, true);
|
||||
assertTrue(existingAccount.getPhoneNumberIdentifierOptional().isPresent());
|
||||
verifyStoredState(e164, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifierOptional().get(), usernameHash, existingAccount, true);
|
||||
|
||||
assertPhoneNumberConstraintExists(e164, existingUuid);
|
||||
assertPhoneNumberIdentifierConstraintExists(existingPni, existingUuid);
|
||||
@@ -507,6 +516,64 @@ class AccountsTest {
|
||||
assertThatThrownBy(() -> createAccount(invalidAccount));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled("reclaiming numberless accounts is not supported yet")
|
||||
void testReclaimNumberlessAccount() throws Exception {
|
||||
final UUID existingUuid = UUID.randomUUID();
|
||||
final Account numberlessExistingAccount = generateNumberlessAccount(existingUuid);
|
||||
|
||||
// Backup vouchers should be carried over across re-registration
|
||||
final Account.BackupVoucher bv = new Account.BackupVoucher(1, Instant.now().plus(Duration.ofDays(1)));
|
||||
numberlessExistingAccount.setBackupVoucher(bv);
|
||||
// ZK credential keys should be carried over across re-registration
|
||||
numberlessExistingAccount.setZkCredentialKey(ZkCredentialKeyPair.generate().getPublicKey());
|
||||
|
||||
createAccount(numberlessExistingAccount);
|
||||
|
||||
final byte[] usernameHash = TestRandomUtil.nextBytes(32);
|
||||
final byte[] encryptedUsername = TestRandomUtil.nextBytes(16);
|
||||
|
||||
// Set up the existing account to have a username hash
|
||||
accounts.confirmUsernameHash(numberlessExistingAccount, usernameHash, encryptedUsername);
|
||||
final UUID usernameLinkHandle = numberlessExistingAccount.getUsernameLinkHandle();
|
||||
|
||||
assertTrue(numberlessExistingAccount.getPhoneNumberIdentifierOptional().isEmpty());
|
||||
verifyStoredState(null, numberlessExistingAccount.getAccountIdentifier(), null, usernameHash, numberlessExistingAccount, true);
|
||||
|
||||
assertDoesNotThrow(() -> accounts.update(numberlessExistingAccount));
|
||||
|
||||
final Account secondAccount = generateNumberlessAccount(existingUuid);
|
||||
|
||||
// TODO: may need to update when we add support for reclaiming numberless accounts
|
||||
reclaimAccount(secondAccount);
|
||||
|
||||
// usernameHash should be unset
|
||||
verifyStoredState(null, existingUuid, null, null, secondAccount, true);
|
||||
|
||||
// username should become 'reclaimable'
|
||||
Map<String, AttributeValue> item = readAccount(existingUuid);
|
||||
Account result = Accounts.fromItem(item);
|
||||
assertThat(AttributeValues.getUUID(item, Accounts.ATTR_USERNAME_LINK_UUID, null))
|
||||
.isEqualTo(usernameLinkHandle)
|
||||
.isEqualTo(result.getUsernameLinkHandle());
|
||||
assertThat(result.getUsernameHash()).isEmpty();
|
||||
assertThat(result.getEncryptedUsername()).isEmpty();
|
||||
assertArrayEquals(result.getReservedUsernameHash().orElseThrow(), usernameHash);
|
||||
|
||||
assertThat(result.getBackupVoucher()).isEqualTo(bv);
|
||||
|
||||
// should keep the same usernameLink, now encryptedUsername should be set
|
||||
accounts.confirmUsernameHash(result, usernameHash, encryptedUsername);
|
||||
item = readAccount(existingUuid);
|
||||
result = Accounts.fromItem(item);
|
||||
assertThat(AttributeValues.getUUID(item, Accounts.ATTR_USERNAME_LINK_UUID, null))
|
||||
.isEqualTo(usernameLinkHandle)
|
||||
.isEqualTo(result.getUsernameLinkHandle());
|
||||
assertArrayEquals(encryptedUsername, result.getEncryptedUsername().orElseThrow());
|
||||
assertArrayEquals(usernameHash, result.getUsernameHash().orElseThrow());
|
||||
assertThat(result.getReservedUsernameHash()).isEmpty();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void testReclaimAccountEquivalentPhoneNumbers(final String firstNumber, final String secondNumber) throws IOException {
|
||||
@@ -516,7 +583,8 @@ class AccountsTest {
|
||||
|
||||
createAccount(existingAccount);
|
||||
|
||||
verifyStoredState(firstNumber, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifier(), null, existingAccount, true);
|
||||
assertTrue(existingAccount.getPhoneNumberIdentifierOptional().isPresent());
|
||||
verifyStoredState(firstNumber, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifierOptional().get(), null, existingAccount, true);
|
||||
|
||||
assertPhoneNumberConstraintExists(firstNumber, existingUuid);
|
||||
assertPhoneNumberIdentifierConstraintExists(pni, existingUuid);
|
||||
@@ -532,9 +600,10 @@ class AccountsTest {
|
||||
Map<String, AttributeValue> item = readAccount(existingUuid);
|
||||
final Account account = SystemMapper.jsonMapper().readValue(item.get(Accounts.ATTR_ACCOUNT_DATA).b().asByteArray(), Account.class);
|
||||
|
||||
assertTrue(account.getNumberOptional().isPresent());
|
||||
assertThat(AttributeValues.getString(item, Accounts.ATTR_ACCOUNT_E164, null))
|
||||
.isEqualTo(secondNumber)
|
||||
.isEqualTo(account.getNumber());
|
||||
.isEqualTo(account.getNumberOptional().get());
|
||||
assertPhoneNumberConstraintDoesNotExist(firstNumber);
|
||||
assertPhoneNumberConstraintExists(secondNumber, existingUuid);
|
||||
assertPhoneNumberIdentifierConstraintExists(pni, existingUuid);
|
||||
@@ -560,7 +629,8 @@ class AccountsTest {
|
||||
|
||||
createAccount(existingAccount);
|
||||
|
||||
verifyStoredState(beninPhoneNumber, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifier(), null, existingAccount, true);
|
||||
assertTrue(existingAccount.getPhoneNumberIdentifierOptional().isPresent());
|
||||
verifyStoredState(beninPhoneNumber, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifierOptional().get(), null, existingAccount, true);
|
||||
|
||||
assertPhoneNumberConstraintExists(beninPhoneNumber, existingUuid);
|
||||
assertPhoneNumberIdentifierConstraintExists(pni, existingUuid);
|
||||
@@ -595,7 +665,8 @@ class AccountsTest {
|
||||
|
||||
createAccount(existingAccount);
|
||||
|
||||
verifyStoredState(beninPhoneNumber, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifier(), null, existingAccount, true);
|
||||
assertTrue(existingAccount.getPhoneNumberIdentifierOptional().isPresent());
|
||||
verifyStoredState(beninPhoneNumber, existingAccount.getAccountIdentifier(), existingAccount.getPhoneNumberIdentifierOptional().get(), null, existingAccount, true);
|
||||
|
||||
assertPhoneNumberConstraintExists(beninPhoneNumber, existingUuid);
|
||||
assertPhoneNumberIdentifierConstraintExists(existingPni, existingUuid);
|
||||
@@ -2014,6 +2085,10 @@ class AccountsTest {
|
||||
return generateAccount(nextNumber, UUID.randomUUID(), UUID.randomUUID());
|
||||
}
|
||||
|
||||
private static Account generateNumberlessAccount(final UUID uuid) {
|
||||
return generateAccount(null, uuid, null);
|
||||
}
|
||||
|
||||
private static Account generateAccount(String number, UUID uuid, final UUID pni) {
|
||||
Device device = generateDevice(DEVICE_ID_1);
|
||||
return generateAccount(number, uuid, pni, List.of(device));
|
||||
@@ -2122,8 +2197,8 @@ class AccountsTest {
|
||||
}
|
||||
|
||||
private void verifyStoredState(String number, UUID uuid, UUID pni, byte[] usernameHash, Account result, Account expecting) {
|
||||
assertThat(result.getNumber()).isEqualTo(number);
|
||||
assertThat(result.getPhoneNumberIdentifier()).isEqualTo(pni);
|
||||
assertThat(result.getNumberOptional()).isEqualTo(Optional.ofNullable(number));
|
||||
assertThat(result.getPhoneNumberIdentifierOptional()).isEqualTo(Optional.ofNullable(pni));
|
||||
assertThat(result.getLastSeen()).isEqualTo(expecting.getLastSeen());
|
||||
assertThat(result.getAccountIdentifier()).isEqualTo(uuid);
|
||||
assertThat(result.getVersion()).isEqualTo(expecting.getVersion());
|
||||
@@ -2139,6 +2214,7 @@ class AccountsTest {
|
||||
assertThat(resultDevice.getUserAgent()).isEqualTo(expectingDevice.getUserAgent());
|
||||
assertThat(resultDevice.getName()).isEqualTo(expectingDevice.getName());
|
||||
assertThat(resultDevice.getCreated()).isEqualTo(expectingDevice.getCreated());
|
||||
assertThat(resultDevice.getPhoneNumberIdentityRegistrationId()).isEqualTo(expectingDevice.getPhoneNumberIdentityRegistrationId());
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-63
@@ -187,15 +187,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
accountsManager.generateLinkDeviceToken(account.getIdentifier(IdentityType.ACI)));
|
||||
|
||||
assertEquals(2, updatedAccountAndDevice.first().getDevices().size());
|
||||
@@ -237,15 +233,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
linkDeviceToken);
|
||||
|
||||
assertEquals(2,
|
||||
@@ -258,15 +250,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
linkDeviceToken));
|
||||
|
||||
assertEquals(2,
|
||||
@@ -292,15 +280,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
accountsManager.generateLinkDeviceToken(account.getIdentifier(IdentityType.ACI)));
|
||||
|
||||
final byte addedDeviceId = updatedAccountAndDevice.second().getId();
|
||||
@@ -343,15 +327,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
accountsManager.generateLinkDeviceToken(account.getIdentifier(IdentityType.ACI)));
|
||||
|
||||
final byte addedDeviceId = updatedAccountAndDevice.second().getId();
|
||||
@@ -413,15 +393,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
linkDeviceToken);
|
||||
|
||||
final Optional<DeviceInfo> maybeDeviceInfo = activeFuture.join();
|
||||
@@ -454,15 +430,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
linkDeviceToken);
|
||||
|
||||
when(messagesManager.getEarliestUndeliveredTimestampForDevice(account.getAccountIdentifier(), account.getPrimaryDevice()))
|
||||
@@ -523,15 +495,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
linkDeviceToken);
|
||||
|
||||
when(messagesManager.getEarliestUndeliveredTimestampForDevice(account.getAccountIdentifier(), account.getPrimaryDevice()))
|
||||
@@ -566,15 +534,11 @@ public class AddRemoveDeviceIntegrationTest {
|
||||
"password",
|
||||
"OWT",
|
||||
Set.of(),
|
||||
1,
|
||||
2,
|
||||
new DeviceIdentityInfo(1, KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(2, KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
true,
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
linkDeviceToken);
|
||||
|
||||
when(messagesManager.getEarliestUndeliveredTimestampForDevice(account.getAccountIdentifier(), account.getPrimaryDevice()))
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,7 +17,9 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair;
|
||||
import org.whispersystems.textsecuregcm.entities.ECPreKey;
|
||||
import org.whispersystems.textsecuregcm.entities.ECSignedPreKey;
|
||||
@@ -61,6 +64,38 @@ class KeysManagerTest {
|
||||
new RepeatedUseKEMSignedPreKeyStore(dynamoDbAsyncClient, Tables.REPEATED_USE_KEM_SIGNED_PRE_KEYS.tableName()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void buildWriteItemsForNewDevicePniPresentMissingPniPreKey(
|
||||
final Optional<ECSignedPreKey> pniSignedPreKey,
|
||||
final Optional<KEMSignedPreKey> pniPqLastResortPreKey) {
|
||||
final ECKeyPair aciKeyPair = ECKeyPair.generate();
|
||||
final ECSignedPreKey aciSignedPreKey = KeysHelper.signedECPreKey(1, aciKeyPair);
|
||||
final KEMSignedPreKey aciPqLastResortPreKey = KeysHelper.signedKEMPreKey(3, aciKeyPair);
|
||||
|
||||
assertThrows(AssertionError.class, () -> keysManager.buildWriteItemsForNewDevice(
|
||||
UUID.randomUUID(),
|
||||
Optional.of(UUID.randomUUID()),
|
||||
Device.PRIMARY_ID,
|
||||
aciSignedPreKey,
|
||||
pniSignedPreKey,
|
||||
aciPqLastResortPreKey,
|
||||
pniPqLastResortPreKey));
|
||||
}
|
||||
|
||||
private static List<Arguments> buildWriteItemsForNewDevicePniPresentMissingPniPreKey() {
|
||||
final ECKeyPair pniKeyPair = ECKeyPair.generate();
|
||||
|
||||
final ECSignedPreKey pniSignedPreKey = KeysHelper.signedECPreKey(2, pniKeyPair);
|
||||
final KEMSignedPreKey pniPqLastResortPreKey = KeysHelper.signedKEMPreKey(4, pniKeyPair);
|
||||
|
||||
return List.of(
|
||||
Arguments.argumentSet("Missing PNI signed pre key", Optional.empty(), Optional.of(pniPqLastResortPreKey)),
|
||||
Arguments.argumentSet("Missing PNI PQ last resort pre key", Optional.of(pniSignedPreKey), Optional.empty()),
|
||||
Arguments.argumentSet("Missing both PNI pre keys", Optional.empty(), Optional.empty())
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void storeEcOneTimePreKeys() {
|
||||
assertEquals(0, keysManager.getEcCount(ACCOUNT_UUID, DEVICE_ID).join(),
|
||||
|
||||
+5
-7
@@ -35,6 +35,7 @@ import org.whispersystems.textsecuregcm.identity.PniServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.DeviceIdentityInfo;
|
||||
import org.whispersystems.textsecuregcm.storage.DeviceSpec;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
|
||||
@@ -297,15 +298,12 @@ public class AccountsHelper {
|
||||
"password",
|
||||
"OWT",
|
||||
accountAttributes.getCapabilities(),
|
||||
accountAttributes.getRegistrationId(),
|
||||
accountAttributes.getPhoneNumberIdentityRegistrationId(),
|
||||
new DeviceIdentityInfo(accountAttributes.getRegistrationId(), KeysHelper.signedECPreKey(1, aciKeyPair), KeysHelper.signedKEMPreKey(3, aciKeyPair)),
|
||||
Optional.of(new DeviceIdentityInfo(accountAttributes.getPhoneNumberIdentityRegistrationId().orElseThrow(() -> new AssertionError("Must provide PNI registration ID for account with number")),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair), KeysHelper.signedKEMPreKey(4, pniKeyPair))),
|
||||
accountAttributes.getFetchesMessages(),
|
||||
Optional.empty(),
|
||||
Optional.empty(),
|
||||
KeysHelper.signedECPreKey(1, aciKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniKeyPair),
|
||||
KeysHelper.signedKEMPreKey(3, aciKeyPair),
|
||||
KeysHelper.signedKEMPreKey(4, pniKeyPair)),
|
||||
Optional.empty()),
|
||||
null);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user