From 5e1338a571b734dc1dcdd402d7b92dd6e7a203ed Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Sat, 11 Apr 2026 10:39:34 -0500 Subject: [PATCH] Factor out DeviceAttributes from AccountAttributes --- .../java/org/signal/integration/TestUser.java | 4 +- .../controllers/DeviceController.java | 14 ++--- .../entities/AccountAttributes.java | 63 ++++++------------- .../entities/DeviceAttributes.java | 46 ++++++++++++++ .../entities/LinkDeviceRequest.java | 9 +-- .../controllers/AccountControllerTest.java | 16 ++--- .../controllers/DeviceControllerTest.java | 40 ++++++------ .../RegistrationControllerTest.java | 6 +- .../tests/util/AccountsHelper.java | 5 +- 9 files changed, 115 insertions(+), 88 deletions(-) create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/entities/DeviceAttributes.java diff --git a/integration-tests/src/main/java/org/signal/integration/TestUser.java b/integration-tests/src/main/java/org/signal/integration/TestUser.java index 045b03e35..cf6853e06 100644 --- a/integration-tests/src/main/java/org/signal/integration/TestUser.java +++ b/integration-tests/src/main/java/org/signal/integration/TestUser.java @@ -130,8 +130,8 @@ public class TestUser { public AccountAttributes accountAttributes() { return new AccountAttributes(true, registrationId, pniRegistrationId, "".getBytes(StandardCharsets.UTF_8), "", true, DeviceCapability.CAPABILITIES_REQUIRED_FOR_NEW_DEVICES) - .withUnidentifiedAccessKey(unidentifiedAccessKey) - .withRecoveryPassword(registrationPassword); + .setUnidentifiedAccessKey(unidentifiedAccessKey) + .setRecoveryPassword(registrationPassword); } public void setAciUuid(final UUID aciUuid) { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java index 03c2c171b..9ed468073 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java @@ -50,8 +50,8 @@ import javax.annotation.Nullable; import org.whispersystems.textsecuregcm.auth.AuthenticatedDevice; import org.whispersystems.textsecuregcm.auth.BasicAuthorizationHeader; import org.whispersystems.textsecuregcm.auth.ChangesLinkedDevices; -import org.whispersystems.textsecuregcm.entities.AccountAttributes; 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.LinkDeviceRequest; @@ -241,7 +241,7 @@ public class DeviceController { .orElseThrow(ForbiddenException::new); final DeviceActivationRequest deviceActivationRequest = linkDeviceRequest.deviceActivationRequest(); - final AccountAttributes accountAttributes = linkDeviceRequest.accountAttributes(); + final DeviceAttributes deviceAttributes = linkDeviceRequest.deviceAttributes(); rateLimiters.getVerifyDeviceLimiter().validate(account.getUuid()); @@ -263,7 +263,7 @@ public class DeviceController { throw new DeviceLimitExceededException(account.getDevices().size(), MAX_DEVICES); } - final Set capabilities = accountAttributes.getCapabilities(); + final Set capabilities = deviceAttributes.capabilities(); if (capabilities == null) { throw new WebApplicationException(Response.status(422, "Missing device capabilities").build()); @@ -282,13 +282,13 @@ public class DeviceController { } try { - final Pair accountAndDevice = accounts.addDevice(account, new DeviceSpec(accountAttributes.getName(), + final Pair accountAndDevice = accounts.addDevice(account, new DeviceSpec(deviceAttributes.name(), authorizationHeader.getPassword(), signalAgent, capabilities, - accountAttributes.getRegistrationId(), - accountAttributes.getPhoneNumberIdentityRegistrationId(), - accountAttributes.getFetchesMessages(), + deviceAttributes.registrationId(), + deviceAttributes.phoneNumberIdentityRegistrationId(), + deviceAttributes.fetchesMessages(), deviceActivationRequest.apnToken(), deviceActivationRequest.gcmToken(), deviceActivationRequest.aciSignedPreKey(), diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountAttributes.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountAttributes.java index 19079505d..787ac9a37 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountAttributes.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/AccountAttributes.java @@ -4,40 +4,26 @@ */ package org.whispersystems.textsecuregcm.entities; -import static org.whispersystems.textsecuregcm.util.RegistrationIdValidator.validRegistrationId; - import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.google.common.annotations.VisibleForTesting; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; import jakarta.validation.constraints.AssertTrue; -import jakarta.validation.constraints.Size; import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; import org.whispersystems.textsecuregcm.auth.UnidentifiedAccessUtil; import org.whispersystems.textsecuregcm.storage.DeviceCapability; import org.whispersystems.textsecuregcm.util.ByteArrayAdapter; -import org.whispersystems.textsecuregcm.util.DeviceCapabilityAdapter; import org.whispersystems.textsecuregcm.util.ExactlySize; public class AccountAttributes { - @JsonProperty - private boolean fetchesMessages; - - @JsonProperty - private int registrationId; - - @JsonProperty("pniRegistrationId") - private int phoneNumberIdentityRegistrationId; - - @JsonProperty - @JsonSerialize(using = ByteArrayAdapter.Serializing.class) - @JsonDeserialize(using = ByteArrayAdapter.Deserializing.class) - @Size(max = 225) - private byte[] name; + @JsonUnwrapped + @Valid + private DeviceAttributes deviceAttributes; @JsonProperty @ExactlySize({0, 64}) @@ -50,12 +36,6 @@ public class AccountAttributes { @JsonProperty private boolean unrestrictedUnidentifiedAccess; - @JsonProperty - @JsonSerialize(using = DeviceCapabilityAdapter.Serializer.class) - @JsonDeserialize(using = DeviceCapabilityAdapter.Deserializer.class) - @Nullable - private Set capabilities; - @JsonProperty private boolean discoverableByPhoneNumber = true; @@ -77,29 +57,26 @@ public class AccountAttributes { final String registrationLock, final boolean discoverableByPhoneNumber, final Set capabilities) { - this.fetchesMessages = fetchesMessages; - this.registrationId = registrationId; - this.phoneNumberIdentityRegistrationId = phoneNumberIdentifierRegistrationId; - this.name = name; + + this.deviceAttributes = new DeviceAttributes(fetchesMessages, registrationId, phoneNumberIdentifierRegistrationId, name, capabilities); this.registrationLock = registrationLock; this.discoverableByPhoneNumber = discoverableByPhoneNumber; - this.capabilities = capabilities; } public boolean getFetchesMessages() { - return fetchesMessages; + return deviceAttributes.fetchesMessages(); } public int getRegistrationId() { - return registrationId; + return deviceAttributes.registrationId(); } public int getPhoneNumberIdentityRegistrationId() { - return phoneNumberIdentityRegistrationId; + return deviceAttributes.phoneNumberIdentityRegistrationId(); } public byte[] getName() { - return name; + return deviceAttributes.name(); } public String getRegistrationLock() { @@ -116,7 +93,7 @@ public class AccountAttributes { @Nullable public Set getCapabilities() { - return capabilities; + return deviceAttributes.capabilities(); } public boolean isDiscoverableByPhoneNumber() { @@ -128,27 +105,27 @@ public class AccountAttributes { } @VisibleForTesting - public AccountAttributes withUnidentifiedAccessKey(final byte[] unidentifiedAccessKey) { + public AccountAttributes setUnidentifiedAccessKey(final byte[] unidentifiedAccessKey) { this.unidentifiedAccessKey = unidentifiedAccessKey; return this; } @VisibleForTesting - public AccountAttributes withRecoveryPassword(final byte[] recoveryPassword) { + public AccountAttributes setRecoveryPassword(final byte[] recoveryPassword) { this.recoveryPassword = recoveryPassword; return this; } @VisibleForTesting - public AccountAttributes withUnrestrictedUnidentifiedAccess(final boolean unrestrictedUnidentifiedAccess) { - this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess; + public AccountAttributes setDeviceAttributes(final DeviceAttributes deviceAttributes) { + this.deviceAttributes = deviceAttributes; return this; } - @AssertTrue - @Schema(hidden = true) - public boolean isEachRegistrationIdValid() { - return validRegistrationId(registrationId) && validRegistrationId(phoneNumberIdentityRegistrationId); + @VisibleForTesting + public AccountAttributes setUnrestrictedUnidentifiedAccess(final boolean unrestrictedUnidentifiedAccess) { + this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess; + return this; } @AssertTrue diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/DeviceAttributes.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/DeviceAttributes.java new file mode 100644 index 000000000..15c84b53a --- /dev/null +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/DeviceAttributes.java @@ -0,0 +1,46 @@ +/* + * Copyright 2026 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.whispersystems.textsecuregcm.entities; + +import static org.whispersystems.textsecuregcm.util.RegistrationIdValidator.validRegistrationId; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.Size; +import java.util.Set; +import javax.annotation.Nullable; +import org.whispersystems.textsecuregcm.storage.DeviceCapability; +import org.whispersystems.textsecuregcm.util.ByteArrayAdapter; +import org.whispersystems.textsecuregcm.util.DeviceCapabilityAdapter; + +public record DeviceAttributes( + boolean fetchesMessages, + + int registrationId, + + @JsonProperty("pniRegistrationId") int phoneNumberIdentityRegistrationId, + + @JsonSerialize(using = ByteArrayAdapter.Serializing.class) + + @JsonDeserialize(using = ByteArrayAdapter.Deserializing.class) + @Size(max = 225) + byte[] name, + + @JsonSerialize(using = DeviceCapabilityAdapter.Serializer.class) + + @JsonDeserialize(using = DeviceCapabilityAdapter.Deserializer.class) + @Nullable + Set capabilities) { + + @AssertTrue + @Schema(hidden = true) + public boolean isEachRegistrationIdValid() { + return validRegistrationId(registrationId) && validRegistrationId(phoneNumberIdentityRegistrationId); + } +} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/entities/LinkDeviceRequest.java b/service/src/main/java/org/whispersystems/textsecuregcm/entities/LinkDeviceRequest.java index c7a6081e2..0a5fe4c69 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/entities/LinkDeviceRequest.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/entities/LinkDeviceRequest.java @@ -19,7 +19,8 @@ public record LinkDeviceRequest(@Schema(requiredMode = Schema.RequiredMode.REQUI @NotNull @Valid - AccountAttributes accountAttributes, + @JsonProperty("accountAttributes") + DeviceAttributes deviceAttributes, @NotNull @Valid @@ -30,7 +31,7 @@ public record LinkDeviceRequest(@Schema(requiredMode = Schema.RequiredMode.REQUI @JsonCreator @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public LinkDeviceRequest(@JsonProperty("verificationCode") String verificationCode, - @JsonProperty("accountAttributes") AccountAttributes accountAttributes, + @JsonProperty("accountAttributes") DeviceAttributes deviceAttributes, @JsonProperty("aciSignedPreKey") @NotNull @Valid ECSignedPreKey aciSignedPreKey, @JsonProperty("pniSignedPreKey") @NotNull @Valid ECSignedPreKey pniSignedPreKey, @JsonProperty("aciPqLastResortPreKey") @NotNull @Valid KEMSignedPreKey aciPqLastResortPreKey, @@ -38,14 +39,14 @@ public record LinkDeviceRequest(@Schema(requiredMode = Schema.RequiredMode.REQUI @JsonProperty("apnToken") Optional<@Valid ApnRegistrationId> apnToken, @JsonProperty("gcmToken") Optional<@Valid GcmRegistrationId> gcmToken) { - this(verificationCode, accountAttributes, + this(verificationCode, deviceAttributes, new DeviceActivationRequest(aciSignedPreKey, pniSignedPreKey, aciPqLastResortPreKey, pniPqLastResortPreKey, apnToken, gcmToken)); } @AssertTrue @Schema(hidden = true) public boolean isExactlyOneMessageDeliveryChannel() { - if (accountAttributes != null && accountAttributes.getFetchesMessages()) { + if (deviceAttributes != null && deviceAttributes.fetchesMessages()) { return deviceActivationRequest().apnToken().isEmpty() && deviceActivationRequest().gcmToken().isEmpty(); } else { return deviceActivationRequest().apnToken().isPresent() ^ deviceActivationRequest().gcmToken().isPresent(); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java index ea212d91a..d04a087a9 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/AccountControllerTest.java @@ -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); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DeviceControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DeviceControllerTest.java index 7c0692452..765e11b4e 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DeviceControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DeviceControllerTest.java @@ -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), diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java index f54d8891f..ebf26a7f5 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java @@ -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)), diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java index dbdc9b028..92318c099 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AccountsHelper.java @@ -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)