From f0ab52eb5d503c9a337ce5257201e2c214d5a19c Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Thu, 19 Oct 2023 10:08:00 -0400 Subject: [PATCH] Rename "master device" to "primary device" --- .../org/signal/integration/Operations.java | 6 +- .../java/org/signal/integration/TestUser.java | 2 +- .../org/signal/integration/MessagingTest.java | 2 +- .../auth/BaseAccountAuthenticator.java | 6 +- .../auth/grpc/AuthenticationUtil.java | 2 +- .../controllers/AccountControllerV2.java | 4 +- .../controllers/DeviceController.java | 6 +- .../controllers/KeysController.java | 2 +- .../controllers/MessageController.java | 4 +- .../controllers/RegistrationController.java | 10 +-- .../grpc/DevicesGrpcService.java | 4 +- .../limits/PushChallengeManager.java | 12 +-- .../push/PushNotificationManager.java | 4 +- .../textsecuregcm/storage/Account.java | 10 +-- .../storage/AccountsManager.java | 6 +- .../storage/ChangeNumberManager.java | 6 +- .../textsecuregcm/storage/Device.java | 10 +-- .../websocket/WebSocketConnection.java | 2 +- .../workers/UnlinkDeviceCommand.java | 2 +- ...blementRefreshRequirementProviderTest.java | 20 ++--- .../auth/BaseAccountAuthenticatorTest.java | 6 +- .../auth/BasicAuthorizationHeaderTest.java | 2 +- ...rChangeRefreshRequirementProviderTest.java | 4 +- ...gistrationLockVerificationManagerTest.java | 8 +- ...edentialAuthenticationInterceptorTest.java | 2 +- .../controllers/DeviceControllerTest.java | 24 +++--- .../controllers/KeysControllerTest.java | 4 +- .../RegistrationControllerTest.java | 10 +-- .../entities/OutgoingMessageEntityTest.java | 2 +- .../grpc/DevicesGrpcServiceTest.java | 38 ++++----- .../grpc/KeysAnonymousGrpcServiceTest.java | 14 ++-- .../grpc/SimpleBaseGrpcTest.java | 2 +- .../push/PushNotificationManagerTest.java | 46 +++++------ .../redis/RedisClusterExtension.java | 2 +- .../textsecuregcm/storage/AccountTest.java | 82 +++++++++---------- ...ntsManagerChangeNumberIntegrationTest.java | 12 +-- ...ConcurrentModificationIntegrationTest.java | 4 +- .../storage/AccountsManagerTest.java | 6 +- .../storage/ChangeNumberManagerTest.java | 10 +-- .../textsecuregcm/storage/DeviceTest.java | 6 +- .../tests/util/AccountsHelper.java | 2 +- .../textsecuregcm/tests/util/AuthHelper.java | 28 +++---- .../util/DestinationDeviceValidatorTest.java | 26 +++--- 43 files changed, 230 insertions(+), 230 deletions(-) diff --git a/integration-tests/src/main/java/org/signal/integration/Operations.java b/integration-tests/src/main/java/org/signal/integration/Operations.java index 88c037bea..e631bfd40 100644 --- a/integration-tests/src/main/java/org/signal/integration/Operations.java +++ b/integration-tests/src/main/java/org/signal/integration/Operations.java @@ -88,9 +88,9 @@ public final class Operations { user.setPniUuid(registrationResponse.pni()); // upload pre-key - final TestUser.PreKeySetPublicView preKeySetPublicView = user.preKeys(Device.MASTER_ID, false); + final TestUser.PreKeySetPublicView preKeySetPublicView = user.preKeys(Device.PRIMARY_ID, false); apiPut("/v2/keys", preKeySetPublicView) - .authorized(user, Device.MASTER_ID) + .authorized(user, Device.PRIMARY_ID) .executeExpectSuccess(); return user; @@ -233,7 +233,7 @@ public final class Operations { } public RequestBuilder authorized(final TestUser user) { - return authorized(user, Device.MASTER_ID); + return authorized(user, Device.PRIMARY_ID); } public RequestBuilder authorized(final TestUser user, final long deviceId) { 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 8925ba5b5..2b71a79ff 100644 --- a/integration-tests/src/main/java/org/signal/integration/TestUser.java +++ b/integration-tests/src/main/java/org/signal/integration/TestUser.java @@ -82,7 +82,7 @@ public class TestUser { this.unidentifiedAccessKey = unidentifiedAccessKey; this.accountPassword = accountPassword; this.registrationPassword = registrationPassword; - devices.put(Device.MASTER_ID, TestDevice.create(Device.MASTER_ID, aciIdentityKey, pniIdentityKey)); + devices.put(Device.PRIMARY_ID, TestDevice.create(Device.PRIMARY_ID, aciIdentityKey, pniIdentityKey)); } public int registrationId() { diff --git a/integration-tests/src/test/java/org/signal/integration/MessagingTest.java b/integration-tests/src/test/java/org/signal/integration/MessagingTest.java index 634e55066..cf2af5e14 100644 --- a/integration-tests/src/test/java/org/signal/integration/MessagingTest.java +++ b/integration-tests/src/test/java/org/signal/integration/MessagingTest.java @@ -38,7 +38,7 @@ public class MessagingTest { try { final byte[] expectedContent = "Hello, World!".getBytes(StandardCharsets.UTF_8); final String contentBase64 = Base64.getEncoder().encodeToString(expectedContent); - final IncomingMessage message = new IncomingMessage(1, Device.MASTER_ID, userB.registrationId(), contentBase64); + final IncomingMessage message = new IncomingMessage(1, Device.PRIMARY_ID, userB.registrationId(), contentBase64); final IncomingMessageList messages = new IncomingMessageList(List.of(message), false, true, System.currentTimeMillis()); final Pair sendMessage = Operations diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java index be4ee98a5..d1def356d 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java @@ -60,7 +60,7 @@ public class BaseAccountAuthenticator { if (deviceIdSeparatorIndex == -1) { identifier = basicUsername; - deviceId = Device.MASTER_ID; + deviceId = Device.PRIMARY_ID; } else { identifier = basicUsername.substring(0, deviceIdSeparatorIndex); deviceId = Long.parseLong(basicUsername.substring(deviceIdSeparatorIndex + 1)); @@ -113,7 +113,7 @@ public class BaseAccountAuthenticator { } else { Metrics.counter(ENABLED_NOT_REQUIRED_AUTHENTICATION_COUNTER_NAME, ENABLED_TAG_NAME, String.valueOf(device.get().isEnabled() && account.get().isEnabled()), - IS_PRIMARY_DEVICE_TAG, String.valueOf(device.get().isMaster())) + IS_PRIMARY_DEVICE_TAG, String.valueOf(device.get().isPrimary())) .increment(); } @@ -162,7 +162,7 @@ public class BaseAccountAuthenticator { // (1) each account will only update last-seen at most once per day // (2) these updates will occur throughout the day rather than all occurring at UTC midnight. if (device.getLastSeen() < todayInMillisWithOffset) { - Metrics.summary(DAYS_SINCE_LAST_SEEN_DISTRIBUTION_NAME, IS_PRIMARY_DEVICE_TAG, String.valueOf(device.isMaster())) + Metrics.summary(DAYS_SINCE_LAST_SEEN_DISTRIBUTION_NAME, IS_PRIMARY_DEVICE_TAG, String.valueOf(device.isPrimary())) .record(Duration.ofMillis(todayInMillisWithOffset - device.getLastSeen()).toDays()); return accountsManager.updateDeviceLastSeen(account, device, Util.todayInMillis(clock)); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/AuthenticationUtil.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/AuthenticationUtil.java index 424b1ab2e..68c57552a 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/AuthenticationUtil.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/AuthenticationUtil.java @@ -53,7 +53,7 @@ public class AuthenticationUtil { public static AuthenticatedDevice requireAuthenticatedPrimaryDevice() { final AuthenticatedDevice authenticatedDevice = requireAuthenticatedDevice(); - if (authenticatedDevice.deviceId() != Device.MASTER_ID) { + if (authenticatedDevice.deviceId() != Device.PRIMARY_ID) { throw Status.PERMISSION_DENIED.asRuntimeException(); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java index 6051f81ce..350e3950f 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountControllerV2.java @@ -94,7 +94,7 @@ public class AccountControllerV2 { @NotNull @Valid final ChangeNumberRequest request, @HeaderParam(HttpHeaders.USER_AGENT) final String userAgent) throws RateLimitExceededException, InterruptedException { - if (!authenticatedAccount.getAuthenticatedDevice().isMaster()) { + if (!authenticatedAccount.getAuthenticatedDevice().isPrimary()) { throw new ForbiddenException(); } @@ -170,7 +170,7 @@ public class AccountControllerV2 { public AccountIdentityResponse distributePhoneNumberIdentityKeys(@Auth final AuthenticatedAccount authenticatedAccount, @NotNull @Valid final PhoneNumberIdentityKeyDistributionRequest request) { - if (!authenticatedAccount.getAuthenticatedDevice().isMaster()) { + if (!authenticatedAccount.getAuthenticatedDevice().isPrimary()) { throw new ForbiddenException(); } 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 e0c424fe5..41b44c209 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/DeviceController.java @@ -137,11 +137,11 @@ public class DeviceController { @ChangesDeviceEnabledState public void removeDevice(@Auth AuthenticatedAccount auth, @PathParam("device_id") long deviceId) { Account account = auth.getAccount(); - if (auth.getAuthenticatedDevice().getId() != Device.MASTER_ID) { + if (auth.getAuthenticatedDevice().getId() != Device.PRIMARY_ID) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } - if (deviceId == Device.MASTER_ID) { + if (deviceId == Device.PRIMARY_ID) { throw new ForbiddenException(); } @@ -175,7 +175,7 @@ public class DeviceController { throw new DeviceLimitExceededException(account.getDevices().size(), MAX_DEVICES); } - if (auth.getAuthenticatedDevice().getId() != Device.MASTER_ID) { + if (auth.getAuthenticatedDevice().getId() != Device.PRIMARY_ID) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java index 11a2f4bb4..31a407ad3 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/KeysController.java @@ -154,7 +154,7 @@ public class KeysController { .and(HAS_IDENTITY_KEY_TAG_NAME, String.valueOf(hasIdentityKey)) .and(IDENTITY_TYPE_TAG_NAME, usePhoneNumberIdentity ? "pni" : "aci"); - if (!device.isMaster()) { + if (!device.isPrimary()) { Metrics.counter(IDENTITY_KEY_CHANGE_FORBIDDEN_COUNTER_NAME, tags).increment(); throw new ForbiddenException(); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java index 0136b4fbe..060c9c377 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java @@ -693,7 +693,7 @@ public class MessageController { messageSender.sendMessage(destinationAccount, destinationDevice, envelope, online); } catch (NotPushRegisteredException e) { - if (destinationDevice.isMaster()) throw new NoSuchUserException(e); + if (destinationDevice.isPrimary()) throw new NoSuchUserException(e); else logger.debug("Not registered", e); } } @@ -727,7 +727,7 @@ public class MessageController { messageSender.sendMessage(destinationAccount, destinationDevice, messageBuilder.build(), online); } catch (NotPushRegisteredException e) { - if (destinationDevice.isMaster()) { + if (destinationDevice.isPrimary()) { throw new NoSuchUserException(e); } else { logger.debug("Not registered", e); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java index 0ef2eb5e6..4ab1a3bce 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/RegistrationController.java @@ -158,7 +158,7 @@ public class RegistrationController { a.setIdentityKey(registrationRequest.aciIdentityKey().get()); a.setPhoneNumberIdentityKey(registrationRequest.pniIdentityKey().get()); - final Device device = a.getMasterDevice().orElseThrow(); + final Device device = a.getPrimaryDevice().orElseThrow(); device.setSignedPreKey(registrationRequest.deviceActivationRequest().aciSignedPreKey().get()); device.setPhoneNumberIdentitySignedPreKey(registrationRequest.deviceActivationRequest().pniSignedPreKey().get()); @@ -173,13 +173,13 @@ public class RegistrationController { CompletableFuture.allOf( keysManager.storeEcSignedPreKeys(a.getUuid(), - Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().aciSignedPreKey().get())), + Map.of(Device.PRIMARY_ID, registrationRequest.deviceActivationRequest().aciSignedPreKey().get())), keysManager.storePqLastResort(a.getUuid(), - Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().aciPqLastResortPreKey().get())), + Map.of(Device.PRIMARY_ID, registrationRequest.deviceActivationRequest().aciPqLastResortPreKey().get())), keysManager.storeEcSignedPreKeys(a.getPhoneNumberIdentifier(), - Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().pniSignedPreKey().get())), + Map.of(Device.PRIMARY_ID, registrationRequest.deviceActivationRequest().pniSignedPreKey().get())), keysManager.storePqLastResort(a.getPhoneNumberIdentifier(), - Map.of(Device.MASTER_ID, registrationRequest.deviceActivationRequest().pniPqLastResortPreKey().get()))) + Map.of(Device.PRIMARY_ID, registrationRequest.deviceActivationRequest().pniPqLastResortPreKey().get()))) .join(); }); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcService.java b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcService.java index aa3d0250c..449cf9426 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcService.java @@ -75,7 +75,7 @@ public class DevicesGrpcService extends ReactorDevicesGrpc.DevicesImplBase { @Override public Mono removeDevice(final RemoveDeviceRequest request) { - if (request.getId() == Device.MASTER_ID) { + if (request.getId() == Device.PRIMARY_ID) { throw Status.INVALID_ARGUMENT.withDescription("Cannot remove primary device").asRuntimeException(); } @@ -181,7 +181,7 @@ public class DevicesGrpcService extends ReactorDevicesGrpc.DevicesImplBase { .map(maybeAccount -> maybeAccount.orElseThrow(Status.UNAUTHENTICATED::asRuntimeException)) .flatMap(account -> Mono.fromFuture(() -> accountsManager.updateDeviceAsync(account, authenticatedDevice.deviceId(), device -> { if (StringUtils.isNotBlank(device.getApnId()) || StringUtils.isNotBlank(device.getVoipApnId())) { - device.setUserAgent(device.isMaster() ? "OWI" : "OWP"); + device.setUserAgent(device.isPrimary() ? "OWI" : "OWP"); } else if (StringUtils.isNotBlank(device.getGcmId())) { device.setUserAgent("OWA"); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/limits/PushChallengeManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/limits/PushChallengeManager.java index 4ec20570d..6443ce180 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/limits/PushChallengeManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/limits/PushChallengeManager.java @@ -45,7 +45,7 @@ public class PushChallengeManager { } public void sendChallenge(final Account account) throws NotPushRegisteredException { - final Device masterDevice = account.getMasterDevice().orElseThrow(NotPushRegisteredException::new); + final Device primaryDevice = account.getPrimaryDevice().orElseThrow(NotPushRegisteredException::new); final byte[] token = new byte[CHALLENGE_TOKEN_LENGTH]; random.nextBytes(token); @@ -58,9 +58,9 @@ public class PushChallengeManager { sent = true; - if (StringUtils.isNotBlank(masterDevice.getGcmId())) { + if (StringUtils.isNotBlank(primaryDevice.getGcmId())) { platform = ClientPlatform.ANDROID.name().toLowerCase(); - } else if (StringUtils.isNotBlank(masterDevice.getApnId())) { + } else if (StringUtils.isNotBlank(primaryDevice.getApnId())) { platform = ClientPlatform.IOS.name().toLowerCase(); } else { // This should never happen; if the account has neither an APN nor FCM token, sending the challenge will result @@ -86,10 +86,10 @@ public class PushChallengeManager { } catch (final IllegalArgumentException ignored) { } - final String platform = account.getMasterDevice().map(masterDevice -> { - if (StringUtils.isNotBlank(masterDevice.getGcmId())) { + final String platform = account.getPrimaryDevice().map(primaryDevice -> { + if (StringUtils.isNotBlank(primaryDevice.getGcmId())) { return ClientPlatform.IOS.name().toLowerCase(); - } else if (StringUtils.isNotBlank(masterDevice.getApnId())) { + } else if (StringUtils.isNotBlank(primaryDevice.getApnId())) { return ClientPlatform.ANDROID.name().toLowerCase(); } else { return "unknown"; diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java index 8fdb6171c..8d48e5189 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java @@ -62,7 +62,7 @@ public class PushNotificationManager { public void sendRateLimitChallengeNotification(final Account destination, final String challengeToken) throws NotPushRegisteredException { - final Device device = destination.getDevice(Device.MASTER_ID).orElseThrow(NotPushRegisteredException::new); + final Device device = destination.getDevice(Device.PRIMARY_ID).orElseThrow(NotPushRegisteredException::new); final Pair tokenAndType = getToken(device); sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(), @@ -70,7 +70,7 @@ public class PushNotificationManager { } public void sendAttemptLoginNotification(final Account destination, final String context) throws NotPushRegisteredException { - final Device device = destination.getDevice(Device.MASTER_ID).orElseThrow(NotPushRegisteredException::new); + final Device device = destination.getDevice(Device.PRIMARY_ID).orElseThrow(NotPushRegisteredException::new); final Pair tokenAndType = getToken(device); sendNotification(new PushNotification(tokenAndType.first(), tokenAndType.second(), diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java index 38d8f9ddf..0686307b1 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Account.java @@ -232,10 +232,10 @@ public class Account { return devices; } - public Optional getMasterDevice() { + public Optional getPrimaryDevice() { requireNotStale(); - return getDevice(Device.MASTER_ID); + return getDevice(Device.PRIMARY_ID); } public Optional getDevice(final long deviceId) { @@ -253,7 +253,7 @@ public class Account { public boolean isTransferSupported() { requireNotStale(); - return getMasterDevice().map(Device::getCapabilities).map(Device.DeviceCapabilities::transfer).orElse(false); + return getPrimaryDevice().map(Device::getCapabilities).map(Device.DeviceCapabilities::transfer).orElse(false); } public boolean isPniSupported() { @@ -275,13 +275,13 @@ public class Account { public boolean isEnabled() { requireNotStale(); - return getMasterDevice().map(Device::isEnabled).orElse(false); + return getPrimaryDevice().map(Device::isEnabled).orElse(false); } public long getNextDeviceId() { requireNotStale(); - long candidateId = Device.MASTER_ID + 1; + long candidateId = Device.PRIMARY_ID + 1; while (getDevice(candidateId).isPresent()) { candidateId++; diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java index 1536c74b8..427dfbc56 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountsManager.java @@ -186,7 +186,7 @@ public class AccountsManager { accountLockManager.withLock(List.of(number), () -> { Device device = new Device(); - device.setId(Device.MASTER_ID); + device.setId(Device.PRIMARY_ID); device.setAuthTokenHash(SaltedTokenHash.generateFor(password)); device.setFetchesMessages(accountAttributes.getFetchesMessages()); device.setRegistrationId(accountAttributes.getRegistrationId()); @@ -423,13 +423,13 @@ public class AccountsManager { throw new IllegalArgumentException("Signed pre-keys and registration IDs must both be null or both be non-null"); } - // Check that all including master ID are in signed pre-keys + // Check that all including primary ID are in signed pre-keys DestinationDeviceValidator.validateCompleteDeviceList( account, pniSignedPreKeys.keySet(), Collections.emptySet()); - // Check that all including master ID are in Pq pre-keys + // Check that all including primary ID are in Pq pre-keys if (pniPqLastResortPreKeys != null) { DestinationDeviceValidator.validateCompleteDeviceList( account, diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManager.java index d16ab858a..d5e8a3549 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManager.java @@ -100,11 +100,11 @@ public class ChangeNumberManager { private void validateDeviceMessages(final Account account, final List deviceMessages) throws MismatchedDevicesException, StaleDevicesException { - // Check that all except master ID are in device messages + // Check that all except primary ID are in device messages DestinationDeviceValidator.validateCompleteDeviceList( account, deviceMessages.stream().map(IncomingMessage::destinationDeviceId).collect(Collectors.toSet()), - Set.of(Device.MASTER_ID)); + Set.of(Device.PRIMARY_ID)); // check that all sync messages are to the current registration ID for the matching device DestinationDeviceValidator.validateRegistrationIds( @@ -140,7 +140,7 @@ public class ChangeNumberManager { .setDestinationUuid(new AciServiceIdentifier(sourceAndDestinationAccount.getUuid()).toServiceIdentifierString()) .setContent(ByteString.copyFrom(contents.get())) .setSourceUuid(new AciServiceIdentifier(sourceAndDestinationAccount.getUuid()).toServiceIdentifierString()) - .setSourceDevice((int) Device.MASTER_ID) + .setSourceDevice((int) Device.PRIMARY_ID) .setUpdatedPni(sourceAndDestinationAccount.getPhoneNumberIdentifier().toString()) .setUrgent(true) .build(); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java index dbad027c9..06b61a719 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/Device.java @@ -19,7 +19,7 @@ import org.whispersystems.textsecuregcm.util.Util; public class Device { - public static final long MASTER_ID = 1; + public static final long PRIMARY_ID = 1; public static final int MAXIMUM_DEVICE_ID = 256; public static final int MAX_REGISTRATION_ID = 0x3FFF; public static final List ALL_POSSIBLE_DEVICE_IDS = LongStream.range(1, MAXIMUM_DEVICE_ID).boxed().collect(Collectors.toList()); @@ -199,8 +199,8 @@ public class Device { public boolean isEnabled() { boolean hasChannel = fetchesMessages || !Util.isEmpty(getApnId()) || !Util.isEmpty(getGcmId()); - return (id == MASTER_ID && hasChannel && signedPreKey != null) || - (id != MASTER_ID && hasChannel && signedPreKey != null && lastSeen > (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30))); + return (id == PRIMARY_ID && hasChannel && signedPreKey != null) || + (id != PRIMARY_ID && hasChannel && signedPreKey != null && lastSeen > (System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30))); } public boolean getFetchesMessages() { @@ -211,8 +211,8 @@ public class Device { this.fetchesMessages = fetchesMessages; } - public boolean isMaster() { - return getId() == MASTER_ID; + public boolean isPrimary() { + return getId() == PRIMARY_ID; } public int getRegistrationId() { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java b/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java index e81a1446a..57da2415d 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java @@ -256,7 +256,7 @@ public class WebSocketConnection implements MessageAvailabilityListener, Displac public static void recordMessageDeliveryDuration(long timestamp, Device messageDestinationDevice) { final long messageDeliveryDuration = System.currentTimeMillis() - timestamp; messageTime.update(messageDeliveryDuration); - if (messageDestinationDevice.isMaster()) { + if (messageDestinationDevice.isPrimary()) { primaryDeviceMessageTime.update(messageDeliveryDuration); } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/UnlinkDeviceCommand.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/UnlinkDeviceCommand.java index 045465cb1..814001764 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/UnlinkDeviceCommand.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/workers/UnlinkDeviceCommand.java @@ -64,7 +64,7 @@ public class UnlinkDeviceCommand extends EnvironmentCommand new IllegalArgumentException("account id " + aci + " does not exist")); - if (deviceIds.contains(Device.MASTER_ID)) { + if (deviceIds.contains(Device.PRIMARY_ID)) { throw new IllegalArgumentException("cannot delete primary device"); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/AuthEnablementRefreshRequirementProviderTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/AuthEnablementRefreshRequirementProviderTest.java index 617eea77e..3c8be9118 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/AuthEnablementRefreshRequirementProviderTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/AuthEnablementRefreshRequirementProviderTest.java @@ -171,7 +171,7 @@ class AuthEnablementRefreshRequirementProviderTest { void testDeviceEnabledChanged(final Map initialEnabled, final Map finalEnabled) { assert initialEnabled.size() == finalEnabled.size(); - assert account.getMasterDevice().orElseThrow().isEnabled(); + assert account.getPrimaryDevice().orElseThrow().isEnabled(); initialEnabled.forEach((deviceId, enabled) -> DevicesHelper.setEnabled(account.getDevice(deviceId).orElseThrow(), enabled)); @@ -211,7 +211,7 @@ class AuthEnablementRefreshRequirementProviderTest { @Test void testDeviceAdded() { - assert account.getMasterDevice().orElseThrow().isEnabled(); + assert account.getPrimaryDevice().orElseThrow().isEnabled(); final int initialDeviceCount = account.getDevices().size(); @@ -235,7 +235,7 @@ class AuthEnablementRefreshRequirementProviderTest { @ParameterizedTest @ValueSource(ints = {1, 2}) void testDeviceRemoved(final int removedDeviceCount) { - assert account.getMasterDevice().orElseThrow().isEnabled(); + assert account.getPrimaryDevice().orElseThrow().isEnabled(); final List initialDeviceIds = account.getDevices().stream().map(Device::getId).collect(Collectors.toList()); @@ -266,8 +266,8 @@ class AuthEnablementRefreshRequirementProviderTest { } @Test - void testMasterDeviceDisabledAndDeviceRemoved() { - assert account.getMasterDevice().orElseThrow().isEnabled(); + void testPrimaryDeviceDisabledAndDeviceRemoved() { + assert account.getPrimaryDevice().orElseThrow().isEnabled(); final Set initialDeviceIds = account.getDevices().stream().map(Device::getId).collect(Collectors.toSet()); @@ -275,7 +275,7 @@ class AuthEnablementRefreshRequirementProviderTest { assertTrue(initialDeviceIds.remove(deletedDeviceId)); final Response response = resources.getJerseyTest() - .target("/v1/test/account/disableMasterDeviceAndDeleteDevice/" + deletedDeviceId) + .target("/v1/test/account/disablePrimaryDeviceAndDeleteDevice/" + deletedDeviceId) .request() .header("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:pass".getBytes(StandardCharsets.UTF_8))) @@ -415,7 +415,7 @@ class AuthEnablementRefreshRequirementProviderTest { @ChangesDeviceEnabledState public String setAccountEnabled(@Auth TestPrincipal principal, @PathParam("enabled") final boolean enabled) { - final Device device = principal.getAccount().getMasterDevice().orElseThrow(); + final Device device = principal.getAccount().getPrimaryDevice().orElseThrow(); DevicesHelper.setEnabled(device, enabled); @@ -469,11 +469,11 @@ class AuthEnablementRefreshRequirementProviderTest { } @POST - @Path("/account/disableMasterDeviceAndDeleteDevice/{deviceId}") + @Path("/account/disablePrimaryDeviceAndDeleteDevice/{deviceId}") @ChangesDeviceEnabledState - public String disableMasterDeviceAndRemoveDevice(@Auth TestPrincipal auth, @PathParam("deviceId") long deviceId) { + public String disablePrimaryDeviceAndRemoveDevice(@Auth TestPrincipal auth, @PathParam("deviceId") long deviceId) { - DevicesHelper.setEnabled(auth.getAccount().getMasterDevice().orElseThrow(), false); + DevicesHelper.setEnabled(auth.getAccount().getPrimaryDevice().orElseThrow(), false); auth.getAccount().removeDevice(deviceId); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticatorTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticatorTest.java index fb9a2e8c2..431296573 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticatorTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticatorTest.java @@ -68,7 +68,7 @@ class BaseAccountAuthenticatorTest { private static Device generateTestDevice(final long lastSeen) { final Device device = new Device(); - device.setId(Device.MASTER_ID); + device.setId(Device.PRIMARY_ID); device.setLastSeen(lastSeen); return device; @@ -374,8 +374,8 @@ class BaseAccountAuthenticatorTest { private static Stream testGetIdentifierAndDeviceId() { return Stream.of( - Arguments.of("", "", Device.MASTER_ID), - Arguments.of("test", "test", Device.MASTER_ID), + Arguments.of("", "", Device.PRIMARY_ID), + Arguments.of("test", "test", Device.PRIMARY_ID), Arguments.of("test.7", "test", 7)); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/BasicAuthorizationHeaderTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/BasicAuthorizationHeaderTest.java index ddee28320..241e0d19a 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/BasicAuthorizationHeaderTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/BasicAuthorizationHeaderTest.java @@ -26,7 +26,7 @@ class BasicAuthorizationHeaderTest { assertEquals("aladdin", header.getUsername()); assertEquals("opensesame", header.getPassword()); - assertEquals(Device.MASTER_ID, header.getDeviceId()); + assertEquals(Device.PRIMARY_ID, header.getDeviceId()); } { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneNumberChangeRefreshRequirementProviderTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneNumberChangeRefreshRequirementProviderTest.java index 5e04da700..2341c5ee6 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneNumberChangeRefreshRequirementProviderTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/PhoneNumberChangeRefreshRequirementProviderTest.java @@ -49,7 +49,7 @@ class PhoneNumberChangeRefreshRequirementProviderTest { when(account.getUuid()).thenReturn(ACCOUNT_UUID); when(account.getNumber()).thenReturn(NUMBER); when(account.getDevices()).thenReturn(List.of(device)); - when(device.getId()).thenReturn(Device.MASTER_ID); + when(device.getId()).thenReturn(Device.PRIMARY_ID); request = mock(ContainerRequest.class); @@ -81,7 +81,7 @@ class PhoneNumberChangeRefreshRequirementProviderTest { provider.handleRequestFiltered(requestEvent); when(account.getNumber()).thenReturn(CHANGED_NUMBER); - assertEquals(List.of(new Pair<>(ACCOUNT_UUID, Device.MASTER_ID)), provider.handleRequestFinished(requestEvent)); + assertEquals(List.of(new Pair<>(ACCOUNT_UUID, Device.PRIMARY_ID)), provider.handleRequestFinished(requestEvent)); } @Test diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java index 44e3b66e2..ed67c07e1 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/RegistrationLockVerificationManagerTest.java @@ -69,7 +69,7 @@ class RegistrationLockVerificationManagerTest { .thenReturn(mock(ExternalServiceCredentials.class)); final Device device = mock(Device.class); - when(device.getId()).thenReturn(Device.MASTER_ID); + when(device.getId()).thenReturn(Device.PRIMARY_ID); AccountsHelper.setupMockUpdate(accountsManager); @@ -104,7 +104,7 @@ class RegistrationLockVerificationManagerTest { } else { verify(registrationRecoveryPasswordsManager, never()).removeForNumber(account.getNumber()); } - verify(clientPresenceManager).disconnectAllPresences(account.getUuid(), List.of(Device.MASTER_ID)); + verify(clientPresenceManager).disconnectAllPresences(account.getUuid(), List.of(Device.PRIMARY_ID)); try { verify(pushNotificationManager).sendAttemptLoginNotification(any(), eq("failedRegistrationLock")); } catch (NotPushRegisteredException npre) {} @@ -127,7 +127,7 @@ class RegistrationLockVerificationManagerTest { verify(pushNotificationManager, never()).sendAttemptLoginNotification(any(), eq("failedRegistrationLock")); } catch (NotPushRegisteredException npre) {} verify(registrationRecoveryPasswordsManager, never()).removeForNumber(account.getNumber()); - verify(clientPresenceManager, never()).disconnectAllPresences(account.getUuid(), List.of(Device.MASTER_ID)); + verify(clientPresenceManager, never()).disconnectAllPresences(account.getUuid(), List.of(Device.PRIMARY_ID)); }); } }; @@ -165,7 +165,7 @@ class RegistrationLockVerificationManagerTest { verify(account, never()).lockAuthTokenHash(); verify(registrationRecoveryPasswordsManager, never()).removeForNumber(account.getNumber()); - verify(clientPresenceManager, never()).disconnectAllPresences(account.getUuid(), List.of(Device.MASTER_ID)); + verify(clientPresenceManager, never()).disconnectAllPresences(account.getUuid(), List.of(Device.PRIMARY_ID)); } static Stream testSuccess() { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/auth/grpc/BasicCredentialAuthenticationInterceptorTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/auth/grpc/BasicCredentialAuthenticationInterceptorTest.java index 16eadcd35..c064c1586 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/auth/grpc/BasicCredentialAuthenticationInterceptorTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/auth/grpc/BasicCredentialAuthenticationInterceptorTest.java @@ -85,7 +85,7 @@ class BasicCredentialAuthenticationInterceptorTest { when(account.getUuid()).thenReturn(UUID.randomUUID()); final Device device = mock(Device.class); - when(device.getId()).thenReturn(Device.MASTER_ID); + when(device.getId()).thenReturn(Device.PRIMARY_ID); when(baseAccountAuthenticator.authenticate(any(), anyBoolean())) .thenReturn(Optional.of(new AuthenticatedAccount(() -> new Pair<>(account, device)))); 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 0d02c6268..a4905fa30 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DeviceControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/DeviceControllerTest.java @@ -92,7 +92,7 @@ class DeviceControllerTest { private static RedisAdvancedClusterCommands commands = mock(RedisAdvancedClusterCommands.class); private static Account account = mock(Account.class); private static Account maxedAccount = mock(Account.class); - private static Device masterDevice = mock(Device.class); + private static Device primaryDevice = mock(Device.class); private static ClientPresenceManager clientPresenceManager = mock(ClientPresenceManager.class); private static Map deviceConfiguration = new HashMap<>(); private static TestClock testClock = TestClock.now(); @@ -132,7 +132,7 @@ class DeviceControllerTest { when(rateLimiters.getAllocateDeviceLimiter()).thenReturn(rateLimiter); when(rateLimiters.getVerifyDeviceLimiter()).thenReturn(rateLimiter); - when(masterDevice.getId()).thenReturn(1L); + when(primaryDevice.getId()).thenReturn(1L); when(account.getNextDeviceId()).thenReturn(42L); when(account.getNumber()).thenReturn(AuthHelper.VALID_NUMBER); @@ -165,7 +165,7 @@ class DeviceControllerTest { commands, account, maxedAccount, - masterDevice, + primaryDevice, clientPresenceManager ); @@ -175,7 +175,7 @@ class DeviceControllerTest { @Test void validDeviceRegisterTest() { final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(existingDevice.isEnabled()).thenReturn(true); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); @@ -205,7 +205,7 @@ class DeviceControllerTest { when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account)); final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); final String verificationToken = deviceController.generateVerificationToken(AuthHelper.VALID_UUID); @@ -228,7 +228,7 @@ class DeviceControllerTest { when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT)); final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); VerificationCode deviceCode = resources.getJerseyTest() @@ -272,7 +272,7 @@ class DeviceControllerTest { final Optional expectedGcmToken) { final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); VerificationCode deviceCode = resources.getJerseyTest() @@ -358,7 +358,7 @@ class DeviceControllerTest { when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(account)); final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); final Optional aciSignedPreKey; @@ -405,7 +405,7 @@ class DeviceControllerTest { when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT)); final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); VerificationCode deviceCode = resources.getJerseyTest() @@ -466,7 +466,7 @@ class DeviceControllerTest { when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT)); final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); VerificationCode deviceCode = resources.getJerseyTest() @@ -524,7 +524,7 @@ class DeviceControllerTest { when(accountsManager.getByAccountIdentifier(AuthHelper.VALID_UUID)).thenReturn(Optional.of(AuthHelper.VALID_ACCOUNT)); final Device existingDevice = mock(Device.class); - when(existingDevice.getId()).thenReturn(Device.MASTER_ID); + when(existingDevice.getId()).thenReturn(Device.PRIMARY_ID); when(AuthHelper.VALID_ACCOUNT.getDevices()).thenReturn(List.of(existingDevice)); VerificationCode deviceCode = resources.getJerseyTest() @@ -765,7 +765,7 @@ class DeviceControllerTest { try (final Response response = resources .getJerseyTest() - .target("/v1/devices/" + Device.MASTER_ID) + .target("/v1/devices/" + Device.PRIMARY_ID) .request() .header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_UUID, AuthHelper.VALID_PASSWORD)) .header(HttpHeaders.USER_AGENT, "Signal-Android/5.42.8675309 Android/30") diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/KeysControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/KeysControllerTest.java index d05df2ce5..b36d443c3 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/KeysControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/KeysControllerTest.java @@ -285,7 +285,7 @@ class KeysControllerTest { verify(AuthHelper.VALID_DEVICE).setSignedPreKey(eq(test)); verify(AuthHelper.VALID_DEVICE, never()).setPhoneNumberIdentitySignedPreKey(any()); verify(accounts).updateDevice(eq(AuthHelper.VALID_ACCOUNT), anyLong(), any()); - verify(KEYS).storeEcSignedPreKeys(AuthHelper.VALID_UUID, Map.of(Device.MASTER_ID, test)); + verify(KEYS).storeEcSignedPreKeys(AuthHelper.VALID_UUID, Map.of(Device.PRIMARY_ID, test)); } @Test @@ -304,7 +304,7 @@ class KeysControllerTest { verify(AuthHelper.VALID_DEVICE).setPhoneNumberIdentitySignedPreKey(eq(replacementKey)); verify(AuthHelper.VALID_DEVICE, never()).setSignedPreKey(any()); verify(accounts).updateDevice(eq(AuthHelper.VALID_ACCOUNT), anyLong(), any()); - verify(KEYS).storeEcSignedPreKeys(AuthHelper.VALID_PNI, Map.of(Device.MASTER_ID, replacementKey)); + verify(KEYS).storeEcSignedPreKeys(AuthHelper.VALID_PNI, Map.of(Device.PRIMARY_ID, replacementKey)); } @Test 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 4fee853d5..97f3e25b7 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/controllers/RegistrationControllerTest.java @@ -684,7 +684,7 @@ class RegistrationControllerTest { final Account account = MockUtils.buildMock(Account.class, a -> { when(a.getUuid()).thenReturn(accountIdentifier); when(a.getPhoneNumberIdentifier()).thenReturn(phoneNumberIdentifier); - when(a.getMasterDevice()).thenReturn(Optional.of(device)); + when(a.getPrimaryDevice()).thenReturn(Optional.of(device)); }); when(accountsManager.create(any(), any(), any(), any(), any())).thenReturn(account); @@ -715,10 +715,10 @@ class RegistrationControllerTest { verify(device).setSignedPreKey(expectedAciSignedPreKey); verify(device).setPhoneNumberIdentitySignedPreKey(expectedPniSignedPreKey); - verify(keysManager).storeEcSignedPreKeys(accountIdentifier, Map.of(Device.MASTER_ID, expectedAciSignedPreKey)); - verify(keysManager).storeEcSignedPreKeys(phoneNumberIdentifier, Map.of(Device.MASTER_ID, expectedPniSignedPreKey)); - verify(keysManager).storePqLastResort(accountIdentifier, Map.of(Device.MASTER_ID, expectedAciPqLastResortPreKey)); - verify(keysManager).storePqLastResort(phoneNumberIdentifier, Map.of(Device.MASTER_ID, expectedPniPqLastResortPreKey)); + verify(keysManager).storeEcSignedPreKeys(accountIdentifier, Map.of(Device.PRIMARY_ID, expectedAciSignedPreKey)); + verify(keysManager).storeEcSignedPreKeys(phoneNumberIdentifier, Map.of(Device.PRIMARY_ID, expectedPniSignedPreKey)); + verify(keysManager).storePqLastResort(accountIdentifier, Map.of(Device.PRIMARY_ID, expectedAciPqLastResortPreKey)); + verify(keysManager).storePqLastResort(phoneNumberIdentifier, Map.of(Device.PRIMARY_ID, expectedPniPqLastResortPreKey)); expectedApnsToken.ifPresentOrElse(expectedToken -> verify(device).setApnId(expectedToken), () -> verify(device, never()).setApnId(any())); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/entities/OutgoingMessageEntityTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/entities/OutgoingMessageEntityTest.java index 5c62c7e19..9448870d7 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/entities/OutgoingMessageEntityTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/entities/OutgoingMessageEntityTest.java @@ -40,7 +40,7 @@ class OutgoingMessageEntityTest { MessageProtos.Envelope.Type.CIPHERTEXT_VALUE, messageTimestamp, sourceIdentifier, - sourceIdentifier != null ? (int) Device.MASTER_ID : 0, + sourceIdentifier != null ? (int) Device.PRIMARY_ID : 0, destinationIdentifier, updatedPni, messageContent, diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcServiceTest.java index b5a5e673c..052c4674c 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/DevicesGrpcServiceTest.java @@ -113,14 +113,14 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest authenticatedServiceStub().removeDevice(RemoveDeviceRequest.newBuilder() .setId(17) .build())); } @ParameterizedTest - @ValueSource(longs = {Device.MASTER_ID, Device.MASTER_ID + 1}) + @ValueSource(longs = {Device.PRIMARY_ID, Device.PRIMARY_ID + 1}) void setDeviceName(final long deviceId) { mockAuthenticationInterceptor().setAuthenticatedDevice(AUTHENTICATED_ACI, deviceId); @@ -238,7 +238,7 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest streamBuilder = Stream.builder(); - for (final long deviceId : new long[] { Device.MASTER_ID, Device.MASTER_ID + 1 }) { + for (final long deviceId : new long[] { Device.PRIMARY_ID, Device.PRIMARY_ID + 1 }) { streamBuilder.add(Arguments.of(deviceId, SetPushTokenRequest.newBuilder() .setApnsTokenRequest(SetPushTokenRequest.ApnsTokenRequest.newBuilder() @@ -352,7 +352,7 @@ class DevicesGrpcServiceTest extends SimpleBaseGrpcTest clearPushToken() { return Stream.of( - Arguments.of(Device.MASTER_ID, "apns-token", null, null, "OWI"), - Arguments.of(Device.MASTER_ID, "apns-token", "apns-voip-token", null, "OWI"), - Arguments.of(Device.MASTER_ID, null, "apns-voip-token", null, "OWI"), - Arguments.of(Device.MASTER_ID, null, null, "fcm-token", "OWA"), - Arguments.of(Device.MASTER_ID, null, null, null, null), - Arguments.of(Device.MASTER_ID + 1, "apns-token", null, null, "OWP"), - Arguments.of(Device.MASTER_ID + 1, "apns-token", "apns-voip-token", null, "OWP"), - Arguments.of(Device.MASTER_ID + 1, null, "apns-voip-token", null, "OWP"), - Arguments.of(Device.MASTER_ID + 1, null, null, "fcm-token", "OWA"), - Arguments.of(Device.MASTER_ID + 1, null, null, null, null) + Arguments.of(Device.PRIMARY_ID, "apns-token", null, null, "OWI"), + Arguments.of(Device.PRIMARY_ID, "apns-token", "apns-voip-token", null, "OWI"), + Arguments.of(Device.PRIMARY_ID, null, "apns-voip-token", null, "OWI"), + Arguments.of(Device.PRIMARY_ID, null, null, "fcm-token", "OWA"), + Arguments.of(Device.PRIMARY_ID, null, null, null, null), + Arguments.of(Device.PRIMARY_ID + 1, "apns-token", null, null, "OWP"), + Arguments.of(Device.PRIMARY_ID + 1, "apns-token", "apns-voip-token", null, "OWP"), + Arguments.of(Device.PRIMARY_ID + 1, null, "apns-voip-token", null, "OWP"), + Arguments.of(Device.PRIMARY_ID + 1, null, null, "fcm-token", "OWA"), + Arguments.of(Device.PRIMARY_ID + 1, null, null, null, null) ); } @CartesianTest void setCapabilities( - @CartesianTest.Values(longs = {Device.MASTER_ID, Device.MASTER_ID + 1}) final long deviceId, + @CartesianTest.Values(longs = {Device.PRIMARY_ID, Device.PRIMARY_ID + 1}) final long deviceId, @CartesianTest.Values(booleans = {true, false}) final boolean storage, @CartesianTest.Values(booleans = {true, false}) final boolean transfer, @CartesianTest.Values(booleans = {true, false}) final boolean pni, diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/KeysAnonymousGrpcServiceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/KeysAnonymousGrpcServiceTest.java index 2c2e3cc1d..ab6bf3826 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/KeysAnonymousGrpcServiceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/KeysAnonymousGrpcServiceTest.java @@ -83,9 +83,9 @@ class KeysAnonymousGrpcServiceTest extends SimpleBaseGrpcTest connection = waitClient.connect()) { // CLUSTER INFO gives us a big blob of key-value pairs, but the one we're interested in is `cluster_state`. // According to https://redis.io/commands/cluster-info, `cluster_state:ok` means that the node is ready to - // receive queries, all slots are assigned, and a majority of master nodes are reachable. + // receive queries, all slots are assigned, and a majority of leader nodes are reachable. final int sleepMillis = 500; int tries = 0; diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountTest.java index 0ff085f43..e7bef84ab 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountTest.java @@ -35,8 +35,8 @@ import org.whispersystems.textsecuregcm.util.TestClock; class AccountTest { - private final Device oldMasterDevice = mock(Device.class); - private final Device recentMasterDevice = mock(Device.class); + private final Device oldPrimaryDevice = mock(Device.class); + private final Device recentPrimaryDevice = mock(Device.class); private final Device agingSecondaryDevice = mock(Device.class); private final Device recentSecondaryDevice = mock(Device.class); private final Device oldSecondaryDevice = mock(Device.class); @@ -71,13 +71,13 @@ class AccountTest { @BeforeEach void setup() { - when(oldMasterDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(366)); - when(oldMasterDevice.isEnabled()).thenReturn(true); - when(oldMasterDevice.getId()).thenReturn(Device.MASTER_ID); + when(oldPrimaryDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(366)); + when(oldPrimaryDevice.isEnabled()).thenReturn(true); + when(oldPrimaryDevice.getId()).thenReturn(Device.PRIMARY_ID); - when(recentMasterDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)); - when(recentMasterDevice.isEnabled()).thenReturn(true); - when(recentMasterDevice.getId()).thenReturn(Device.MASTER_ID); + when(recentPrimaryDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)); + when(recentPrimaryDevice.isEnabled()).thenReturn(true); + when(recentPrimaryDevice.getId()).thenReturn(Device.PRIMARY_ID); when(agingSecondaryDevice.getLastSeen()).thenReturn(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31)); when(agingSecondaryDevice.isEnabled()).thenReturn(false); @@ -178,69 +178,69 @@ class AccountTest { @Test void testIsEnabled() { - final Device enabledMasterDevice = mock(Device.class); + final Device enabledPrimaryDevice = mock(Device.class); final Device enabledLinkedDevice = mock(Device.class); - final Device disabledMasterDevice = mock(Device.class); + final Device disabledPrimaryDevice = mock(Device.class); final Device disabledLinkedDevice = mock(Device.class); - when(enabledMasterDevice.isEnabled()).thenReturn(true); + when(enabledPrimaryDevice.isEnabled()).thenReturn(true); when(enabledLinkedDevice.isEnabled()).thenReturn(true); - when(disabledMasterDevice.isEnabled()).thenReturn(false); + when(disabledPrimaryDevice.isEnabled()).thenReturn(false); when(disabledLinkedDevice.isEnabled()).thenReturn(false); - when(enabledMasterDevice.getId()).thenReturn(1L); + when(enabledPrimaryDevice.getId()).thenReturn(1L); when(enabledLinkedDevice.getId()).thenReturn(2L); - when(disabledMasterDevice.getId()).thenReturn(1L); + when(disabledPrimaryDevice.getId()).thenReturn(1L); when(disabledLinkedDevice.getId()).thenReturn(2L); - assertTrue(AccountsHelper.generateTestAccount("+14151234567", List.of(enabledMasterDevice)).isEnabled()); - assertTrue(AccountsHelper.generateTestAccount("+14151234567", List.of(enabledMasterDevice, enabledLinkedDevice)).isEnabled()); - assertTrue(AccountsHelper.generateTestAccount("+14151234567", List.of(enabledMasterDevice, disabledLinkedDevice)).isEnabled()); - assertFalse(AccountsHelper.generateTestAccount("+14151234567", List.of(disabledMasterDevice)).isEnabled()); - assertFalse(AccountsHelper.generateTestAccount("+14151234567", List.of(disabledMasterDevice, enabledLinkedDevice)).isEnabled()); - assertFalse(AccountsHelper.generateTestAccount("+14151234567", List.of(disabledMasterDevice, disabledLinkedDevice)).isEnabled()); + assertTrue(AccountsHelper.generateTestAccount("+14151234567", List.of(enabledPrimaryDevice)).isEnabled()); + assertTrue(AccountsHelper.generateTestAccount("+14151234567", List.of(enabledPrimaryDevice, enabledLinkedDevice)).isEnabled()); + assertTrue(AccountsHelper.generateTestAccount("+14151234567", List.of(enabledPrimaryDevice, disabledLinkedDevice)).isEnabled()); + assertFalse(AccountsHelper.generateTestAccount("+14151234567", List.of(disabledPrimaryDevice)).isEnabled()); + assertFalse(AccountsHelper.generateTestAccount("+14151234567", List.of(disabledPrimaryDevice, enabledLinkedDevice)).isEnabled()); + assertFalse(AccountsHelper.generateTestAccount("+14151234567", List.of(disabledPrimaryDevice, disabledLinkedDevice)).isEnabled()); } @Test void testIsTransferSupported() { - final Device transferCapableMasterDevice = mock(Device.class); - final Device nonTransferCapableMasterDevice = mock(Device.class); + final Device transferCapablePrimaryDevice = mock(Device.class); + final Device nonTransferCapablePrimaryDevice = mock(Device.class); final Device transferCapableLinkedDevice = mock(Device.class); final DeviceCapabilities transferCapabilities = mock(DeviceCapabilities.class); final DeviceCapabilities nonTransferCapabilities = mock(DeviceCapabilities.class); - when(transferCapableMasterDevice.getId()).thenReturn(1L); - when(transferCapableMasterDevice.isMaster()).thenReturn(true); - when(transferCapableMasterDevice.getCapabilities()).thenReturn(transferCapabilities); + when(transferCapablePrimaryDevice.getId()).thenReturn(1L); + when(transferCapablePrimaryDevice.isPrimary()).thenReturn(true); + when(transferCapablePrimaryDevice.getCapabilities()).thenReturn(transferCapabilities); - when(nonTransferCapableMasterDevice.getId()).thenReturn(1L); - when(nonTransferCapableMasterDevice.isMaster()).thenReturn(true); - when(nonTransferCapableMasterDevice.getCapabilities()).thenReturn(nonTransferCapabilities); + when(nonTransferCapablePrimaryDevice.getId()).thenReturn(1L); + when(nonTransferCapablePrimaryDevice.isPrimary()).thenReturn(true); + when(nonTransferCapablePrimaryDevice.getCapabilities()).thenReturn(nonTransferCapabilities); when(transferCapableLinkedDevice.getId()).thenReturn(2L); - when(transferCapableLinkedDevice.isMaster()).thenReturn(false); + when(transferCapableLinkedDevice.isPrimary()).thenReturn(false); when(transferCapableLinkedDevice.getCapabilities()).thenReturn(transferCapabilities); when(transferCapabilities.transfer()).thenReturn(true); when(nonTransferCapabilities.transfer()).thenReturn(false); { - final Account transferableMasterAccount = - AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(transferCapableMasterDevice), "1234".getBytes()); + final Account transferablePrimaryAccount = + AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(transferCapablePrimaryDevice), "1234".getBytes()); - assertTrue(transferableMasterAccount.isTransferSupported()); + assertTrue(transferablePrimaryAccount.isTransferSupported()); } { - final Account nonTransferableMasterAccount = - AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(nonTransferCapableMasterDevice), "1234".getBytes()); + final Account nonTransferablePrimaryAccount = + AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(nonTransferCapablePrimaryDevice), "1234".getBytes()); - assertFalse(nonTransferableMasterAccount.isTransferSupported()); + assertFalse(nonTransferablePrimaryAccount.isTransferSupported()); } { - final Account transferableLinkedAccount = AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(nonTransferCapableMasterDevice, transferCapableLinkedDevice), "1234".getBytes()); + final Account transferableLinkedAccount = AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(nonTransferCapablePrimaryDevice, transferCapableLinkedDevice), "1234".getBytes()); assertFalse(transferableLinkedAccount.isTransferSupported()); } @@ -248,7 +248,7 @@ class AccountTest { @Test void testDiscoverableByPhoneNumber() { - final Account account = AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(recentMasterDevice), + final Account account = AccountsHelper.generateTestAccount("+14152222222", UUID.randomUUID(), UUID.randomUUID(), List.of(recentPrimaryDevice), "1234".getBytes()); assertTrue(account.isDiscoverableByPhoneNumber(), @@ -303,7 +303,7 @@ class AccountTest { @Test void getNextDeviceId() { - final List devices = List.of(createDevice(Device.MASTER_ID)); + final List devices = List.of(createDevice(Device.PRIMARY_ID)); final Account account = AccountsHelper.generateTestAccount("+14151234567", UUID.randomUUID(), UUID.randomUUID(), devices, new byte[0]); @@ -326,8 +326,8 @@ class AccountTest { @Test void replaceDevice() { - final Device firstDevice = createDevice(Device.MASTER_ID); - final Device secondDevice = createDevice(Device.MASTER_ID); + final Device firstDevice = createDevice(Device.PRIMARY_ID); + final Device secondDevice = createDevice(Device.PRIMARY_ID); final Account account = AccountsHelper.generateTestAccount("+14151234567", UUID.randomUUID(), UUID.randomUUID(), List.of(firstDevice), new byte[0]); assertEquals(List.of(firstDevice), account.getDevices()); @@ -339,7 +339,7 @@ class AccountTest { @Test void addAndRemoveBadges() { - final Account account = AccountsHelper.generateTestAccount("+14151234567", UUID.randomUUID(), UUID.randomUUID(), List.of(createDevice(Device.MASTER_ID)), new byte[0]); + final Account account = AccountsHelper.generateTestAccount("+14151234567", UUID.randomUUID(), UUID.randomUUID(), List.of(createDevice(Device.PRIMARY_ID)), new byte[0]); final Clock clock = TestClock.pinned(Instant.ofEpochSecond(40)); account.addBadge(clock, new AccountBadge("foo", Instant.ofEpochSecond(42), false)); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerChangeNumberIntegrationTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerChangeNumberIntegrationTest.java index 40b5b1c25..d455df7fd 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerChangeNumberIntegrationTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerChangeNumberIntegrationTest.java @@ -175,14 +175,14 @@ class AccountsManagerChangeNumberIntegrationTest { final AccountAttributes accountAttributes = new AccountAttributes(true, rotatedPniRegistrationId + 1, "test", null, true, new Device.DeviceCapabilities(false, false, false, false)); final Account account = accountsManager.create(originalNumber, "password", null, accountAttributes, new ArrayList<>()); - account.getMasterDevice().orElseThrow().setSignedPreKey(KeysHelper.signedECPreKey(1, pniIdentityKeyPair)); + account.getPrimaryDevice().orElseThrow().setSignedPreKey(KeysHelper.signedECPreKey(1, pniIdentityKeyPair)); final UUID originalUuid = account.getUuid(); final UUID originalPni = account.getPhoneNumberIdentifier(); final IdentityKey pniIdentityKey = new IdentityKey(pniIdentityKeyPair.getPublicKey()); - final Map preKeys = Map.of(Device.MASTER_ID, rotatedSignedPreKey); - final Map registrationIds = Map.of(Device.MASTER_ID, rotatedPniRegistrationId); + final Map preKeys = Map.of(Device.PRIMARY_ID, rotatedSignedPreKey); + final Map registrationIds = Map.of(Device.PRIMARY_ID, rotatedPniRegistrationId); final Account updatedAccount = accountsManager.changeNumber(account, secondNumber, pniIdentityKey, preKeys, null, registrationIds); @@ -200,9 +200,9 @@ class AccountsManagerChangeNumberIntegrationTest { assertEquals(pniIdentityKey, updatedAccount.getIdentityKey(IdentityType.PNI)); assertEquals(OptionalInt.of(rotatedPniRegistrationId), - updatedAccount.getMasterDevice().orElseThrow().getPhoneNumberIdentityRegistrationId()); + updatedAccount.getPrimaryDevice().orElseThrow().getPhoneNumberIdentityRegistrationId()); - assertEquals(rotatedSignedPreKey, updatedAccount.getMasterDevice().orElseThrow().getSignedPreKey(IdentityType.PNI)); + assertEquals(rotatedSignedPreKey, updatedAccount.getPrimaryDevice().orElseThrow().getSignedPreKey(IdentityType.PNI)); } @Test @@ -249,7 +249,7 @@ class AccountsManagerChangeNumberIntegrationTest { assertEquals(secondNumber, accountsManager.getByAccountIdentifier(originalUuid).map(Account::getNumber).orElseThrow()); - verify(clientPresenceManager).disconnectPresence(existingAccountUuid, Device.MASTER_ID); + verify(clientPresenceManager).disconnectPresence(existingAccountUuid, Device.PRIMARY_ID); assertEquals(Optional.of(existingAccountUuid), accountsManager.findRecentlyDeletedAccountIdentifier(originalNumber)); assertEquals(Optional.empty(), accountsManager.findRecentlyDeletedAccountIdentifier(secondNumber)); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerConcurrentModificationIntegrationTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerConcurrentModificationIntegrationTest.java index 16d6a541f..d3fd89e4c 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerConcurrentModificationIntegrationTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerConcurrentModificationIntegrationTest.java @@ -168,8 +168,8 @@ class AccountsManagerConcurrentModificationIntegrationTest { modifyAccount(uuid, account -> account.setUnidentifiedAccessKey(unidentifiedAccessKey)), modifyAccount(uuid, account -> account.setRegistrationLock(credentials.hash(), credentials.salt())), modifyAccount(uuid, account -> account.setUnrestrictedUnidentifiedAccess(unrestrictedUnidentifiedAccess)), - modifyDevice(uuid, Device.MASTER_ID, device -> device.setLastSeen(lastSeen)), - modifyDevice(uuid, Device.MASTER_ID, device -> device.setName("deviceName")) + modifyDevice(uuid, Device.PRIMARY_ID, device -> device.setLastSeen(lastSeen)), + modifyDevice(uuid, Device.PRIMARY_ID, device -> device.setName("deviceName")) ).join(); final Account managerAccount = accountsManager.getByAccountIdentifier(uuid).orElseThrow(); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java index 54db1e888..385f6de2e 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/AccountsManagerTest.java @@ -1530,8 +1530,8 @@ class AccountsManagerTest { assertEquals(originalAccount.getDevices().size(), parsedAccount.getDevices().size()); - final Device originalDevice = originalAccount.getMasterDevice().orElseThrow(); - final Device parsedDevice = parsedAccount.getMasterDevice().orElseThrow(); + final Device originalDevice = originalAccount.getPrimaryDevice().orElseThrow(); + final Device parsedDevice = parsedAccount.getPrimaryDevice().orElseThrow(); assertEquals(originalDevice.getId(), parsedDevice.getId()); assertEquals(originalDevice.getSignedPreKey(IdentityType.ACI), parsedDevice.getSignedPreKey(IdentityType.ACI)); @@ -1549,7 +1549,7 @@ class AccountsManagerTest { private static Device generateTestDevice(final long lastSeen) { final Device device = new Device(); - device.setId(Device.MASTER_ID); + device.setId(Device.PRIMARY_ID); device.setFetchesMessages(true); device.setSignedPreKey(KeysHelper.signedECPreKey(1, Curve.generateKeyPair())); device.setLastSeen(lastSeen); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManagerTest.java index 7ce758211..5463988e8 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/ChangeNumberManagerTest.java @@ -158,7 +158,7 @@ public class ChangeNumberManagerTest { assertEquals(aci, UUID.fromString(envelope.getDestinationUuid())); assertEquals(aci, UUID.fromString(envelope.getSourceUuid())); - assertEquals(Device.MASTER_ID, envelope.getSourceDevice()); + assertEquals(Device.PRIMARY_ID, envelope.getSourceDevice()); assertEquals(updatedPhoneNumberIdentifiersByAccount.get(account), UUID.fromString(envelope.getUpdatedPni())); } @@ -203,7 +203,7 @@ public class ChangeNumberManagerTest { assertEquals(aci, UUID.fromString(envelope.getDestinationUuid())); assertEquals(aci, UUID.fromString(envelope.getSourceUuid())); - assertEquals(Device.MASTER_ID, envelope.getSourceDevice()); + assertEquals(Device.PRIMARY_ID, envelope.getSourceDevice()); assertEquals(updatedPhoneNumberIdentifiersByAccount.get(account), UUID.fromString(envelope.getUpdatedPni())); } @@ -246,7 +246,7 @@ public class ChangeNumberManagerTest { assertEquals(aci, UUID.fromString(envelope.getDestinationUuid())); assertEquals(aci, UUID.fromString(envelope.getSourceUuid())); - assertEquals(Device.MASTER_ID, envelope.getSourceDevice()); + assertEquals(Device.PRIMARY_ID, envelope.getSourceDevice()); assertFalse(updatedPhoneNumberIdentifiersByAccount.containsKey(account)); } @@ -286,7 +286,7 @@ public class ChangeNumberManagerTest { assertEquals(aci, UUID.fromString(envelope.getDestinationUuid())); assertEquals(aci, UUID.fromString(envelope.getSourceUuid())); - assertEquals(Device.MASTER_ID, envelope.getSourceDevice()); + assertEquals(Device.PRIMARY_ID, envelope.getSourceDevice()); assertFalse(updatedPhoneNumberIdentifiersByAccount.containsKey(account)); } @@ -327,7 +327,7 @@ public class ChangeNumberManagerTest { assertEquals(aci, UUID.fromString(envelope.getDestinationUuid())); assertEquals(aci, UUID.fromString(envelope.getSourceUuid())); - assertEquals(Device.MASTER_ID, envelope.getSourceDevice()); + assertEquals(Device.PRIMARY_ID, envelope.getSourceDevice()); assertFalse(updatedPhoneNumberIdentifiersByAccount.containsKey(account)); } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java index 44f25921a..9a0f1b569 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/storage/DeviceTest.java @@ -19,13 +19,13 @@ class DeviceTest { @ParameterizedTest @MethodSource - void testIsEnabled(final boolean master, final boolean fetchesMessages, final String apnId, final String gcmId, + void testIsEnabled(final boolean primary, final boolean fetchesMessages, final String apnId, final String gcmId, final ECSignedPreKey signedPreKey, final Duration timeSinceLastSeen, final boolean expectEnabled) { final long lastSeen = System.currentTimeMillis() - timeSinceLastSeen.toMillis(); final Device device = new Device(); - device.setId(master ? Device.MASTER_ID : Device.MASTER_ID + 1); + device.setId(primary ? Device.PRIMARY_ID : Device.PRIMARY_ID + 1); device.setFetchesMessages(fetchesMessages); device.setApnId(apnId); device.setGcmId(gcmId); @@ -38,7 +38,7 @@ class DeviceTest { private static Stream testIsEnabled() { return Stream.of( - // master fetchesMessages apnId gcmId signedPreKey lastSeen expectEnabled + // primary fetchesMessages apnId gcmId signedPreKey lastSeen expectEnabled Arguments.of(true, false, null, null, null, Duration.ofDays(60), false), Arguments.of(true, false, null, null, null, Duration.ofDays(1), false), Arguments.of(true, false, null, null, mock(ECSignedPreKey.class), Duration.ofDays(60), false), 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 b1ff2f2db..480f4ea4e 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 @@ -117,7 +117,7 @@ public class AccountsHelper { case "getUsernameHash" -> when(updatedAccount.getUsernameHash()).thenAnswer(stubbing); case "getDevices" -> when(updatedAccount.getDevices()).thenAnswer(stubbing); case "getDevice" -> when(updatedAccount.getDevice(stubbing.getInvocation().getArgument(0))).thenAnswer(stubbing); - case "getMasterDevice" -> when(updatedAccount.getMasterDevice()).thenAnswer(stubbing); + case "getPrimaryDevice" -> when(updatedAccount.getPrimaryDevice()).thenAnswer(stubbing); case "isEnabled" -> when(updatedAccount.isEnabled()).thenAnswer(stubbing); case "isDiscoverableByPhoneNumber" -> when(updatedAccount.isDiscoverableByPhoneNumber()).thenAnswer(stubbing); case "getNextDeviceId" -> when(updatedAccount.getNextDeviceId()).thenAnswer(stubbing); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AuthHelper.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AuthHelper.java index 59abd528d..951af1590 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AuthHelper.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/util/AuthHelper.java @@ -105,12 +105,12 @@ public class AuthHelper { when(DISABLED_DEVICE.getAuthTokenHash()).thenReturn(DISABLED_CREDENTIALS); when(UNDISCOVERABLE_DEVICE.getAuthTokenHash()).thenReturn(UNDISCOVERABLE_CREDENTIALS); - when(VALID_DEVICE.isMaster()).thenReturn(true); - when(VALID_DEVICE_TWO.isMaster()).thenReturn(true); - when(DISABLED_DEVICE.isMaster()).thenReturn(true); - when(UNDISCOVERABLE_DEVICE.isMaster()).thenReturn(true); - when(VALID_DEVICE_3_PRIMARY.isMaster()).thenReturn(true); - when(VALID_DEVICE_3_LINKED.isMaster()).thenReturn(false); + when(VALID_DEVICE.isPrimary()).thenReturn(true); + when(VALID_DEVICE_TWO.isPrimary()).thenReturn(true); + when(DISABLED_DEVICE.isPrimary()).thenReturn(true); + when(UNDISCOVERABLE_DEVICE.isPrimary()).thenReturn(true); + when(VALID_DEVICE_3_PRIMARY.isPrimary()).thenReturn(true); + when(VALID_DEVICE_3_LINKED.isPrimary()).thenReturn(false); when(VALID_DEVICE.getId()).thenReturn(1L); when(VALID_DEVICE_TWO.getId()).thenReturn(1L); @@ -122,20 +122,20 @@ public class AuthHelper { when(VALID_DEVICE.isEnabled()).thenReturn(true); when(VALID_DEVICE_TWO.isEnabled()).thenReturn(true); when(DISABLED_DEVICE.isEnabled()).thenReturn(false); - when(UNDISCOVERABLE_DEVICE.isMaster()).thenReturn(true); + when(UNDISCOVERABLE_DEVICE.isPrimary()).thenReturn(true); when(VALID_DEVICE_3_PRIMARY.isEnabled()).thenReturn(true); when(VALID_DEVICE_3_LINKED.isEnabled()).thenReturn(true); when(VALID_ACCOUNT.getDevice(1L)).thenReturn(Optional.of(VALID_DEVICE)); - when(VALID_ACCOUNT.getMasterDevice()).thenReturn(Optional.of(VALID_DEVICE)); + when(VALID_ACCOUNT.getPrimaryDevice()).thenReturn(Optional.of(VALID_DEVICE)); when(VALID_ACCOUNT_TWO.getDevice(eq(1L))).thenReturn(Optional.of(VALID_DEVICE_TWO)); - when(VALID_ACCOUNT_TWO.getMasterDevice()).thenReturn(Optional.of(VALID_DEVICE_TWO)); + when(VALID_ACCOUNT_TWO.getPrimaryDevice()).thenReturn(Optional.of(VALID_DEVICE_TWO)); when(DISABLED_ACCOUNT.getDevice(eq(1L))).thenReturn(Optional.of(DISABLED_DEVICE)); - when(DISABLED_ACCOUNT.getMasterDevice()).thenReturn(Optional.of(DISABLED_DEVICE)); + when(DISABLED_ACCOUNT.getPrimaryDevice()).thenReturn(Optional.of(DISABLED_DEVICE)); when(UNDISCOVERABLE_ACCOUNT.getDevice(eq(1L))).thenReturn(Optional.of(UNDISCOVERABLE_DEVICE)); - when(UNDISCOVERABLE_ACCOUNT.getMasterDevice()).thenReturn(Optional.of(UNDISCOVERABLE_DEVICE)); + when(UNDISCOVERABLE_ACCOUNT.getPrimaryDevice()).thenReturn(Optional.of(UNDISCOVERABLE_DEVICE)); when(VALID_ACCOUNT_3.getDevice(1L)).thenReturn(Optional.of(VALID_DEVICE_3_PRIMARY)); - when(VALID_ACCOUNT_3.getMasterDevice()).thenReturn(Optional.of(VALID_DEVICE_3_PRIMARY)); + when(VALID_ACCOUNT_3.getPrimaryDevice()).thenReturn(Optional.of(VALID_DEVICE_3_PRIMARY)); when(VALID_ACCOUNT_3.getDevice(2L)).thenReturn(Optional.of(VALID_DEVICE_3_LINKED)); when(VALID_ACCOUNT_TWO.getEnabledDeviceCount()).thenReturn(6); @@ -250,11 +250,11 @@ public class AuthHelper { private void setup(final AccountsManager accountsManager) { when(saltedTokenHash.verify(password)).thenReturn(true); when(device.getAuthTokenHash()).thenReturn(saltedTokenHash); - when(device.isMaster()).thenReturn(true); + when(device.isPrimary()).thenReturn(true); when(device.getId()).thenReturn(1L); when(device.isEnabled()).thenReturn(true); when(account.getDevice(1L)).thenReturn(Optional.of(device)); - when(account.getMasterDevice()).thenReturn(Optional.of(device)); + when(account.getPrimaryDevice()).thenReturn(Optional.of(device)); when(account.getNumber()).thenReturn(number); when(account.getUuid()).thenReturn(uuid); when(account.isEnabled()).thenReturn(true); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/util/DestinationDeviceValidatorTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/util/DestinationDeviceValidatorTest.java index 2ad4e7837..288b32afd 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/util/DestinationDeviceValidatorTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/util/DestinationDeviceValidatorTest.java @@ -192,24 +192,24 @@ class DestinationDeviceValidatorTest { @Test void testDuplicateDeviceIds() { - final Account account = mockAccountWithDeviceAndRegId(Map.of(Device.MASTER_ID, 17)); + final Account account = mockAccountWithDeviceAndRegId(Map.of(Device.PRIMARY_ID, 17)); try { DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, 16), new Pair<>(Device.MASTER_ID, 17)), false); + Stream.of(new Pair<>(Device.PRIMARY_ID, 16), new Pair<>(Device.PRIMARY_ID, 17)), false); Assertions.fail("duplicate devices should throw StaleDevicesException"); } catch (StaleDevicesException e) { - Assertions.assertThat(e.getStaleDevices()).hasSameElementsAs(Collections.singletonList(Device.MASTER_ID)); + Assertions.assertThat(e.getStaleDevices()).hasSameElementsAs(Collections.singletonList(Device.PRIMARY_ID)); } } @Test void testValidatePniRegistrationIds() { final Device device = mock(Device.class); - when(device.getId()).thenReturn(Device.MASTER_ID); + when(device.getId()).thenReturn(Device.PRIMARY_ID); final Account account = mock(Account.class); when(account.getDevices()).thenReturn(List.of(device)); - when(account.getDevice(Device.MASTER_ID)).thenReturn(Optional.of(device)); + when(account.getDevice(Device.PRIMARY_ID)).thenReturn(Optional.of(device)); final int aciRegistrationId = 17; final int pniRegistrationId = 89; @@ -220,33 +220,33 @@ class DestinationDeviceValidatorTest { assertDoesNotThrow( () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, aciRegistrationId)), false)); + Stream.of(new Pair<>(Device.PRIMARY_ID, aciRegistrationId)), false)); assertDoesNotThrow( () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, pniRegistrationId)), + Stream.of(new Pair<>(Device.PRIMARY_ID, pniRegistrationId)), true)); assertThrows(StaleDevicesException.class, () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, aciRegistrationId)), + Stream.of(new Pair<>(Device.PRIMARY_ID, aciRegistrationId)), true)); assertThrows(StaleDevicesException.class, () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, pniRegistrationId)), + Stream.of(new Pair<>(Device.PRIMARY_ID, pniRegistrationId)), false)); when(device.getPhoneNumberIdentityRegistrationId()).thenReturn(OptionalInt.empty()); assertDoesNotThrow( () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, aciRegistrationId)), + Stream.of(new Pair<>(Device.PRIMARY_ID, aciRegistrationId)), false)); assertDoesNotThrow( () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, aciRegistrationId)), + Stream.of(new Pair<>(Device.PRIMARY_ID, aciRegistrationId)), true)); assertThrows(StaleDevicesException.class, () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, incorrectRegistrationId)), true)); + Stream.of(new Pair<>(Device.PRIMARY_ID, incorrectRegistrationId)), true)); assertThrows(StaleDevicesException.class, () -> DestinationDeviceValidator.validateRegistrationIds(account, - Stream.of(new Pair<>(Device.MASTER_ID, incorrectRegistrationId)), false)); + Stream.of(new Pair<>(Device.PRIMARY_ID, incorrectRegistrationId)), false)); } }