Skip to content
Snippets Groups Projects
Verified Commit 2a0ecc3f authored by akwizgran's avatar akwizgran
Browse files

Clean up some tests.

parent b176ec58
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory; ...@@ -25,6 +25,7 @@ import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes; import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getSecretKey; import static org.briarproject.bramble.test.TestUtils.getSecretKey;
import static org.briarproject.bramble.test.TestUtils.getTestDirectory; import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.bramble.util.StringUtils.toHexString; import static org.briarproject.bramble.util.StringUtils.toHexString;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -41,8 +42,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase { ...@@ -41,8 +42,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
private final String encryptedKeyHex = toHexString(encryptedKey); private final String encryptedKeyHex = toHexString(encryptedKey);
private final byte[] newEncryptedKey = getRandomBytes(123); private final byte[] newEncryptedKey = getRandomBytes(123);
private final String newEncryptedKeyHex = toHexString(newEncryptedKey); private final String newEncryptedKeyHex = toHexString(newEncryptedKey);
private final String password = "some.password"; private final String password = getRandomString(10);
private final String newPassword = "some.new.password"; private final String newPassword = getRandomString(10);
private final File testDir = getTestDirectory(); private final File testDir = getTestDirectory();
private final File dbDir = new File(testDir, "db"); private final File dbDir = new File(testDir, "db");
private final File keyDir = new File(testDir, "key"); private final File keyDir = new File(testDir, "key");
...@@ -66,21 +67,6 @@ public class AccountManagerImplTest extends BrambleMockTestCase { ...@@ -66,21 +67,6 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
assertFalse(keyBackupFile.exists()); assertFalse(keyBackupFile.exists());
} }
@Test
public void testCreatingAccountStoresDbKey() throws Exception {
context.checking(new Expectations() {{
oneOf(crypto).generateSecretKey();
will(returnValue(key));
oneOf(crypto).encryptWithPassword(key.getBytes(), password);
will(returnValue(encryptedKey));
}});
accountManager.createAccount(password);
assertEquals(encryptedKeyHex, loadDatabaseKey(keyFile));
assertEquals(encryptedKeyHex, loadDatabaseKey(keyBackupFile));
}
@Test @Test
public void testSignInReturnsFalseIfDbKeyCannotBeLoaded() { public void testSignInReturnsFalseIfDbKeyCannotBeLoaded() {
assertFalse(accountManager.signIn(password)); assertFalse(accountManager.signIn(password));
...@@ -302,7 +288,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase { ...@@ -302,7 +288,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
} }
@Test @Test
public void testChangePasswordReturnsTrueIfPasswordIsRight() throws Exception { public void testChangePasswordReturnsTrueIfPasswordIsRight()
throws Exception {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(crypto).decryptWithPassword(encryptedKey, password); oneOf(crypto).decryptWithPassword(encryptedKey, password);
will(returnValue(key.getBytes())); will(returnValue(key.getBytes()));
......
...@@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
public class PasswordControllerImplTest extends BrambleMockTestCase { public class PasswordControllerImplTest extends BrambleMockTestCase {
...@@ -22,8 +23,8 @@ public class PasswordControllerImplTest extends BrambleMockTestCase { ...@@ -22,8 +23,8 @@ public class PasswordControllerImplTest extends BrambleMockTestCase {
private final Executor ioExecutor = new ImmediateExecutor(); private final Executor ioExecutor = new ImmediateExecutor();
private final String oldPassword = "some.old.pass"; private final String oldPassword = getRandomString(10);
private final String newPassword = "some.new.pass"; private final String newPassword = getRandomString(10);
@Test @Test
public void testChangePasswordReturnsTrue() { public void testChangePasswordReturnsTrue() {
......
...@@ -31,7 +31,7 @@ public class SetupControllerImplTest extends BrambleMockTestCase { ...@@ -31,7 +31,7 @@ public class SetupControllerImplTest extends BrambleMockTestCase {
private final Executor ioExecutor = new ImmediateExecutor(); private final Executor ioExecutor = new ImmediateExecutor();
private final String authorName = getRandomString(MAX_AUTHOR_NAME_LENGTH); private final String authorName = getRandomString(MAX_AUTHOR_NAME_LENGTH);
private final String password = "some.strong.pass"; private final String password = getRandomString(10);
private final LocalAuthor localAuthor = getLocalAuthor(); private final LocalAuthor localAuthor = getLocalAuthor();
public SetupControllerImplTest() { public SetupControllerImplTest() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment