mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 21:59:54 +01:00
Clean up some tests.
This commit is contained in:
@@ -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 {
|
|||||||
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 {
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
|||||||
|
|
||||||
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 {
|
|||||||
|
|
||||||
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 {
|
|||||||
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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user