Move account deletion into AccountManager.

This commit is contained in:
akwizgran
2018-07-26 17:13:08 +01:00
parent 233af69909
commit 1edf2bfa75
20 changed files with 252 additions and 168 deletions

View File

@@ -1,49 +0,0 @@
package org.briarproject.briar.android.controller;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.test.BrambleMockTestCase;
import org.jmock.Expectations;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.util.StringUtils.toHexString;
public class ConfigControllerImplTest extends BrambleMockTestCase {
private final SharedPreferences prefs =
context.mock(SharedPreferences.class);
private final AccountManager accountManager =
context.mock(AccountManager.class);
private final DatabaseConfig databaseConfig =
context.mock(DatabaseConfig.class);
private final Editor editor = context.mock(Editor.class);
private final String encryptedKeyHex = toHexString(getRandomBytes(123));
@Test
public void testDbKeyIsMigratedFromPreferencesToFile() {
context.checking(new Expectations() {{
oneOf(prefs).getString("key", null);
will(returnValue(encryptedKeyHex));
oneOf(accountManager).storeEncryptedDatabaseKey(encryptedKeyHex);
will(returnValue(true));
oneOf(prefs).edit();
will(returnValue(editor));
oneOf(editor).remove("key");
will(returnValue(editor));
oneOf(editor).commit();
will(returnValue(true));
}});
ConfigControllerImpl c = new ConfigControllerImpl(prefs, accountManager,
databaseConfig);
assertEquals(encryptedKeyHex, c.getEncryptedDatabaseKey());
}
}

View File

@@ -1,11 +1,8 @@
package org.briarproject.briar.android.login;
import android.content.SharedPreferences;
import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.bramble.test.ImmediateExecutor;
import org.jmock.Expectations;
@@ -22,12 +19,8 @@ import static org.briarproject.bramble.util.StringUtils.toHexString;
public class PasswordControllerImplTest extends BrambleMockTestCase {
private final SharedPreferences briarPrefs =
context.mock(SharedPreferences.class);
private final AccountManager accountManager =
context.mock(AccountManager.class);
private final DatabaseConfig databaseConfig =
context.mock(DatabaseConfig.class);
private final CryptoComponent crypto = context.mock(CryptoComponent.class);
private final PasswordStrengthEstimator estimator =
context.mock(PasswordStrengthEstimator.class);
@@ -46,8 +39,6 @@ public class PasswordControllerImplTest extends BrambleMockTestCase {
public void testChangePasswordReturnsTrue() {
context.checking(new Expectations() {{
// Look up the encrypted DB key
oneOf(briarPrefs).getString("key", null);
will(returnValue(null));
oneOf(accountManager).getEncryptedDatabaseKey();
will(returnValue(oldEncryptedKeyHex));
// Decrypt and re-encrypt the key
@@ -60,9 +51,8 @@ public class PasswordControllerImplTest extends BrambleMockTestCase {
will(returnValue(true));
}});
PasswordControllerImpl p = new PasswordControllerImpl(briarPrefs,
accountManager, databaseConfig, cryptoExecutor, crypto,
estimator);
PasswordControllerImpl p = new PasswordControllerImpl(accountManager,
cryptoExecutor, crypto, estimator);
AtomicBoolean capturedResult = new AtomicBoolean(false);
p.changePassword(oldPassword, newPassword, capturedResult::set);
@@ -73,8 +63,6 @@ public class PasswordControllerImplTest extends BrambleMockTestCase {
public void testChangePasswordReturnsFalseIfOldPasswordIsWrong() {
context.checking(new Expectations() {{
// Look up the encrypted DB key
oneOf(briarPrefs).getString("key", null);
will(returnValue(null));
oneOf(accountManager).getEncryptedDatabaseKey();
will(returnValue(oldEncryptedKeyHex));
// Try to decrypt the key - the password is wrong
@@ -82,9 +70,8 @@ public class PasswordControllerImplTest extends BrambleMockTestCase {
will(returnValue(null));
}});
PasswordControllerImpl p = new PasswordControllerImpl(briarPrefs,
accountManager, databaseConfig, cryptoExecutor, crypto,
estimator);
PasswordControllerImpl p = new PasswordControllerImpl(accountManager,
cryptoExecutor, crypto, estimator);
AtomicBoolean capturedResult = new AtomicBoolean(true);
p.changePassword(oldPassword, newPassword, capturedResult::set);

View File

@@ -1,12 +1,9 @@
package org.briarproject.briar.android.login;
import android.content.SharedPreferences;
import org.briarproject.bramble.api.account.AccountManager;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
import org.briarproject.bramble.api.crypto.SecretKey;
import org.briarproject.bramble.api.db.DatabaseConfig;
import org.briarproject.bramble.api.identity.IdentityManager;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.test.BrambleMockTestCase;
@@ -28,12 +25,8 @@ import static org.briarproject.bramble.util.StringUtils.toHexString;
public class SetupControllerImplTest extends BrambleMockTestCase {
private final SharedPreferences briarPrefs =
context.mock(SharedPreferences.class);
private final AccountManager accountManager =
context.mock(AccountManager.class);
private final DatabaseConfig databaseConfig =
context.mock(DatabaseConfig.class);
private final CryptoComponent crypto = context.mock(CryptoComponent.class);
private final PasswordStrengthEstimator estimator =
context.mock(PasswordStrengthEstimator.class);
@@ -84,9 +77,8 @@ public class SetupControllerImplTest extends BrambleMockTestCase {
oneOf(accountManager).setDatabaseKey(key);
}});
SetupControllerImpl s = new SetupControllerImpl(briarPrefs,
accountManager, databaseConfig, cryptoExecutor, crypto,
estimator, identityManager);
SetupControllerImpl s = new SetupControllerImpl(accountManager,
cryptoExecutor, crypto, estimator, identityManager);
s.setSetupActivity(setupActivity);
AtomicBoolean called = new AtomicBoolean(false);