mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Make tests more readable.
This commit is contained in:
@@ -215,7 +215,6 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testStartsSessionAtStartup() throws Exception {
|
public void testStartsSessionAtStartup() throws Exception {
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
AtomicReference<Session> savedSession = new AtomicReference<>();
|
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).getContacts(txn);
|
oneOf(db).getContacts(txn);
|
||||||
@@ -227,41 +226,22 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
oneOf(db).getTransportsWithKeys(txn);
|
oneOf(db).getTransportsWithKeys(txn);
|
||||||
will(returnValue(singletonMap(contact.getId(),
|
will(returnValue(singletonMap(contact.getId(),
|
||||||
singletonList(duplexTransportId))));
|
singletonList(duplexTransportId))));
|
||||||
// Check whether a session exists - it doesn't
|
// Get the contact group ID
|
||||||
oneOf(contactGroupFactory)
|
oneOf(contactGroupFactory)
|
||||||
.createContactGroup(CLIENT_ID, MAJOR_VERSION, contact);
|
.createContactGroup(CLIENT_ID, MAJOR_VERSION, contact);
|
||||||
will(returnValue(contactGroup));
|
will(returnValue(contactGroup));
|
||||||
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
|
||||||
will(returnValue(sessionQuery));
|
|
||||||
oneOf(clientHelper)
|
|
||||||
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
|
||||||
will(returnValue(emptyList()));
|
|
||||||
// Send a key message
|
|
||||||
oneOf(crypto).generateKeyPair();
|
|
||||||
will(returnValue(localKeyPair));
|
|
||||||
oneOf(messageEncoder).encodeKeyMessage(contactGroup.getId(),
|
|
||||||
simplexTransportId, localKeyPair.getPublic());
|
|
||||||
will(returnValue(localKeyMessage));
|
|
||||||
oneOf(messageEncoder)
|
|
||||||
.encodeMessageMetadata(simplexTransportId, KEY, true);
|
|
||||||
will(returnValue(localKeyMeta));
|
|
||||||
oneOf(clientHelper).addLocalMessage(txn, localKeyMessage,
|
|
||||||
localKeyMeta, true, false);
|
|
||||||
// Save the session
|
|
||||||
oneOf(clientHelper)
|
|
||||||
.createMessageForStoringMetadata(contactGroup.getId());
|
|
||||||
will(returnValue(storageMessage));
|
|
||||||
oneOf(db).addLocalMessage(txn, storageMessage, new Metadata(),
|
|
||||||
false, false);
|
|
||||||
oneOf(sessionEncoder).encodeSession(with(any(Session.class)),
|
|
||||||
with(simplexTransportId));
|
|
||||||
will(doAll(
|
|
||||||
new CaptureArgumentAction<>(savedSession, Session.class, 0),
|
|
||||||
returnValue(sessionMeta)));
|
|
||||||
oneOf(clientHelper).mergeMessageMetadata(txn,
|
|
||||||
storageMessage.getId(), sessionMeta);
|
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
// Check whether a session exists - it doesn't
|
||||||
|
expectSessionDoesNotExist(txn);
|
||||||
|
// Generate the local key pair
|
||||||
|
expectGenerateLocalKeyPair();
|
||||||
|
// Send a key message
|
||||||
|
expectSendKeyMessage(txn);
|
||||||
|
// Save the session
|
||||||
|
expectCreateStorageMessage(txn);
|
||||||
|
AtomicReference<Session> savedSession = expectSaveSession(txn);
|
||||||
|
|
||||||
manager.onDatabaseOpened(txn);
|
manager.onDatabaseOpened(txn);
|
||||||
|
|
||||||
assertEquals(AWAIT_KEY, savedSession.get().getState());
|
assertEquals(AWAIT_KEY, savedSession.get().getState());
|
||||||
@@ -289,61 +269,21 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
Session loadedSession = new Session(AWAIT_KEY,
|
Session loadedSession = new Session(AWAIT_KEY,
|
||||||
localKeyMessage.getId(), localKeyPair, localTimestamp, null);
|
localKeyMessage.getId(), localKeyPair, localTimestamp, null);
|
||||||
AtomicReference<Session> savedSession = new AtomicReference<>();
|
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
// Check whether a session exists - it does
|
||||||
// Check whether a session exists - it does
|
expectLoadSession(txn, loadedSession);
|
||||||
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
// Load the contact ID
|
||||||
will(returnValue(sessionQuery));
|
expectLoadContactId(txn);
|
||||||
oneOf(clientHelper)
|
// Check whether we already have keys - we don't
|
||||||
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
expectKeysExist(txn, false);
|
||||||
will(returnValue(singletonList(storageMessage.getId())));
|
// Parse the remote public key
|
||||||
// Load the session
|
expectParseRemotePublicKey();
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
// Derive and store the transport keys
|
||||||
storageMessage.getId());
|
expectDeriveAndStoreTransportKeys(txn);
|
||||||
will(returnValue(sessionMeta));
|
// Send an activate message
|
||||||
oneOf(sessionParser).parseSession(sessionMeta);
|
expectSendActivateMessage(txn);
|
||||||
will(returnValue(loadedSession));
|
// Save the session
|
||||||
// Load the contact ID
|
AtomicReference<Session> savedSession = expectSaveSession(txn);
|
||||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
|
||||||
will(returnValue(contact.getId()));
|
|
||||||
// Check whether we already have keys - we don't
|
|
||||||
oneOf(db).containsTransportKeys(txn, contact.getId(),
|
|
||||||
simplexTransportId);
|
|
||||||
will(returnValue(false));
|
|
||||||
// Parse the remote public key
|
|
||||||
oneOf(crypto).parsePublicKey(remotePublicKey.getEncoded());
|
|
||||||
will(returnValue(remotePublicKey));
|
|
||||||
// Derive and store the transport keys
|
|
||||||
oneOf(crypto).deriveRootKey(localKeyPair, remotePublicKey,
|
|
||||||
min(localTimestamp, remoteTimestamp));
|
|
||||||
will(returnValue(rootKey));
|
|
||||||
oneOf(db).getContact(txn, contact.getId());
|
|
||||||
will(returnValue(contact));
|
|
||||||
oneOf(identityManager).getLocalAuthor(txn);
|
|
||||||
will(returnValue(localAuthor));
|
|
||||||
oneOf(keyManager).addRotationKeys(txn, contact.getId(),
|
|
||||||
simplexTransportId, rootKey,
|
|
||||||
min(localTimestamp, remoteTimestamp), alice, false);
|
|
||||||
will(returnValue(keySetId));
|
|
||||||
// Send an activate message
|
|
||||||
oneOf(messageEncoder).encodeActivateMessage(contactGroup.getId(),
|
|
||||||
simplexTransportId, localKeyMessage.getId());
|
|
||||||
will(returnValue(localActivateMessage));
|
|
||||||
oneOf(messageEncoder)
|
|
||||||
.encodeMessageMetadata(simplexTransportId, ACTIVATE, true);
|
|
||||||
will(returnValue(localActivateMeta));
|
|
||||||
oneOf(clientHelper).addLocalMessage(txn, localActivateMessage,
|
|
||||||
localActivateMeta, true, false);
|
|
||||||
// Save the session
|
|
||||||
oneOf(sessionEncoder).encodeSession(with(any(Session.class)),
|
|
||||||
with(simplexTransportId));
|
|
||||||
will(doAll(
|
|
||||||
new CaptureArgumentAction<>(savedSession, Session.class, 0),
|
|
||||||
returnValue(sessionMeta)));
|
|
||||||
oneOf(clientHelper).mergeMessageMetadata(txn,
|
|
||||||
storageMessage.getId(), sessionMeta);
|
|
||||||
}});
|
|
||||||
|
|
||||||
assertEquals(ACCEPT_DO_NOT_SHARE, manager.incomingMessage(txn,
|
assertEquals(ACCEPT_DO_NOT_SHARE, manager.incomingMessage(txn,
|
||||||
remoteKeyMessage, remoteMessageBody, remoteKeyMeta));
|
remoteKeyMessage, remoteMessageBody, remoteKeyMeta));
|
||||||
@@ -360,72 +300,26 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
public void testAcceptsKeyMessageIfWeHaveTransportKeysButNoSession()
|
public void testAcceptsKeyMessageIfWeHaveTransportKeysButNoSession()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
AtomicReference<Session> savedSession = new AtomicReference<>();
|
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
// Check whether a session exists - it doesn't
|
||||||
// Check whether a session exists - it doesn't
|
expectSessionDoesNotExist(txn);
|
||||||
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
// Load the contact ID
|
||||||
will(returnValue(sessionQuery));
|
expectLoadContactId(txn);
|
||||||
oneOf(clientHelper)
|
// Check whether we already have keys - we do
|
||||||
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
expectKeysExist(txn, true);
|
||||||
will(returnValue(emptyList()));
|
// Generate the local key pair
|
||||||
// Load the contact ID
|
expectGenerateLocalKeyPair();
|
||||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
// Parse the remote public key
|
||||||
will(returnValue(contact.getId()));
|
expectParseRemotePublicKey();
|
||||||
// Check whether we already have keys - we do
|
// Send a key message
|
||||||
oneOf(db).containsTransportKeys(txn, contact.getId(),
|
expectSendKeyMessage(txn);
|
||||||
simplexTransportId);
|
// Derive and store the transport keys
|
||||||
will(returnValue(true));
|
expectDeriveAndStoreTransportKeys(txn);
|
||||||
// Generate the local key pair
|
// Send an activate message
|
||||||
oneOf(crypto).generateKeyPair();
|
expectSendActivateMessage(txn);
|
||||||
will(returnValue(localKeyPair));
|
// Save the session
|
||||||
// Parse the remote public key
|
expectCreateStorageMessage(txn);
|
||||||
oneOf(crypto).parsePublicKey(remotePublicKey.getEncoded());
|
AtomicReference<Session> savedSession = expectSaveSession(txn);
|
||||||
will(returnValue(remotePublicKey));
|
|
||||||
// Send a key message
|
|
||||||
oneOf(messageEncoder).encodeKeyMessage(contactGroup.getId(),
|
|
||||||
simplexTransportId, localKeyPair.getPublic());
|
|
||||||
will(returnValue(localKeyMessage));
|
|
||||||
oneOf(messageEncoder)
|
|
||||||
.encodeMessageMetadata(simplexTransportId, KEY, true);
|
|
||||||
will(returnValue(localKeyMeta));
|
|
||||||
oneOf(clientHelper).addLocalMessage(txn, localKeyMessage,
|
|
||||||
localKeyMeta, true, false);
|
|
||||||
// Derive and store the transport keys
|
|
||||||
oneOf(crypto).deriveRootKey(localKeyPair, remotePublicKey,
|
|
||||||
min(localTimestamp, remoteTimestamp));
|
|
||||||
will(returnValue(rootKey));
|
|
||||||
oneOf(db).getContact(txn, contact.getId());
|
|
||||||
will(returnValue(contact));
|
|
||||||
oneOf(identityManager).getLocalAuthor(txn);
|
|
||||||
will(returnValue(localAuthor));
|
|
||||||
oneOf(keyManager).addRotationKeys(txn, contact.getId(),
|
|
||||||
simplexTransportId, rootKey,
|
|
||||||
min(localTimestamp, remoteTimestamp), alice, false);
|
|
||||||
will(returnValue(keySetId));
|
|
||||||
// Send an activate message
|
|
||||||
oneOf(messageEncoder).encodeActivateMessage(contactGroup.getId(),
|
|
||||||
simplexTransportId, localKeyMessage.getId());
|
|
||||||
will(returnValue(localActivateMessage));
|
|
||||||
oneOf(messageEncoder)
|
|
||||||
.encodeMessageMetadata(simplexTransportId, ACTIVATE, true);
|
|
||||||
will(returnValue(localActivateMeta));
|
|
||||||
oneOf(clientHelper).addLocalMessage(txn, localActivateMessage,
|
|
||||||
localActivateMeta, true, false);
|
|
||||||
// Save the session
|
|
||||||
oneOf(clientHelper)
|
|
||||||
.createMessageForStoringMetadata(contactGroup.getId());
|
|
||||||
will(returnValue(storageMessage));
|
|
||||||
oneOf(db).addLocalMessage(txn, storageMessage, new Metadata(),
|
|
||||||
false, false);
|
|
||||||
oneOf(sessionEncoder).encodeSession(with(any(Session.class)),
|
|
||||||
with(simplexTransportId));
|
|
||||||
will(doAll(
|
|
||||||
new CaptureArgumentAction<>(savedSession, Session.class, 0),
|
|
||||||
returnValue(sessionMeta)));
|
|
||||||
oneOf(clientHelper).mergeMessageMetadata(txn,
|
|
||||||
storageMessage.getId(), sessionMeta);
|
|
||||||
}});
|
|
||||||
|
|
||||||
assertEquals(ACCEPT_DO_NOT_SHARE, manager.incomingMessage(txn,
|
assertEquals(ACCEPT_DO_NOT_SHARE, manager.incomingMessage(txn,
|
||||||
remoteKeyMessage, remoteMessageBody, remoteKeyMeta));
|
remoteKeyMessage, remoteMessageBody, remoteKeyMeta));
|
||||||
@@ -456,27 +350,12 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
// Check whether a session exists - it does
|
||||||
// Check whether a session exists - it does
|
expectLoadSession(txn, loadedSession);
|
||||||
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
// Load the contact ID
|
||||||
will(returnValue(sessionQuery));
|
expectLoadContactId(txn);
|
||||||
oneOf(clientHelper)
|
// Check whether we already have keys - we don't
|
||||||
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
expectKeysExist(txn, false);
|
||||||
will(returnValue(singletonList(storageMessage.getId())));
|
|
||||||
// Load the session
|
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
|
||||||
storageMessage.getId());
|
|
||||||
will(returnValue(sessionMeta));
|
|
||||||
oneOf(sessionParser).parseSession(sessionMeta);
|
|
||||||
will(returnValue(loadedSession));
|
|
||||||
// Load the contact ID
|
|
||||||
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
|
||||||
will(returnValue(contact.getId()));
|
|
||||||
// Check whether we already have keys - we don't
|
|
||||||
oneOf(db).containsTransportKeys(txn, contact.getId(),
|
|
||||||
simplexTransportId);
|
|
||||||
will(returnValue(false));
|
|
||||||
}});
|
|
||||||
|
|
||||||
assertEquals(REJECT, manager.incomingMessage(txn,
|
assertEquals(REJECT, manager.incomingMessage(txn,
|
||||||
remoteKeyMessage, remoteMessageBody, remoteKeyMeta));
|
remoteKeyMessage, remoteMessageBody, remoteKeyMeta));
|
||||||
@@ -488,34 +367,19 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
Session loadedSession = new Session(AWAIT_ACTIVATE,
|
Session loadedSession = new Session(AWAIT_ACTIVATE,
|
||||||
localActivateMessage.getId(), null, null, keySetId);
|
localActivateMessage.getId(), null, null, keySetId);
|
||||||
AtomicReference<Session> savedSession = new AtomicReference<>();
|
|
||||||
|
|
||||||
|
// Check whether a session exists - it does
|
||||||
|
expectLoadSession(txn, loadedSession);
|
||||||
|
|
||||||
|
// Activate the transport keys
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Check whether a session exists - it does
|
|
||||||
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
|
||||||
will(returnValue(sessionQuery));
|
|
||||||
oneOf(clientHelper)
|
|
||||||
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
|
||||||
will(returnValue(singletonList(storageMessage.getId())));
|
|
||||||
// Load the session
|
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
|
||||||
storageMessage.getId());
|
|
||||||
will(returnValue(sessionMeta));
|
|
||||||
oneOf(sessionParser).parseSession(sessionMeta);
|
|
||||||
will(returnValue(loadedSession));
|
|
||||||
// Activate the transport keys
|
|
||||||
oneOf(keyManager).activateKeys(txn,
|
oneOf(keyManager).activateKeys(txn,
|
||||||
singletonMap(simplexTransportId, keySetId));
|
singletonMap(simplexTransportId, keySetId));
|
||||||
// Save the session
|
|
||||||
oneOf(sessionEncoder).encodeSession(with(any(Session.class)),
|
|
||||||
with(simplexTransportId));
|
|
||||||
will(doAll(
|
|
||||||
new CaptureArgumentAction<>(savedSession, Session.class, 0),
|
|
||||||
returnValue(sessionMeta)));
|
|
||||||
oneOf(clientHelper).mergeMessageMetadata(txn,
|
|
||||||
storageMessage.getId(), sessionMeta);
|
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
// Save the session
|
||||||
|
AtomicReference<Session> savedSession = expectSaveSession(txn);
|
||||||
|
|
||||||
assertEquals(ACCEPT_DO_NOT_SHARE, manager.incomingMessage(txn,
|
assertEquals(ACCEPT_DO_NOT_SHARE, manager.incomingMessage(txn,
|
||||||
remoteActivateMessage, remoteMessageBody, remoteActivateMeta));
|
remoteActivateMessage, remoteMessageBody, remoteActivateMeta));
|
||||||
|
|
||||||
@@ -531,14 +395,8 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
public void testRejectsActivateMessageWithNoSession() throws Exception {
|
public void testRejectsActivateMessageWithNoSession() throws Exception {
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
// Check whether a session exists - it doesn't
|
||||||
// Check whether a session exists - it doesn't
|
expectSessionDoesNotExist(txn);
|
||||||
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
|
||||||
will(returnValue(sessionQuery));
|
|
||||||
oneOf(clientHelper)
|
|
||||||
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
|
||||||
will(returnValue(emptyList()));
|
|
||||||
}});
|
|
||||||
|
|
||||||
assertEquals(REJECT, manager.incomingMessage(txn,
|
assertEquals(REJECT, manager.incomingMessage(txn,
|
||||||
remoteActivateMessage, remoteMessageBody, remoteActivateMeta));
|
remoteActivateMessage, remoteMessageBody, remoteActivateMeta));
|
||||||
@@ -562,22 +420,136 @@ public class TransportKeyAgreementManagerImplTest extends BrambleMockTestCase {
|
|||||||
Session loadedSession) throws Exception {
|
Session loadedSession) throws Exception {
|
||||||
Transaction txn = new Transaction(null, false);
|
Transaction txn = new Transaction(null, false);
|
||||||
|
|
||||||
|
// Check whether a session exists - it does
|
||||||
|
expectLoadSession(txn, loadedSession);
|
||||||
|
|
||||||
|
assertEquals(REJECT, manager.incomingMessage(txn,
|
||||||
|
remoteActivateMessage, remoteMessageBody, remoteActivateMeta));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectSessionDoesNotExist(Transaction txn) throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
||||||
|
will(returnValue(sessionQuery));
|
||||||
|
oneOf(clientHelper)
|
||||||
|
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
||||||
|
will(returnValue(emptyList()));
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectLoadSession(Transaction txn, Session loadedSession)
|
||||||
|
throws Exception {
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Check whether a session exists - it does
|
|
||||||
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
oneOf(sessionEncoder).getSessionQuery(simplexTransportId);
|
||||||
will(returnValue(sessionQuery));
|
will(returnValue(sessionQuery));
|
||||||
oneOf(clientHelper)
|
oneOf(clientHelper)
|
||||||
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
.getMessageIds(txn, contactGroup.getId(), sessionQuery);
|
||||||
will(returnValue(singletonList(storageMessage.getId())));
|
will(returnValue(singletonList(storageMessage.getId())));
|
||||||
// Load the session
|
|
||||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||||
storageMessage.getId());
|
storageMessage.getId());
|
||||||
will(returnValue(sessionMeta));
|
will(returnValue(sessionMeta));
|
||||||
oneOf(sessionParser).parseSession(sessionMeta);
|
oneOf(sessionParser).parseSession(sessionMeta);
|
||||||
will(returnValue(loadedSession));
|
will(returnValue(loadedSession));
|
||||||
}});
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
assertEquals(REJECT, manager.incomingMessage(txn,
|
private void expectSendKeyMessage(Transaction txn) throws Exception {
|
||||||
remoteActivateMessage, remoteMessageBody, remoteActivateMeta));
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(messageEncoder).encodeKeyMessage(contactGroup.getId(),
|
||||||
|
simplexTransportId, localKeyPair.getPublic());
|
||||||
|
will(returnValue(localKeyMessage));
|
||||||
|
oneOf(messageEncoder)
|
||||||
|
.encodeMessageMetadata(simplexTransportId, KEY, true);
|
||||||
|
will(returnValue(localKeyMeta));
|
||||||
|
oneOf(clientHelper).addLocalMessage(txn, localKeyMessage,
|
||||||
|
localKeyMeta, true, false);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectSendActivateMessage(Transaction txn) throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(messageEncoder).encodeActivateMessage(contactGroup.getId(),
|
||||||
|
simplexTransportId, localKeyMessage.getId());
|
||||||
|
will(returnValue(localActivateMessage));
|
||||||
|
oneOf(messageEncoder)
|
||||||
|
.encodeMessageMetadata(simplexTransportId, ACTIVATE, true);
|
||||||
|
will(returnValue(localActivateMeta));
|
||||||
|
oneOf(clientHelper).addLocalMessage(txn, localActivateMessage,
|
||||||
|
localActivateMeta, true, false);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectCreateStorageMessage(Transaction txn) throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(clientHelper)
|
||||||
|
.createMessageForStoringMetadata(contactGroup.getId());
|
||||||
|
will(returnValue(storageMessage));
|
||||||
|
oneOf(db).addLocalMessage(txn, storageMessage, new Metadata(),
|
||||||
|
false, false);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtomicReference<Session> expectSaveSession(Transaction txn)
|
||||||
|
throws Exception {
|
||||||
|
AtomicReference<Session> savedSession = new AtomicReference<>();
|
||||||
|
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(sessionEncoder).encodeSession(with(any(Session.class)),
|
||||||
|
with(simplexTransportId));
|
||||||
|
will(doAll(
|
||||||
|
new CaptureArgumentAction<>(savedSession, Session.class, 0),
|
||||||
|
returnValue(sessionMeta)));
|
||||||
|
oneOf(clientHelper).mergeMessageMetadata(txn,
|
||||||
|
storageMessage.getId(), sessionMeta);
|
||||||
|
}});
|
||||||
|
|
||||||
|
return savedSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectLoadContactId(Transaction txn) throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(clientHelper).getContactId(txn, contactGroup.getId());
|
||||||
|
will(returnValue(contact.getId()));
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectGenerateLocalKeyPair() {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(crypto).generateKeyPair();
|
||||||
|
will(returnValue(localKeyPair));
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectParseRemotePublicKey() throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(crypto).parsePublicKey(remotePublicKey.getEncoded());
|
||||||
|
will(returnValue(remotePublicKey));
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectDeriveAndStoreTransportKeys(Transaction txn)
|
||||||
|
throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(crypto).deriveRootKey(localKeyPair, remotePublicKey,
|
||||||
|
min(localTimestamp, remoteTimestamp));
|
||||||
|
will(returnValue(rootKey));
|
||||||
|
oneOf(db).getContact(txn, contact.getId());
|
||||||
|
will(returnValue(contact));
|
||||||
|
oneOf(identityManager).getLocalAuthor(txn);
|
||||||
|
will(returnValue(localAuthor));
|
||||||
|
oneOf(keyManager).addRotationKeys(txn, contact.getId(),
|
||||||
|
simplexTransportId, rootKey,
|
||||||
|
min(localTimestamp, remoteTimestamp), alice, false);
|
||||||
|
will(returnValue(keySetId));
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectKeysExist(Transaction txn, boolean exist)
|
||||||
|
throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(db).containsTransportKeys(txn, contact.getId(),
|
||||||
|
simplexTransportId);
|
||||||
|
will(returnValue(exist));
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user