mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Factor out DeviceAttributes from AccountAttributes
This commit is contained in:
1 parent
149de6c464
commit
5e1338a571
9 files changed
+115
-88
No files matched your search
+8
-8
@@ -786,8 +786,8 @@ class AccountControllerTest {
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION, AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.put(Entity.json(new AccountAttributes(false, 2222, 3333, null, null, true, null)
|
||||
.withUnidentifiedAccessKey(unidentifiedAccessKey)
|
||||
.withUnrestrictedUnidentifiedAccess(unrestrictedUnidentifiedAccess)))) {
|
||||
.setUnidentifiedAccessKey(unidentifiedAccessKey)
|
||||
.setUnrestrictedUnidentifiedAccess(unrestrictedUnidentifiedAccess)))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(expectedStatus);
|
||||
}
|
||||
@@ -810,7 +810,7 @@ class AccountControllerTest {
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION, AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.put(Entity.json(new AccountAttributes(false, 2222, 3333, null, null, true, null)
|
||||
.withUnidentifiedAccessKey(new byte[16])))) {
|
||||
.setUnidentifiedAccessKey(new byte[16])))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
}
|
||||
@@ -823,7 +823,7 @@ class AccountControllerTest {
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION, AuthHelper.getAuthHeader(AuthHelper.UNDISCOVERABLE_UUID, AuthHelper.UNDISCOVERABLE_PASSWORD))
|
||||
.put(Entity.json(new AccountAttributes(false, 2222, 3333, null, null, true, null)
|
||||
.withUnidentifiedAccessKey(new byte[16])))) {
|
||||
.setUnidentifiedAccessKey(new byte[16])))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
}
|
||||
@@ -840,8 +840,8 @@ class AccountControllerTest {
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION, AuthHelper.getAuthHeader(AuthHelper.UNDISCOVERABLE_UUID, AuthHelper.UNDISCOVERABLE_PASSWORD))
|
||||
.put(Entity.json(new AccountAttributes(false, 2222, 3333, null, null, true, null)
|
||||
.withUnidentifiedAccessKey(new byte[16])
|
||||
.withRecoveryPassword(recoveryPassword)))) {
|
||||
.setUnidentifiedAccessKey(new byte[16])
|
||||
.setRecoveryPassword(recoveryPassword)))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
verify(registrationRecoveryPasswordsManager).store(AuthHelper.UNDISCOVERABLE_PNI, recoveryPassword);
|
||||
@@ -855,7 +855,7 @@ class AccountControllerTest {
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION, AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.put(Entity.json(new AccountAttributes(false, 2222, 3333, null, null, false, null)
|
||||
.withUnidentifiedAccessKey(new byte[16])))) {
|
||||
.setUnidentifiedAccessKey(new byte[16])))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
}
|
||||
@@ -868,7 +868,7 @@ class AccountControllerTest {
|
||||
.request()
|
||||
.header(HttpHeaders.AUTHORIZATION, AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD))
|
||||
.put(Entity.json(new AccountAttributes(false, 2222, 3333, null, null, false, null)
|
||||
.withUnidentifiedAccessKey(new byte[7])))) {
|
||||
.setUnidentifiedAccessKey(new byte[7])))) {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(422);
|
||||
}
|
||||
|
||||
+20
-20
@@ -60,9 +60,9 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair;
|
||||
import org.whispersystems.textsecuregcm.auth.AuthenticatedDevice;
|
||||
import org.whispersystems.textsecuregcm.entities.AccountAttributes;
|
||||
import org.whispersystems.textsecuregcm.entities.ApnRegistrationId;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceActivationRequest;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceAttributes;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceInfo;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceInfoList;
|
||||
import org.whispersystems.textsecuregcm.entities.ECSignedPreKey;
|
||||
@@ -252,11 +252,11 @@ class DeviceControllerTest {
|
||||
|
||||
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||
|
||||
final AccountAttributes accountAttributes = new AccountAttributes(fetchesMessages, 1234, 5678, null,
|
||||
null, true, DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES);
|
||||
final DeviceAttributes deviceAttributes = new DeviceAttributes(fetchesMessages, 1234, 5678, null,
|
||||
DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES);
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
accountAttributes,
|
||||
deviceAttributes,
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, apnRegistrationId, gcmRegistrationId));
|
||||
|
||||
final LinkDeviceResponse response = resources.getJerseyTest()
|
||||
@@ -335,7 +335,7 @@ class DeviceControllerTest {
|
||||
}
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(false, 1234, 5678, null, null, true, requestCapabilities),
|
||||
new DeviceAttributes(false, 1234, 5678, null, requestCapabilities),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
final int expectedStatus =
|
||||
@@ -388,7 +388,7 @@ class DeviceControllerTest {
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(false, 1234, 5678, null, null, true, requestCapabilities),
|
||||
new DeviceAttributes(false, 1234, 5678, null, requestCapabilities),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -426,7 +426,7 @@ class DeviceControllerTest {
|
||||
when(account.getIdentityKey(IdentityType.PNI)).thenReturn(new IdentityKey(pniIdentityKeyPair.getPublicKey()));
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(false, 1234, 5678, null, null, true, null),
|
||||
new DeviceAttributes(false, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -468,11 +468,11 @@ class DeviceControllerTest {
|
||||
|
||||
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||
|
||||
final AccountAttributes accountAttributes = new AccountAttributes(true, 1234, 5678, null,
|
||||
null, true, DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES);
|
||||
final DeviceAttributes deviceAttributes = new DeviceAttributes(true, 1234, 5678, null,
|
||||
DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES);
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
accountAttributes,
|
||||
deviceAttributes,
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -513,7 +513,7 @@ class DeviceControllerTest {
|
||||
when(commands.get(anyString())).thenReturn("");
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(false, 1234, 5678, null, null, true, null),
|
||||
new DeviceAttributes(false, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -562,7 +562,7 @@ class DeviceControllerTest {
|
||||
when(account.getIdentityKey(IdentityType.PNI)).thenReturn(new IdentityKey(pniIdentityKeyPair.getPublicKey()));
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.token(),
|
||||
new AccountAttributes(fetchesMessages, 1234, 5678, null, null, true, null),
|
||||
new DeviceAttributes(fetchesMessages, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, apnRegistrationId, gcmRegistrationId));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -610,7 +610,7 @@ class DeviceControllerTest {
|
||||
when(account.getIdentityKey(IdentityType.PNI)).thenReturn(pniIdentityKey);
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest(deviceCode.token(),
|
||||
new AccountAttributes(true, 1234, 5678, null, null, true, null),
|
||||
new DeviceAttributes(true, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -670,7 +670,7 @@ class DeviceControllerTest {
|
||||
when(accountsManager.checkDeviceLinkingToken(anyString())).thenReturn(Optional.of(AuthHelper.VALID_UUID));
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(true, 1234, 5678, null, null, true, null),
|
||||
new DeviceAttributes(true, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -703,7 +703,7 @@ class DeviceControllerTest {
|
||||
when(accountsManager.checkDeviceLinkingToken(anyString())).thenReturn(Optional.of(AuthHelper.VALID_UUID));
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(true, 1234, 5678, null, null, true, null),
|
||||
new DeviceAttributes(true, 1234, 5678, null, null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.empty()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -762,7 +762,7 @@ class DeviceControllerTest {
|
||||
when(account.getIdentityKey(IdentityType.PNI)).thenReturn(new IdentityKey(pniIdentityKeyPair.getPublicKey()));
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(false, 1234, 5678, TestRandomUtil.nextBytes(512), null, true, null),
|
||||
new DeviceAttributes(false, 1234, 5678, TestRandomUtil.nextBytes(512), null),
|
||||
new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, Optional.empty(), Optional.of(new GcmRegistrationId("gcm-id"))));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -807,7 +807,7 @@ class DeviceControllerTest {
|
||||
when(asyncCommands.set(any(), any(), any())).thenReturn(MockRedisFuture.completedFuture(null));
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest("link-device-token",
|
||||
new AccountAttributes(false, registrationId, pniRegistrationId, null, null, true, DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES),
|
||||
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()));
|
||||
|
||||
try (final Response response = resources.getJerseyTest()
|
||||
@@ -1461,14 +1461,14 @@ class DeviceControllerTest {
|
||||
@NullSource
|
||||
@ValueSource(strings = {""})
|
||||
void linkDeviceMissingVerificationCode(final String verificationCode) {
|
||||
final AccountAttributes accountAttributes = new AccountAttributes(true, 1234, 5678, null,
|
||||
null, true, Set.of());
|
||||
final DeviceAttributes deviceAttributes = new DeviceAttributes(true, 1234, 5678, null,
|
||||
Set.of());
|
||||
|
||||
final ECKeyPair aciIdentityKeyPair = ECKeyPair.generate();
|
||||
final ECKeyPair pniIdentityKeyPair = ECKeyPair.generate();
|
||||
|
||||
final LinkDeviceRequest request = new LinkDeviceRequest(verificationCode,
|
||||
accountAttributes,
|
||||
deviceAttributes,
|
||||
new DeviceActivationRequest(
|
||||
KeysHelper.signedECPreKey(1, aciIdentityKeyPair),
|
||||
KeysHelper.signedECPreKey(2, pniIdentityKeyPair),
|
||||
|
||||
+3
-3
@@ -903,11 +903,11 @@ class RegistrationControllerTest {
|
||||
|
||||
final AccountAttributes fetchesMessagesAccountAttributes =
|
||||
new AccountAttributes(true, registrationId, pniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, deviceCapabilities)
|
||||
.withUnidentifiedAccessKey(TestRandomUtil.nextBytes(16));
|
||||
.setUnidentifiedAccessKey(TestRandomUtil.nextBytes(16));
|
||||
|
||||
final AccountAttributes pushAccountAttributes =
|
||||
new AccountAttributes(false, registrationId, pniRegistrationId, "test".getBytes(StandardCharsets.UTF_8), null, true, deviceCapabilities)
|
||||
.withUnidentifiedAccessKey(TestRandomUtil.nextBytes(16));
|
||||
.setUnidentifiedAccessKey(TestRandomUtil.nextBytes(16));
|
||||
|
||||
final String apnsToken = "apns-token";
|
||||
final String gcmToken = "gcm-token";
|
||||
@@ -1021,7 +1021,7 @@ class RegistrationControllerTest {
|
||||
final AccountAttributes accountAttributes = new AccountAttributes(true, registrationId, pniRegistrationId,
|
||||
"name".getBytes(StandardCharsets.UTF_8), REGLOCK,
|
||||
true, deviceCapabilities)
|
||||
.withUnidentifiedAccessKey(TestRandomUtil.nextBytes(16));
|
||||
.setUnidentifiedAccessKey(TestRandomUtil.nextBytes(16));
|
||||
|
||||
return new RegistrationRequest(
|
||||
Base64.getEncoder().encodeToString(sessionId.getBytes(StandardCharsets.UTF_8)),
|
||||
|
||||
+4
-1
@@ -16,6 +16,7 @@ import static org.mockito.Mockito.when;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -26,6 +27,7 @@ import org.mockito.stubbing.Stubbing;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair;
|
||||
import org.whispersystems.textsecuregcm.entities.AccountAttributes;
|
||||
import org.whispersystems.textsecuregcm.entities.DeviceAttributes;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
@@ -197,7 +199,8 @@ public class AccountsHelper {
|
||||
public static Account createAccount(final AccountsManager accountsManager, final String e164)
|
||||
throws InterruptedException {
|
||||
|
||||
return createAccount(accountsManager, e164, new AccountAttributes());
|
||||
return createAccount(accountsManager, e164, new AccountAttributes().setDeviceAttributes(
|
||||
new DeviceAttributes(false, 1, 1, new byte[0], Collections.emptySet())));
|
||||
}
|
||||
|
||||
public static Account createAccount(final AccountsManager accountsManager, final String e164, final AccountAttributes accountAttributes)
|
||||
|
||||
Reference in new issue
Block a user