mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Rename account to identity.
This commit is contained in:
@@ -3,7 +3,7 @@ package org.briarproject.bramble.account;
|
||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.identity.Account;
|
||||
import org.briarproject.bramble.api.identity.Identity;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
@@ -25,7 +25,7 @@ import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
||||
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTestDirectory;
|
||||
@@ -48,8 +48,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
||||
private final String encryptedKeyHex = toHexString(encryptedKey);
|
||||
private final byte[] newEncryptedKey = getRandomBytes(123);
|
||||
private final String newEncryptedKeyHex = toHexString(newEncryptedKey);
|
||||
private final Account account = getAccount();
|
||||
private final LocalAuthor localAuthor = account.getLocalAuthor();
|
||||
private final Identity identity = getIdentity();
|
||||
private final LocalAuthor localAuthor = identity.getLocalAuthor();
|
||||
private final String authorName = localAuthor.getName();
|
||||
private final String password = getRandomString(10);
|
||||
private final String newPassword = getRandomString(10);
|
||||
@@ -253,9 +253,9 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testCreateAccountStoresDbKey() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(identityManager).createAccount(authorName);
|
||||
will(returnValue(account));
|
||||
oneOf(identityManager).registerAccount(account);
|
||||
oneOf(identityManager).createIdentity(authorName);
|
||||
will(returnValue(identity));
|
||||
oneOf(identityManager).registerIdentity(identity);
|
||||
oneOf(crypto).generateSecretKey();
|
||||
will(returnValue(key));
|
||||
oneOf(crypto).encryptWithPassword(key.getBytes(), password);
|
||||
|
||||
@@ -17,8 +17,8 @@ import org.briarproject.bramble.api.db.NoSuchPendingContactException;
|
||||
import org.briarproject.bramble.api.db.NoSuchTransportException;
|
||||
import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.identity.Account;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.Identity;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent;
|
||||
import org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent;
|
||||
@@ -75,11 +75,11 @@ import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERE
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.UNKNOWN;
|
||||
import static org.briarproject.bramble.api.transport.TransportConstants.REORDERING_WINDOW_SIZE;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
@@ -107,7 +107,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
private final GroupId groupId;
|
||||
private final Group group;
|
||||
private final Author author;
|
||||
private final Account account;
|
||||
private final Identity identity;
|
||||
private final LocalAuthor localAuthor;
|
||||
private final String alias;
|
||||
private final Message message, message1;
|
||||
@@ -126,8 +126,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
group = getGroup(clientId, majorVersion);
|
||||
groupId = group.getId();
|
||||
author = getAuthor();
|
||||
account = getAccount();
|
||||
localAuthor = account.getLocalAuthor();
|
||||
identity = getIdentity();
|
||||
localAuthor = identity.getLocalAuthor();
|
||||
message = getMessage(groupId);
|
||||
message1 = getMessage(groupId);
|
||||
messageId = message.getId();
|
||||
@@ -162,15 +162,15 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
// startTransaction()
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
// addAccount()
|
||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
||||
// addIdentity()
|
||||
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||
will(returnValue(false));
|
||||
oneOf(database).addAccount(txn, account);
|
||||
oneOf(database).addIdentity(txn, identity);
|
||||
oneOf(eventBus).broadcast(with(any(LocalAuthorAddedEvent.class)));
|
||||
// addContact()
|
||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
||||
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsAccount(txn, author.getId());
|
||||
oneOf(database).containsIdentity(txn, author.getId());
|
||||
will(returnValue(false));
|
||||
oneOf(database).containsContact(txn, author.getId(),
|
||||
localAuthor.getId());
|
||||
@@ -206,10 +206,10 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(true));
|
||||
oneOf(database).removeContact(txn, contactId);
|
||||
oneOf(eventBus).broadcast(with(any(ContactRemovedEvent.class)));
|
||||
// removeAccount()
|
||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
||||
// removeIdentity()
|
||||
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(database).removeAccount(txn, localAuthor.getId());
|
||||
oneOf(database).removeIdentity(txn, localAuthor.getId());
|
||||
oneOf(eventBus).broadcast(with(any(LocalAuthorRemovedEvent.class)));
|
||||
// endTransaction()
|
||||
oneOf(database).commitTransaction(txn);
|
||||
@@ -221,7 +221,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
assertFalse(db.open(key, null));
|
||||
db.transaction(false, transaction -> {
|
||||
db.addAccount(transaction, account);
|
||||
db.addIdentity(transaction, identity);
|
||||
assertEquals(contactId, db.addContact(transaction, author,
|
||||
localAuthor.getId(), true));
|
||||
assertEquals(singletonList(contact),
|
||||
@@ -232,7 +232,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
db.getGroups(transaction, clientId, majorVersion));
|
||||
db.removeGroup(transaction, group);
|
||||
db.removeContact(transaction, contactId);
|
||||
db.removeAccount(transaction, localAuthor.getId());
|
||||
db.removeIdentity(transaction, localAuthor.getId());
|
||||
});
|
||||
db.close();
|
||||
}
|
||||
@@ -437,13 +437,13 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariousMethodsThrowExceptionIfAccountIsMissing()
|
||||
public void testVariousMethodsThrowExceptionIfIdentityIsMissing()
|
||||
throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the account is in the DB (which it's not)
|
||||
// Check whether the identity is in the DB (which it's not)
|
||||
exactly(4).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(4).of(database).containsAccount(txn, localAuthor.getId());
|
||||
exactly(4).of(database).containsIdentity(txn, localAuthor.getId());
|
||||
will(returnValue(false));
|
||||
exactly(4).of(database).abortTransaction(txn);
|
||||
}});
|
||||
@@ -461,7 +461,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.getAccount(transaction, localAuthor.getId()));
|
||||
db.getIdentity(transaction, localAuthor.getId()));
|
||||
fail();
|
||||
} catch (NoSuchLocalAuthorException expected) {
|
||||
// Expected
|
||||
@@ -469,7 +469,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
try {
|
||||
db.transaction(false, transaction ->
|
||||
db.removeAccount(transaction, localAuthor.getId()));
|
||||
db.removeIdentity(transaction, localAuthor.getId()));
|
||||
fail();
|
||||
} catch (NoSuchLocalAuthorException expected) {
|
||||
// Expected
|
||||
@@ -1418,10 +1418,10 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
||||
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||
will(returnValue(true));
|
||||
// Contact is a local identity
|
||||
oneOf(database).containsAccount(txn, author.getId());
|
||||
oneOf(database).containsIdentity(txn, author.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(database).abortTransaction(txn);
|
||||
}});
|
||||
@@ -1444,9 +1444,9 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
oneOf(database).containsAccount(txn, localAuthor.getId());
|
||||
oneOf(database).containsIdentity(txn, localAuthor.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsAccount(txn, author.getId());
|
||||
oneOf(database).containsIdentity(txn, author.getId());
|
||||
will(returnValue(false));
|
||||
// Contact already exists for this local identity
|
||||
oneOf(database).containsContact(txn, author.getId(),
|
||||
@@ -1469,7 +1469,6 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMessageDependencies() throws Exception {
|
||||
int shutdownHandle = 12345;
|
||||
MessageId messageId2 = new MessageId(getRandomId());
|
||||
|
||||
@@ -4,8 +4,8 @@ import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.identity.Account;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
import org.briarproject.bramble.api.identity.Identity;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.bramble.api.sync.Group;
|
||||
@@ -36,9 +36,9 @@ import static java.util.logging.Level.OFF;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_IDS;
|
||||
import static org.briarproject.bramble.api.sync.validation.MessageState.DELIVERED;
|
||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomId;
|
||||
@@ -162,11 +162,11 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContainsAccount() throws Exception {
|
||||
String name = "containsAccount(T, AuthorId)";
|
||||
public void testContainsIdentity() throws Exception {
|
||||
String name = "containsIdentity(T, AuthorId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
db.containsAccount(txn, localAuthor.getId());
|
||||
db.containsIdentity(txn, localAuthor.getId());
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
@@ -296,21 +296,21 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccount() throws Exception {
|
||||
String name = "getAccount(T, AuthorId)";
|
||||
public void testGetIdentity() throws Exception {
|
||||
String name = "getIdentity(T, AuthorId)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
db.getAccount(txn, localAuthor.getId());
|
||||
db.getIdentity(txn, localAuthor.getId());
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAccounts() throws Exception {
|
||||
String name = "getAccounts(T)";
|
||||
public void testGetIdentities() throws Exception {
|
||||
String name = "getIdentities(T)";
|
||||
benchmark(name, db -> {
|
||||
Connection txn = db.startTransaction();
|
||||
db.getAccounts(txn);
|
||||
db.getIdentities(txn);
|
||||
db.commitTransaction(txn);
|
||||
});
|
||||
}
|
||||
@@ -532,8 +532,8 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
void populateDatabase(Database<Connection> db) throws DbException {
|
||||
Account account = getAccount();
|
||||
localAuthor = account.getLocalAuthor();
|
||||
Identity identity = getIdentity();
|
||||
localAuthor = identity.getLocalAuthor();
|
||||
clientIds = new ArrayList<>();
|
||||
contacts = new ArrayList<>();
|
||||
groups = new ArrayList<>();
|
||||
@@ -545,7 +545,7 @@ public abstract class DatabasePerformanceTest extends BrambleTestCase {
|
||||
for (int i = 0; i < CLIENTS; i++) clientIds.add(getClientId());
|
||||
|
||||
Connection txn = db.startTransaction();
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
for (int i = 0; i < CONTACTS; i++) {
|
||||
ContactId c = db.addContact(txn, getAuthor(), localAuthor.getId(),
|
||||
random.nextBoolean());
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.MessageDeletedException;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.identity.Account;
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.Identity;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.plugin.TransportId;
|
||||
import org.briarproject.bramble.api.settings.Settings;
|
||||
@@ -72,10 +72,10 @@ import static org.briarproject.bramble.db.DatabaseConstants.DB_SETTINGS_NAMESPAC
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.LAST_COMPACTED_KEY;
|
||||
import static org.briarproject.bramble.db.DatabaseConstants.MAX_COMPACTION_INTERVAL_MS;
|
||||
import static org.briarproject.bramble.test.TestUtils.deleteTestDirectory;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
import static org.briarproject.bramble.test.TestUtils.getClientId;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getPendingContact;
|
||||
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
|
||||
@@ -106,7 +106,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
private final int majorVersion;
|
||||
private final Group group;
|
||||
private final Author author;
|
||||
private final Account account;
|
||||
private final Identity identity;
|
||||
private final LocalAuthor localAuthor;
|
||||
private final Message message;
|
||||
private final MessageId messageId;
|
||||
@@ -123,8 +123,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
group = getGroup(clientId, majorVersion);
|
||||
groupId = group.getId();
|
||||
author = getAuthor();
|
||||
account = getAccount();
|
||||
localAuthor = account.getLocalAuthor();
|
||||
identity = getIdentity();
|
||||
localAuthor = identity.getLocalAuthor();
|
||||
message = getMessage(groupId);
|
||||
messageId = message.getId();
|
||||
transportId = getTransportId();
|
||||
@@ -150,7 +150,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
@@ -213,7 +213,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -244,7 +244,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared but unvalidated message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -289,7 +289,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, an invisible group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -340,7 +340,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and an unshared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -371,7 +371,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -398,7 +398,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and a visible group
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -439,7 +439,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -571,7 +571,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and a shared group
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -591,7 +591,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
|
||||
@@ -609,7 +609,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, an invisible group and a message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -628,7 +628,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact and a group
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -680,7 +680,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
assertEquals(emptyList(), db.getTransportKeys(txn, transportId));
|
||||
|
||||
// Add the contact, the transport and the transport keys
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
@@ -781,7 +781,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
assertEquals(emptyList(), db.getHandshakeKeys(txn, transportId));
|
||||
|
||||
// Add the contact, the transport and the handshake keys
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
@@ -934,7 +934,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and transport keys
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
@@ -978,7 +978,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and handshake keys
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
@@ -1025,7 +1025,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and transport keys
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
@@ -1072,7 +1072,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add the contact, transport and handshake keys
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
@@ -1114,14 +1114,15 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add an account for a local author - no contacts should be associated
|
||||
db.addAccount(txn, account);
|
||||
// Add an identity for a local author - no contacts should be
|
||||
// associated
|
||||
db.addIdentity(txn, identity);
|
||||
|
||||
// Add a contact associated with the local author
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
|
||||
// Ensure contact is returned from database by Author ID
|
||||
// Ensure contact is returned from database by author ID
|
||||
Collection<Contact> contacts =
|
||||
db.getContactsByAuthorId(txn, author.getId());
|
||||
assertEquals(1, contacts.size());
|
||||
@@ -1141,8 +1142,9 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add an account for a local author - no contacts should be associated
|
||||
db.addAccount(txn, account);
|
||||
// Add an identity for a local author - no contacts should be
|
||||
// associated
|
||||
db.addIdentity(txn, identity);
|
||||
Collection<ContactId> contacts =
|
||||
db.getContacts(txn, localAuthor.getId());
|
||||
assertEquals(emptyList(), contacts);
|
||||
@@ -1153,8 +1155,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
contacts = db.getContacts(txn, localAuthor.getId());
|
||||
assertEquals(singletonList(contactId), contacts);
|
||||
|
||||
// Remove the account - the contact should be removed
|
||||
db.removeAccount(txn, localAuthor.getId());
|
||||
// Remove the identity - the contact should be removed
|
||||
db.removeIdentity(txn, localAuthor.getId());
|
||||
contacts = db.getContacts(txn, localAuthor.getId());
|
||||
assertEquals(emptyList(), contacts);
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
@@ -1169,7 +1171,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact - initially there should be no offered messages
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
assertEquals(0, db.countOfferedMessages(txn, contactId));
|
||||
@@ -1753,7 +1755,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -1855,15 +1857,15 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testDifferentLocalAuthorsCanHaveTheSameContact()
|
||||
throws Exception {
|
||||
Account account1 = getAccount();
|
||||
LocalAuthor localAuthor1 = account1.getLocalAuthor();
|
||||
Identity identity1 = getIdentity();
|
||||
LocalAuthor localAuthor1 = identity1.getLocalAuthor();
|
||||
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add accounts for two local authors
|
||||
db.addAccount(txn, account);
|
||||
db.addAccount(txn, account1);
|
||||
// Add identities for two local authors
|
||||
db.addIdentity(txn, identity);
|
||||
db.addIdentity(txn, identity1);
|
||||
|
||||
// Add the same contact for each local author
|
||||
ContactId contactId =
|
||||
@@ -1887,7 +1889,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -1941,7 +1943,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
|
||||
@@ -1998,7 +2000,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a group and a message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -2082,7 +2084,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -2127,7 +2129,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
// Add a contact, a shared group and a shared message
|
||||
db.addAccount(txn, account);
|
||||
db.addIdentity(txn, identity);
|
||||
assertEquals(contactId,
|
||||
db.addContact(txn, author, localAuthor.getId(), true));
|
||||
db.addGroup(txn, group);
|
||||
@@ -2245,8 +2247,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testSetHandshakeKeyPair() throws Exception {
|
||||
Account withoutKeys =
|
||||
new Account(localAuthor, null, null, account.getTimeCreated());
|
||||
Identity withoutKeys =
|
||||
new Identity(localAuthor, null, null, identity.getTimeCreated());
|
||||
assertFalse(withoutKeys.hasHandshakeKeyPair());
|
||||
byte[] publicKey = getRandomBytes(MAX_AGREEMENT_PUBLIC_KEY_BYTES);
|
||||
byte[] privateKey = getRandomBytes(123);
|
||||
@@ -2254,11 +2256,11 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
db.addAccount(txn, withoutKeys);
|
||||
Account retrieved = db.getAccount(txn, localAuthor.getId());
|
||||
db.addIdentity(txn, withoutKeys);
|
||||
Identity retrieved = db.getIdentity(txn, localAuthor.getId());
|
||||
assertFalse(retrieved.hasHandshakeKeyPair());
|
||||
db.setHandshakeKeyPair(txn, localAuthor.getId(), publicKey, privateKey);
|
||||
retrieved = db.getAccount(txn, localAuthor.getId());
|
||||
retrieved = db.getIdentity(txn, localAuthor.getId());
|
||||
assertTrue(retrieved.hasHandshakeKeyPair());
|
||||
assertArrayEquals(publicKey, retrieved.getHandshakePublicKey());
|
||||
assertArrayEquals(privateKey, retrieved.getHandshakePrivateKey());
|
||||
|
||||
@@ -7,8 +7,8 @@ import org.briarproject.bramble.api.crypto.PublicKey;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.identity.Account;
|
||||
import org.briarproject.bramble.api.identity.AuthorFactory;
|
||||
import org.briarproject.bramble.api.identity.Identity;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
@@ -18,7 +18,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAccount;
|
||||
import static org.briarproject.bramble.test.TestUtils.getIdentity;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
@@ -33,16 +33,16 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
context.mock(PrivateKey.class);
|
||||
|
||||
private final Transaction txn = new Transaction(null, false);
|
||||
private final Account accountWithKeys = getAccount();
|
||||
private final LocalAuthor localAuthor = accountWithKeys.getLocalAuthor();
|
||||
private final Account accountWithoutKeys = new Account(localAuthor,
|
||||
null, null, accountWithKeys.getTimeCreated());
|
||||
private final Identity identityWithKeys = getIdentity();
|
||||
private final LocalAuthor localAuthor = identityWithKeys.getLocalAuthor();
|
||||
private final Identity identityWithoutKeys = new Identity(localAuthor,
|
||||
null, null, identityWithKeys.getTimeCreated());
|
||||
private final KeyPair handshakeKeyPair =
|
||||
new KeyPair(handshakePublicKey, handshakePrivateKey);
|
||||
private final byte[] handshakePublicKeyBytes =
|
||||
accountWithKeys.getHandshakePublicKey();
|
||||
identityWithKeys.getHandshakePublicKey();
|
||||
private final byte[] handshakePrivateKeyBytes =
|
||||
accountWithKeys.getHandshakePrivateKey();
|
||||
identityWithKeys.getHandshakePrivateKey();
|
||||
|
||||
private IdentityManagerImpl identityManager;
|
||||
|
||||
@@ -53,20 +53,20 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenDatabaseAccountRegistered() throws Exception {
|
||||
public void testOpenDatabaseIdentityRegistered() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).addAccount(txn, accountWithKeys);
|
||||
oneOf(db).addIdentity(txn, identityWithKeys);
|
||||
}});
|
||||
|
||||
identityManager.registerAccount(accountWithKeys);
|
||||
identityManager.registerIdentity(identityWithKeys);
|
||||
identityManager.onDatabaseOpened(txn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenDatabaseHandshakeKeysGenerated() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getAccounts(txn);
|
||||
will(returnValue(singletonList(accountWithoutKeys)));
|
||||
oneOf(db).getIdentities(txn);
|
||||
will(returnValue(singletonList(identityWithoutKeys)));
|
||||
oneOf(crypto).generateAgreementKeyPair();
|
||||
will(returnValue(handshakeKeyPair));
|
||||
oneOf(handshakePublicKey).getEncoded();
|
||||
@@ -83,16 +83,16 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testOpenDatabaseNoHandshakeKeysGenerated() throws Exception {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).getAccounts(txn);
|
||||
will(returnValue(singletonList(accountWithKeys)));
|
||||
oneOf(db).getIdentities(txn);
|
||||
will(returnValue(singletonList(identityWithKeys)));
|
||||
}});
|
||||
|
||||
identityManager.onDatabaseOpened(txn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLocalAuthorAccountRegistered() throws DbException {
|
||||
identityManager.registerAccount(accountWithKeys);
|
||||
public void testGetLocalAuthorIdentityRegistered() throws DbException {
|
||||
identityManager.registerIdentity(identityWithKeys);
|
||||
assertEquals(localAuthor, identityManager.getLocalAuthor());
|
||||
}
|
||||
|
||||
@@ -100,8 +100,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
public void testGetLocalAuthorHandshakeKeysGenerated() throws Exception {
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(db).getAccounts(txn);
|
||||
will(returnValue(singletonList(accountWithoutKeys)));
|
||||
oneOf(db).getIdentities(txn);
|
||||
will(returnValue(singletonList(identityWithoutKeys)));
|
||||
oneOf(crypto).generateAgreementKeyPair();
|
||||
will(returnValue(handshakeKeyPair));
|
||||
oneOf(handshakePublicKey).getEncoded();
|
||||
@@ -117,8 +117,8 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
public void testGetLocalAuthorNoHandshakeKeysGenerated() throws Exception {
|
||||
context.checking(new DbExpectations() {{
|
||||
oneOf(db).transactionWithResult(with(true), withDbCallable(txn));
|
||||
oneOf(db).getAccounts(txn);
|
||||
will(returnValue(singletonList(accountWithKeys)));
|
||||
oneOf(db).getIdentities(txn);
|
||||
will(returnValue(singletonList(identityWithKeys)));
|
||||
}});
|
||||
|
||||
assertEquals(localAuthor, identityManager.getLocalAuthor());
|
||||
|
||||
Reference in New Issue
Block a user