Migrate a username links test from `AccountsTest` to `AccountsManager… · signalapp/Signal-Server@0100f0f

1 min read Original article ↗

@@ -22,7 +22,6 @@

2222

import com.fasterxml.uuid.UUIDComparator;

2323

import java.nio.charset.StandardCharsets;

2424

import java.security.SecureRandom;

25-

import java.time.Clock;

2625

import java.time.Duration;

2726

import java.time.Instant;

2827

import java.util.ArrayList;

@@ -35,14 +34,12 @@

3534

import java.util.UUID;

3635

import java.util.concurrent.CompletableFuture;

3736

import java.util.concurrent.CompletionException;

38-

import java.util.concurrent.Executor;

3937

import java.util.concurrent.atomic.AtomicInteger;

4038

import java.util.function.BiConsumer;

4139

import java.util.stream.Collectors;

4240

import java.util.stream.Stream;

4341

import org.apache.commons.lang3.RandomUtils;

4442

import org.junit.jupiter.api.BeforeEach;

45-

import org.junit.jupiter.api.Disabled;

4643

import org.junit.jupiter.api.Test;

4744

import org.junit.jupiter.api.Timeout;

4845

import org.junit.jupiter.api.extension.RegisterExtension;

@@ -51,12 +48,7 @@

5148

import org.junit.jupiter.params.provider.MethodSource;

5249

import org.junit.jupiter.params.provider.ValueSource;

5350

import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration;

54-

import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;

5551

import org.whispersystems.textsecuregcm.identity.IdentityType;

56-

import org.whispersystems.textsecuregcm.push.ClientPresenceManager;

57-

import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;

58-

import org.whispersystems.textsecuregcm.securestorage.SecureStorageClient;

59-

import org.whispersystems.textsecuregcm.securevaluerecovery.SecureValueRecovery2Client;

6052

import org.whispersystems.textsecuregcm.storage.DynamoDbExtensionSchema.Tables;

6153

import org.whispersystems.textsecuregcm.tests.util.AccountsHelper;

6254

import org.whispersystems.textsecuregcm.tests.util.DevicesHelper;

@@ -131,7 +123,7 @@ void setupAccountsDao() {

131123

}

132124133125

@Test

134-

public void testStoreAndLookupUsernameLink() throws Exception {

126+

public void testStoreAndLookupUsernameLink() {

135127

final Account account = nextRandomAccount();

136128

account.setUsernameHash(RandomUtils.nextBytes(16));

137129

accounts.create(account);

@@ -165,54 +157,6 @@ public void testStoreAndLookupUsernameLink() throws Exception {

165157

assertTrue(accounts.getByUsernameLinkHandle(linkHandle2).join().isEmpty());

166158

}

167159168-

@Test

169-

@Disabled

170-

// TODO: @Sergey: what's the story with this test?

171-

public void testUsernameLinksViaAccountsManager() {

172-

final AccountsManager accountsManager = new AccountsManager(

173-

accounts,

174-

mock(PhoneNumberIdentifiers.class),

175-

mock(FaultTolerantRedisCluster.class),

176-

mock(AccountLockManager.class),

177-

mock(KeysManager.class),

178-

mock(MessagesManager.class),

179-

mock(ProfilesManager.class),

180-

mock(SecureStorageClient.class),

181-

mock(SecureValueRecovery2Client.class),

182-

mock(ClientPresenceManager.class),

183-

mock(ExperimentEnrollmentManager.class),

184-

mock(RegistrationRecoveryPasswordsManager.class),

185-

mock(Executor.class),

186-

mock(Clock.class));

187-188-

final Account account = nextRandomAccount();

189-

account.setUsernameHash(RandomUtils.nextBytes(16));

190-

accounts.create(account);

191-192-

final UUID linkHandle = UUID.randomUUID();

193-

final byte[] encryptedUsername = RandomUtils.nextBytes(32);

194-

accountsManager.update(account, a -> a.setUsernameLinkDetails(linkHandle, encryptedUsername));

195-196-

final Optional<Account> maybeAccount = accountsManager.getByUsernameLinkHandle(linkHandle).join();

197-

assertTrue(maybeAccount.isPresent());

198-

assertTrue(maybeAccount.get().getEncryptedUsername().isPresent());

199-

assertArrayEquals(encryptedUsername, maybeAccount.get().getEncryptedUsername().get());

200-201-

// making some unrelated change and updating account to check that username link data is still there

202-

final Optional<Account> accountToChange = accountsManager.getByAccountIdentifier(account.getUuid());

203-

assertTrue(accountToChange.isPresent());

204-

accountsManager.update(accountToChange.get(), a -> a.setDiscoverableByPhoneNumber(!a.isDiscoverableByPhoneNumber()));

205-

final Optional<Account> accountAfterChange = accountsManager.getByUsernameLinkHandle(linkHandle).join();

206-

assertTrue(accountAfterChange.isPresent());

207-

assertTrue(accountAfterChange.get().getEncryptedUsername().isPresent());

208-

assertArrayEquals(encryptedUsername, accountAfterChange.get().getEncryptedUsername().get());

209-210-

// now deleting the link

211-

final Optional<Account> accountToDeleteLink = accountsManager.getByAccountIdentifier(account.getUuid());

212-

accountsManager.update(accountToDeleteLink.get(), a -> a.setUsernameLinkDetails(null, null));

213-

assertTrue(accounts.getByUsernameLinkHandle(linkHandle).join().isEmpty());

214-

}

215-216160

@Test

217161

void testStore() {

218162

Device device = generateDevice(1);