Skip to content
Snippets Groups Projects
Commit 698f3470 authored by akwizgran's avatar akwizgran
Browse files

Merge branch '276-introduction-integration-tests' into 'master'

Introduction Integration Tests

This introduces these integration tests for the 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

I managed to get rid of the non-determinism missing validator problem by properly injecting the eager singletons.

Attention: This is based on !143 which addresses a corner case that is already tested here.

See merge request !139
parents 2d23ecea 36ef536e
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ dependencies {
compile project(':briar-api')
compile project(':briar-core')
testCompile 'junit:junit:4.12'
testCompile 'net.jodah:concurrentunit:0.4.2'
compile 'com.android.support:appcompat-v7:23.2.0'
testApt 'com.google.dagger:dagger-compiler:2.0.2'
provided 'javax.annotation:jsr250-api:1.0'
......
package org.briarproject;
import org.briarproject.api.contact.ContactManager;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.identity.IdentityManager;
import org.briarproject.api.introduction.IntroductionManager;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.properties.TransportPropertyManager;
import org.briarproject.api.sync.SyncSessionFactory;
import org.briarproject.clients.ClientsModule;
import org.briarproject.contact.ContactModule;
import org.briarproject.crypto.CryptoModule;
import org.briarproject.data.DataModule;
import org.briarproject.db.DatabaseModule;
import org.briarproject.event.EventModule;
import org.briarproject.identity.IdentityModule;
import org.briarproject.introduction.IntroductionModule;
import org.briarproject.lifecycle.LifecycleModule;
import org.briarproject.properties.PropertiesModule;
import org.briarproject.sync.SyncModule;
import org.briarproject.transport.TransportModule;
import javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = {
TestSystemModule.class,
TestDatabaseModule.class,
TestPluginsModule.class,
LifecycleModule.class,
IntroductionModule.class,
DatabaseModule.class,
CryptoModule.class,
EventModule.class,
ContactModule.class,
IdentityModule.class,
TransportModule.class,
ClientsModule.class,
SyncModule.class,
DataModule.class,
PropertiesModule.class
})
public interface IntroductionIntegrationTestComponent {
void inject(IntroductionIntegrationTest testCase);
void inject(ContactModule.EagerSingletons init);
void inject(CryptoModule.EagerSingletons init);
void inject(IntroductionModule.EagerSingletons init);
void inject(LifecycleModule.EagerSingletons init);
void inject(PropertiesModule.EagerSingletons init);
void inject(SyncModule.EagerSingletons init);
void inject(TransportModule.EagerSingletons init);
LifecycleManager getLifecycleManager();
EventBus getEventBus();
IdentityManager getIdentityManager();
ContactManager getContactManager();
IntroductionManager getIntroductionManager();
TransportPropertyManager getTransportPropertyManager();
SyncSessionFactory getSyncSessionFactory();
}
package org.briarproject.api.event;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.introduction.SessionId;
public class IntroductionAbortedEvent extends Event {
private final ContactId contactId;
private final SessionId sessionId;
public IntroductionAbortedEvent(ContactId contactId, SessionId sessionId) {
this.contactId = contactId;
this.sessionId = sessionId;
}
public ContactId getContactId() {
return contactId;
}
public SessionId getSessionId() {
return sessionId;
}
}
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment