mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 13:56:47 +00:00
Auto refactor Only: s/Account/Device/g
This commit is contained in:
1 parent
5a837d4481
commit
bd6cf10402
20 files changed
+217
-298
No files matched your search
+4
-7
@@ -11,15 +11,12 @@ import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.whispersystems.textsecuregcm.controllers.AccountController;
|
||||
import org.whispersystems.textsecuregcm.controllers.DeviceController;
|
||||
import org.whispersystems.textsecuregcm.entities.AccountAttributes;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.sms.SmsSender;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.PendingAccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.PendingDevicesManager;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
import org.whispersystems.textsecuregcm.util.VerificationCode;
|
||||
|
||||
@@ -80,10 +77,10 @@ public class AccountControllerTest extends ResourceTest {
|
||||
Mockito.doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
((Account)invocation.getArguments()[0]).setDeviceId(2);
|
||||
((Device)invocation.getArguments()[0]).setDeviceId(2);
|
||||
return null;
|
||||
}
|
||||
}).when(accountsManager).createAccountOnExistingNumber(any(Account.class));
|
||||
}).when(accountsManager).createAccountOnExistingNumber(any(Device.class));
|
||||
|
||||
addResource(new DumbVerificationAccountController(pendingAccountsManager, accountsManager, rateLimiters, smsSender));
|
||||
}
|
||||
@@ -110,7 +107,7 @@ public class AccountControllerTest extends ResourceTest {
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(204);
|
||||
|
||||
verify(accountsManager).createResetNumber(isA(Account.class));
|
||||
verify(accountsManager).createResetNumber(isA(Device.class));
|
||||
|
||||
ArgumentCaptor<String> number = ArgumentCaptor.forClass(String.class);
|
||||
verify(pendingAccountsManager).remove(number.capture());
|
||||
|
||||
+5
-5
@@ -27,7 +27,7 @@ import org.whispersystems.textsecuregcm.controllers.DeviceController;
|
||||
import org.whispersystems.textsecuregcm.entities.AccountAttributes;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.PendingDevicesManager;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
@@ -75,17 +75,17 @@ public class DeviceControllerTest extends ResourceTest {
|
||||
Mockito.doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
((Account) invocation.getArguments()[0]).setDeviceId(2);
|
||||
((Device) invocation.getArguments()[0]).setDeviceId(2);
|
||||
return null;
|
||||
}
|
||||
}).when(accountsManager).createAccountOnExistingNumber(any(Account.class));
|
||||
}).when(accountsManager).createAccountOnExistingNumber(any(Device.class));
|
||||
|
||||
addResource(new DumbVerificationDeviceController(pendingDevicesManager, accountsManager, rateLimiters));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validDeviceRegisterTest() throws Exception {
|
||||
VerificationCode deviceCode = client().resource("/v1/devices/")
|
||||
VerificationCode deviceCode = client().resource("/v1/devices/provisioning_code")
|
||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.VALID_PASSWORD))
|
||||
.get(VerificationCode.class);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class DeviceControllerTest extends ResourceTest {
|
||||
.put(Long.class);
|
||||
assertThat(deviceId).isNotEqualTo(AuthHelper.DEFAULT_DEVICE_ID);
|
||||
|
||||
ArgumentCaptor<Account> newAccount = ArgumentCaptor.forClass(Account.class);
|
||||
ArgumentCaptor<Device> newAccount = ArgumentCaptor.forClass(Device.class);
|
||||
verify(accountsManager).createAccountOnExistingNumber(newAccount.capture());
|
||||
assertThat(deviceId).isEqualTo(newAccount.getValue().getDeviceId());
|
||||
|
||||
|
||||
+12
-13
@@ -9,12 +9,11 @@ import org.whispersystems.textsecuregcm.entities.PreKey;
|
||||
import org.whispersystems.textsecuregcm.entities.UnstructuredPreKeyList;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.Keys;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
|
||||
import javax.jws.WebResult;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -31,7 +30,7 @@ public class KeyControllerTest extends ResourceTest {
|
||||
private final PreKey SAMPLE_KEY2 = new PreKey(2, EXISTS_NUMBER, 2, 5667, "test3", "test4", false);
|
||||
private final Keys keys = mock(Keys.class);
|
||||
|
||||
Account[] fakeAccount;
|
||||
Device[] fakeDevice;
|
||||
|
||||
@Override
|
||||
protected void setUpResources() {
|
||||
@@ -41,20 +40,20 @@ public class KeyControllerTest extends ResourceTest {
|
||||
RateLimiter rateLimiter = mock(RateLimiter.class );
|
||||
AccountsManager accounts = mock(AccountsManager.class);
|
||||
|
||||
fakeAccount = new Account[2];
|
||||
fakeAccount[0] = mock(Account.class);
|
||||
fakeAccount[1] = mock(Account.class);
|
||||
fakeDevice = new Device[2];
|
||||
fakeDevice[0] = mock(Device.class);
|
||||
fakeDevice[1] = mock(Device.class);
|
||||
|
||||
when(rateLimiters.getPreKeysLimiter()).thenReturn(rateLimiter);
|
||||
|
||||
when(keys.get(eq(EXISTS_NUMBER), anyList())).thenReturn(new UnstructuredPreKeyList(Arrays.asList(SAMPLE_KEY, SAMPLE_KEY2)));
|
||||
when(keys.get(eq(NOT_EXISTS_NUMBER), anyList())).thenReturn(null);
|
||||
|
||||
when(fakeAccount[0].getDeviceId()).thenReturn(AuthHelper.DEFAULT_DEVICE_ID);
|
||||
when(fakeAccount[1].getDeviceId()).thenReturn((long) 2);
|
||||
when(fakeDevice[0].getDeviceId()).thenReturn(AuthHelper.DEFAULT_DEVICE_ID);
|
||||
when(fakeDevice[1].getDeviceId()).thenReturn((long) 2);
|
||||
|
||||
when(accounts.getAllByNumber(EXISTS_NUMBER)).thenReturn(Arrays.asList(fakeAccount[0], fakeAccount[1]));
|
||||
when(accounts.getAllByNumber(NOT_EXISTS_NUMBER)).thenReturn(new LinkedList<Account>());
|
||||
when(accounts.getAllByNumber(EXISTS_NUMBER)).thenReturn(Arrays.asList(fakeDevice[0], fakeDevice[1]));
|
||||
when(accounts.getAllByNumber(NOT_EXISTS_NUMBER)).thenReturn(new LinkedList<Device>());
|
||||
|
||||
addResource(new KeysController(rateLimiters, keys, accounts, null));
|
||||
}
|
||||
@@ -72,7 +71,7 @@ public class KeyControllerTest extends ResourceTest {
|
||||
assertThat(result.getId() == 0);
|
||||
assertThat(result.getNumber() == null);
|
||||
|
||||
verify(keys).get(eq(EXISTS_NUMBER), eq(Arrays.asList(fakeAccount)));
|
||||
verify(keys).get(eq(EXISTS_NUMBER), eq(Arrays.asList(fakeDevice)));
|
||||
verifyNoMoreInteractions(keys);
|
||||
|
||||
List<PreKey> results = client().resource(String.format("/v1/keys/%s?multikeys", EXISTS_NUMBER))
|
||||
@@ -96,7 +95,7 @@ public class KeyControllerTest extends ResourceTest {
|
||||
assertThat(result.getId() == 1);
|
||||
assertThat(result.getNumber() == null);
|
||||
|
||||
verify(keys, times(2)).get(eq(EXISTS_NUMBER), eq(Arrays.asList(fakeAccount[0], fakeAccount[1])));
|
||||
verify(keys, times(2)).get(eq(EXISTS_NUMBER), eq(Arrays.asList(fakeDevice[0], fakeDevice[1])));
|
||||
verifyNoMoreInteractions(keys);
|
||||
}
|
||||
|
||||
@@ -108,7 +107,7 @@ public class KeyControllerTest extends ResourceTest {
|
||||
|
||||
assertThat(response.getClientResponseStatus().getStatusCode()).isEqualTo(404);
|
||||
|
||||
verify(keys).get(NOT_EXISTS_NUMBER, new LinkedList<Account>());
|
||||
verify(keys).get(NOT_EXISTS_NUMBER, new LinkedList<Device>());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.whispersystems.textsecuregcm.tests.util;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
|
||||
import org.whispersystems.textsecuregcm.auth.DeviceAuthenticator;
|
||||
import org.whispersystems.textsecuregcm.auth.AuthenticationCredentials;
|
||||
import org.whispersystems.textsecuregcm.auth.FederatedPeerAuthenticator;
|
||||
import org.whispersystems.textsecuregcm.auth.MultiBasicAuthProvider;
|
||||
import org.whispersystems.textsecuregcm.configuration.FederationConfiguration;
|
||||
import org.whispersystems.textsecuregcm.federation.FederatedPeer;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||
import org.whispersystems.textsecuregcm.util.Base64;
|
||||
|
||||
@@ -23,19 +23,19 @@ public class AuthHelper {
|
||||
public static final String INVVALID_NUMBER = "+14151111111";
|
||||
public static final String INVALID_PASSWORD = "bar";
|
||||
|
||||
public static MultiBasicAuthProvider<FederatedPeer, Account> getAuthenticator() {
|
||||
public static MultiBasicAuthProvider<FederatedPeer, Device> getAuthenticator() {
|
||||
AccountsManager accounts = mock(AccountsManager.class);
|
||||
Account account = mock(Account.class);
|
||||
Device device = mock(Device.class);
|
||||
AuthenticationCredentials credentials = mock(AuthenticationCredentials.class);
|
||||
|
||||
when(credentials.verify("foo")).thenReturn(true);
|
||||
when(account.getAuthenticationCredentials()).thenReturn(credentials);
|
||||
when(accounts.get(VALID_NUMBER, DEFAULT_DEVICE_ID)).thenReturn(Optional.of(account));
|
||||
when(device.getAuthenticationCredentials()).thenReturn(credentials);
|
||||
when(accounts.get(VALID_NUMBER, DEFAULT_DEVICE_ID)).thenReturn(Optional.of(device));
|
||||
|
||||
return new MultiBasicAuthProvider<>(new FederatedPeerAuthenticator(new FederationConfiguration()),
|
||||
FederatedPeer.class,
|
||||
new AccountAuthenticator(accounts),
|
||||
Account.class, "WhisperServer");
|
||||
new DeviceAuthenticator(accounts),
|
||||
Device.class, "WhisperServer");
|
||||
}
|
||||
|
||||
public static String getAuthHeader(String number, String password) {
|
||||
|
||||
Reference in new issue
Block a user