Add a method for binding transport keys to a contact.

This commit is contained in:
akwizgran
2018-03-27 17:01:39 +01:00
parent 5bd2092a03
commit 17fe358fd9
11 changed files with 139 additions and 32 deletions

View File

@@ -284,11 +284,11 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
throws Exception {
context.checking(new Expectations() {{
// Check whether the contact is in the DB (which it's not)
exactly(17).of(database).startTransaction();
exactly(18).of(database).startTransaction();
will(returnValue(txn));
exactly(17).of(database).containsContact(txn, contactId);
exactly(18).of(database).containsContact(txn, contactId);
will(returnValue(false));
exactly(17).of(database).abortTransaction(txn);
exactly(18).of(database).abortTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
@@ -303,6 +303,16 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db.endTransaction(transaction);
}
transaction = db.startTransaction(false);
try {
db.bindTransportKeys(transaction, contactId, transportId, keySetId);
fail();
} catch (NoSuchContactException expected) {
// Expected
} finally {
db.endTransaction(transaction);
}
transaction = db.startTransaction(false);
try {
db.generateAck(transaction, contactId, 123);
@@ -768,13 +778,13 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
// endTransaction()
oneOf(database).commitTransaction(txn);
// Check whether the transport is in the DB (which it's not)
exactly(4).of(database).startTransaction();
exactly(5).of(database).startTransaction();
will(returnValue(txn));
oneOf(database).containsContact(txn, contactId);
exactly(2).of(database).containsContact(txn, contactId);
will(returnValue(true));
exactly(4).of(database).containsTransport(txn, transportId);
exactly(5).of(database).containsTransport(txn, transportId);
will(returnValue(false));
exactly(4).of(database).abortTransaction(txn);
exactly(5).of(database).abortTransaction(txn);
}});
DatabaseComponent db = createDatabaseComponent(database, eventBus,
shutdown);
@@ -789,6 +799,16 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db.endTransaction(transaction);
}
transaction = db.startTransaction(false);
try {
db.bindTransportKeys(transaction, contactId, transportId, keySetId);
fail();
} catch (NoSuchTransportException expected) {
// Expected
} finally {
db.endTransaction(transaction);
}
transaction = db.startTransaction(false);
try {
db.getTransportKeys(transaction, transportId);

View File

@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Random;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
import static org.briarproject.bramble.test.TestUtils.getAuthor;
import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
@@ -122,7 +123,7 @@ public class KeyManagerImplTest extends BrambleMockTestCase {
will(returnValue(keySetId));
}});
assertEquals(singletonList(keySetId),
assertEquals(singletonMap(transportId, keySetId),
keyManager.addUnboundKeys(txn, secretKey, timestamp, alice));
}

View File

@@ -449,8 +449,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
}
// Save the keys that were rotated
oneOf(db).updateTransportKeys(txn1, asList(
new KeySet(keySetId, contactId, rotated),
new KeySet(keySetId1, null, rotated1)
new KeySet(keySetId1, null, rotated1),
new KeySet(keySetId, contactId, rotated)
));
// Schedule key rotation at the start of the next rotation period
oneOf(scheduler).schedule(with(any(Runnable.class)),