Integration Tests for Introduction Client

* normal session where both introducees accept
* normal session where the first introducee declines
* normal session where the second introducee declines
* one session where a contact is introduced to herself
* one session where two identities of the same contact
  are introduced to each other

This introduces a new IntroductionAbortedEvent to signal when the
protocol was aborted. It is not yet used in the UI.

It closes #276
This commit is contained in:
Torsten Grote
2016-04-11 17:40:42 -03:00
parent d0036deaf7
commit 36ef536e82
7 changed files with 888 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ import org.briarproject.api.ProtocolEngine;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.IntroductionAbortedEvent;
import org.briarproject.api.event.IntroductionRequestReceivedEvent;
import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.introduction.IntroduceeAction;
@@ -25,6 +26,8 @@ import static org.briarproject.api.introduction.IntroduceeAction.LOCAL_ABORT;
import static org.briarproject.api.introduction.IntroduceeAction.LOCAL_ACCEPT;
import static org.briarproject.api.introduction.IntroduceeAction.LOCAL_DECLINE;
import static org.briarproject.api.introduction.IntroduceeAction.REMOTE_ABORT;
import static org.briarproject.api.introduction.IntroduceeAction.REMOTE_ACCEPT;
import static org.briarproject.api.introduction.IntroduceeAction.REMOTE_DECLINE;
import static org.briarproject.api.introduction.IntroduceeProtocolState.AWAIT_ACK;
import static org.briarproject.api.introduction.IntroduceeProtocolState.AWAIT_REMOTE_RESPONSE;
import static org.briarproject.api.introduction.IntroduceeProtocolState.AWAIT_REQUEST;
@@ -92,7 +95,7 @@ public class IntroduceeEngine
currentState.name());
}
if (currentState == ERROR) return noUpdate(localState);
else abortSession(currentState, localState);
else return abortSession(currentState, localState);
}
if (action == LOCAL_ACCEPT || action == LOCAL_DECLINE) {
@@ -194,6 +197,11 @@ public class IntroduceeEngine
}
// we are done (probably declined response) and ignore this message
else if (currentState == FINISHED) {
if(action == REMOTE_DECLINE || action == REMOTE_ACCEPT) {
// record response data,
// so we later know which response was ours
addResponseData(localState, msg);
}
return noUpdate(localState);
}
// this should not happen
@@ -355,8 +363,14 @@ public class IntroduceeEngine
msg.put(GROUP_ID, localState.getRaw(GROUP_ID));
msg.put(SESSION_ID, localState.getRaw(SESSION_ID));
List<BdfDictionary> messages = Collections.singletonList(msg);
// TODO inform about protocol abort via new Event?
List<Event> events = Collections.emptyList();
// send abort event
ContactId contactId =
new ContactId(localState.getLong(CONTACT_ID_1).intValue());
SessionId sessionId = new SessionId(localState.getRaw(SESSION_ID));
Event event = new IntroductionAbortedEvent(contactId, sessionId);
List<Event> events = Collections.singletonList(event);
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
localState, messages, events);
}

View File

@@ -5,6 +5,7 @@ import org.briarproject.api.ProtocolEngine;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.IntroductionAbortedEvent;
import org.briarproject.api.event.IntroductionResponseReceivedEvent;
import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.introduction.IntroducerAction;
@@ -56,7 +57,6 @@ import static org.briarproject.api.introduction.IntroductionConstants.RESPONSE_1
import static org.briarproject.api.introduction.IntroductionConstants.RESPONSE_2;
import static org.briarproject.api.introduction.IntroductionConstants.SESSION_ID;
import static org.briarproject.api.introduction.IntroductionConstants.STATE;
import static org.briarproject.api.introduction.IntroductionConstants.TIME;
import static org.briarproject.api.introduction.IntroductionConstants.TYPE;
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ABORT;
import static org.briarproject.api.introduction.IntroductionConstants.TYPE_ACK;
@@ -288,11 +288,11 @@ public class IntroducerEngine
ContactId contactId =
new ContactId(localState.getLong(CONTACT_ID_1).intValue());
AuthorId authorId = new AuthorId(localState.getRaw(AUTHOR_ID_1, new byte[32])); // TODO remove byte[]
AuthorId authorId = new AuthorId(localState.getRaw(AUTHOR_ID_1));
if (Arrays.equals(msg.getRaw(GROUP_ID), localState.getRaw(GROUP_ID_2))) {
contactId =
new ContactId(localState.getLong(CONTACT_ID_2).intValue());
authorId = new AuthorId(localState.getRaw(AUTHOR_ID_2, new byte[32])); // TODO remove byte[]
authorId = new AuthorId(localState.getRaw(AUTHOR_ID_2));
}
SessionId sessionId = new SessionId(localState.getRaw(SESSION_ID));
@@ -365,8 +365,19 @@ public class IntroducerEngine
msg2.put(SESSION_ID, localState.getRaw(SESSION_ID));
msg2.put(GROUP_ID, localState.getRaw(GROUP_ID_2));
messages.add(msg2);
// TODO inform about protocol abort via new Event?
List<Event> events = Collections.emptyList();
// send one abort event per contact
List<Event> events = new ArrayList<Event>(2);
SessionId sessionId = new SessionId(localState.getRaw(SESSION_ID));
ContactId contactId1 =
new ContactId(localState.getLong(CONTACT_ID_1).intValue());
ContactId contactId2 =
new ContactId(localState.getLong(CONTACT_ID_2).intValue());
Event event1 = new IntroductionAbortedEvent(contactId1, sessionId);
events.add(event1);
Event event2 = new IntroductionAbortedEvent(contactId2, sessionId);
events.add(event2);
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
localState, messages, events);
}

View File

@@ -3,13 +3,9 @@ package org.briarproject.introduction;
import org.briarproject.api.clients.ClientHelper;
import org.briarproject.api.clients.MessageQueueManager;
import org.briarproject.api.contact.ContactManager;
import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.data.MetadataEncoder;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.identity.AuthorFactory;
import org.briarproject.api.introduction.IntroductionManager;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.properties.TransportPropertyManager;
import org.briarproject.api.system.Clock;
import javax.inject.Inject;
@@ -18,17 +14,19 @@ import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import static org.briarproject.api.sync.ValidationManager.MessageValidator;
@Module
public class IntroductionModule {
public static class EagerSingletons {
@Inject IntroductionManager introductionManager;
@Inject IntroductionValidator introductionValidator;
@Inject MessageValidator introductionValidator;
}
@Provides
@Singleton
IntroductionValidator getValidator(MessageQueueManager messageQueueManager,
MessageValidator getValidator(MessageQueueManager messageQueueManager,
IntroductionManager introductionManager,
MetadataEncoder metadataEncoder, ClientHelper clientHelper,
Clock clock) {