mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
FIX: Addresses reviewer comments
This commit is contained in:
@@ -171,11 +171,11 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
final IntroduceeSessionState state =
|
||||
initializeSessionState(txn, sessionId,
|
||||
introductionGroup1.getId(), msg);
|
||||
state.setIntroducedName(msg.getString(NAME));
|
||||
state.setIntroducedPublicKey(msg.getRaw(PUBLIC_KEY));
|
||||
|
||||
final BdfDictionary statedict = state.toBdfDictionary();
|
||||
statedict.put(STATE, AWAIT_RESPONSES.getValue());
|
||||
statedict.put(SESSION_ID, sessionId);
|
||||
statedict.put(PUBLIC_KEY, msg.getRaw(PUBLIC_KEY));
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(clientHelper).mergeMessageMetadata(txn,
|
||||
@@ -207,7 +207,7 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
initializeSessionState(txn, sessionId,
|
||||
introductionGroup1.getId(), msg);
|
||||
state.setTheirTime(time);
|
||||
state.setTransport(new BdfDictionary());
|
||||
state.setOurTransportProperties(new BdfDictionary());
|
||||
final BdfDictionary statedict = state.toBdfDictionary();
|
||||
state.setState(AWAIT_RESPONSES);
|
||||
statedict.put(STATE, AWAIT_LOCAL_RESPONSE.getValue());
|
||||
@@ -242,7 +242,6 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
|
||||
BdfDictionary statedict = state.toBdfDictionary();
|
||||
assertEquals(statedict, fromBdfDictionary(statedict).toBdfDictionary());
|
||||
// assertEquals(state, fromBdfDictionary(statedict));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -257,24 +256,23 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
state.setOurTime(-1L);
|
||||
state.setTheirTime(-2L);
|
||||
state.setMessage("");
|
||||
state.setEPublicKey(TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
|
||||
state.setTransport(new BdfDictionary());
|
||||
state.setTheirEphemeralPublicKey(TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
|
||||
state.setOurTransportProperties(new BdfDictionary());
|
||||
state.setContactExists(false);
|
||||
state.setRemoteAuthorId(new AuthorId(TestUtils.getRandomId()));
|
||||
state.setRemoteAuthorIsUs(false);
|
||||
state.setOtherResponseId(TestUtils.getRandomId());
|
||||
state.setTheirResponseId(TestUtils.getRandomId());
|
||||
state.setTask(-1);
|
||||
state.setName(TestUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH));
|
||||
state.setIntroducedName(TestUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH));
|
||||
state.setOurPublicKey(TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
|
||||
state.setOurPrivateKey(TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
|
||||
state.setIntroducedPublicKey(TestUtils.getRandomBytes(MAX_PUBLIC_KEY_LENGTH));
|
||||
state.setIntroducedName(TestUtils.getRandomString(MAX_AUTHOR_NAME_LENGTH));
|
||||
state.setMac(TestUtils.getRandomBytes(MAC_LENGTH));
|
||||
state.setSignature(TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH));
|
||||
state.setOurSignature(TestUtils.getRandomBytes(MAX_SIGNATURE_LENGTH));
|
||||
state.setOurTransport(new BdfDictionary());
|
||||
state.setNonce(TestUtils.getRandomBytes(32));
|
||||
state.setMacKey(TestUtils.getRandomBytes(32));
|
||||
state.setTheirNonce(TestUtils.getRandomBytes(32));
|
||||
state.setTheirMacKey(TestUtils.getRandomBytes(32));
|
||||
|
||||
BdfDictionary statedict = state.toBdfDictionary();
|
||||
assertEquals(statedict, fromBdfDictionary(statedict).toBdfDictionary());
|
||||
@@ -312,10 +310,10 @@ public class IntroduceeManagerTest extends BriarTestCase {
|
||||
introducer.getAuthor().getId(), introducer.getAuthor().getName(),
|
||||
introducer.getLocalAuthorId(), AWAIT_REQUEST);
|
||||
|
||||
state.setName(msg.getString(NAME));
|
||||
state.setContactExists(true);
|
||||
state.setRemoteAuthorIsUs(false);
|
||||
state.setRemoteAuthorId(introducee2.getAuthor().getId());
|
||||
state.setIntroducedPublicKey(introducee2.getAuthor().getPublicKey());
|
||||
final BdfDictionary statedict = state.toBdfDictionary();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -43,6 +43,8 @@ import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID_2
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.MESSAGE_TIME;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.NAME;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.PUBLIC_KEY;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.PUBLIC_KEY1;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.PUBLIC_KEY2;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.ROLE;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCER;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.SESSION_ID;
|
||||
@@ -124,6 +126,9 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
final IntroducerSessionState state =
|
||||
getState(msg, introducee1, introducee2);
|
||||
|
||||
state.setPublicKey1(introducee1.getAuthor().getPublicKey());
|
||||
state.setPublicKey2(introducee2.getAuthor().getPublicKey());
|
||||
|
||||
checkInitialisation(time, salt, msg, txn, state);
|
||||
|
||||
IntroducerSessionState result = introducerManager.initialize(txn,
|
||||
@@ -145,6 +150,9 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
final IntroducerSessionState state =
|
||||
getState(msg, introducee1, introducee2);
|
||||
|
||||
state.setPublicKey1(introducee1.getAuthor().getPublicKey());
|
||||
state.setPublicKey2(introducee2.getAuthor().getPublicKey());
|
||||
|
||||
checkInitialisation(time, salt, msg, txn, state);
|
||||
|
||||
final IntroducerSessionState state2 = state;
|
||||
@@ -152,8 +160,8 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
|
||||
final BdfDictionary msg1 = new BdfDictionary();
|
||||
msg1.put(TYPE, TYPE_REQUEST);
|
||||
msg1.put(SESSION_ID, state.getSessionId().getBytes());
|
||||
msg1.put(GROUP_ID, state.getGroup1Id().getBytes());
|
||||
msg1.put(SESSION_ID, state.getSessionId());
|
||||
msg1.put(GROUP_ID, state.getGroup1Id());
|
||||
msg1.put(NAME, state.getContact2Name());
|
||||
msg1.put(PUBLIC_KEY, introducee2.getAuthor().getPublicKey());
|
||||
final BdfDictionary msg1send = (BdfDictionary) msg1.clone();
|
||||
@@ -161,8 +169,8 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
|
||||
final BdfDictionary msg2 = new BdfDictionary();
|
||||
msg2.put(TYPE, TYPE_REQUEST);
|
||||
msg2.put(SESSION_ID, state.getSessionId().getBytes());
|
||||
msg2.put(GROUP_ID, state.getGroup2Id().getBytes());
|
||||
msg2.put(SESSION_ID, state.getSessionId());
|
||||
msg2.put(GROUP_ID, state.getGroup2Id());
|
||||
msg2.put(NAME, state.getContact1Name());
|
||||
msg2.put(PUBLIC_KEY, introducee1.getAuthor().getPublicKey());
|
||||
final BdfDictionary msg2send = (BdfDictionary) msg2.clone();
|
||||
@@ -184,8 +192,13 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
assertFalse(txn.isComplete());
|
||||
}
|
||||
|
||||
private IntroducerSessionState getState(Message msg, Contact c1, Contact c2)
|
||||
throws FormatException {
|
||||
@Test
|
||||
public void testFullSerialization() throws FormatException {
|
||||
|
||||
final Message msg = new Message(new MessageId(TestUtils.getRandomId()),
|
||||
localGroup0.getId(), 0L, TestUtils.getRandomBytes(64));
|
||||
|
||||
IntroducerSessionState state = getState(msg, introducee1, introducee2);
|
||||
|
||||
final BdfDictionary d = new BdfDictionary();
|
||||
d.put(SESSION_ID, new SessionId(msg.getId().getBytes()));
|
||||
@@ -201,10 +214,20 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
d.put(AUTHOR_ID_1, introducee1.getAuthor().getId());
|
||||
d.put(AUTHOR_ID_2, introducee2.getAuthor().getId());
|
||||
|
||||
IntroducerSessionState state =
|
||||
IntroducerSessionState.fromBdfDictionary(d);
|
||||
|
||||
assertEquals(d, state.toBdfDictionary());
|
||||
}
|
||||
|
||||
|
||||
private IntroducerSessionState getState(Message msg, Contact c1, Contact c2)
|
||||
throws FormatException {
|
||||
|
||||
IntroducerSessionState state = new IntroducerSessionState(msg.getId(),
|
||||
new SessionId(msg.getId().getBytes()),
|
||||
introductionGroup1.getId(),
|
||||
introductionGroup2.getId(), c1.getId(), c1.getAuthor().getId(),
|
||||
c1.getAuthor().getName(), c2.getId(), c2.getAuthor().getId(),
|
||||
c2.getAuthor().getName(), PREPARE_REQUESTS);
|
||||
|
||||
|
||||
return state;
|
||||
}
|
||||
@@ -235,10 +258,6 @@ public class IntroducerManagerTest extends BriarTestCase {
|
||||
|
||||
oneOf(clientHelper).addLocalMessage(txn, msg,
|
||||
state.toBdfDictionary(), false);
|
||||
// send message
|
||||
//// oneOf(clientHelper).mergeMessageMetadata(txn, msg.getId(), state2);
|
||||
//// oneOf(messageSender).sendMessage(txn, msg1send);
|
||||
//// oneOf(messageSender).sendMessage(txn, msg2send);
|
||||
}});
|
||||
}
|
||||
|
||||
|
||||
@@ -46,12 +46,12 @@ import static org.briarproject.api.introduction.IntroductionConstants.CONTACT_2;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.CONTACT_ID_1;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.CONTACT_ID_2;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID_1;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.GROUP_ID_2;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.LOCAL_AUTHOR_ID;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.REMOTE_AUTHOR_IS_US;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.ROLE;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCEE;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.ROLE_INTRODUCER;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.SESSION_ID;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.STORAGE_ID;
|
||||
import static org.briarproject.api.introduction.IntroductionConstants.STATE;
|
||||
@@ -165,29 +165,32 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
assertTrue(txn.isComplete());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void testAcceptIntroduction() throws DbException, FormatException {
|
||||
final BdfDictionary state = BdfDictionary.of(
|
||||
new BdfEntry(ROLE, ROLE_INTRODUCEE),
|
||||
new BdfEntry(GROUP_ID, introductionGroup1.getId()),
|
||||
new BdfEntry(GROUP_ID_1, introductionGroup1.getId()),
|
||||
// FIXME: GROUP_ID, GROUP_ID_2 and GROUP_ID_1 are needed to
|
||||
// FIXME: deserialize an *introducee*. Why is this?
|
||||
new BdfEntry(GROUP_ID_2, introductionGroup2.getId()),
|
||||
new BdfEntry(SESSION_ID, sessionId),
|
||||
new BdfEntry(STORAGE_ID, sessionId),
|
||||
new BdfEntry(AUTHOR_ID_1,introducee1.getAuthor().getId()),
|
||||
new BdfEntry(AUTHOR_ID_1, introducee1.getAuthor().getId()),
|
||||
new BdfEntry(CONTACT_1, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(CONTACT_ID_1, introducee1.getId().getInt()),
|
||||
new BdfEntry(AUTHOR_ID_2,introducee2.getAuthor().getId() ),
|
||||
new BdfEntry(AUTHOR_ID_2, introducee2.getAuthor().getId()),
|
||||
new BdfEntry(CONTACT_2, introducee2.getAuthor().getName()),
|
||||
new BdfEntry(CONTACT_ID_2, introducee2.getId().getInt()),
|
||||
new BdfEntry(STATE, AWAIT_REQUEST.getValue()),
|
||||
new BdfEntry(TIME, time),
|
||||
new BdfEntry(OUR_TIME, time),
|
||||
new BdfEntry(NAME, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(OUR_TIME, time),
|
||||
new BdfEntry(NAME, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(LOCAL_AUTHOR_ID, introducee1.getLocalAuthorId()),
|
||||
new BdfEntry(INTRODUCER, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(EXISTS, false),
|
||||
new BdfEntry(TASK, NO_TASK),
|
||||
new BdfEntry(REMOTE_AUTHOR_IS_US, false)
|
||||
new BdfEntry(INTRODUCER, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(EXISTS, false),
|
||||
new BdfEntry(TASK, NO_TASK),
|
||||
new BdfEntry(REMOTE_AUTHOR_IS_US, false)
|
||||
);
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
@@ -197,7 +200,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, introducee1.getId());
|
||||
will(returnValue(introducee1));
|
||||
oneOf(introductionGroupFactory).createIntroductionGroup(introducee1);
|
||||
oneOf(introductionGroupFactory)
|
||||
.createIntroductionGroup(introducee1);
|
||||
will(returnValue(introductionGroup1));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, sessionId);
|
||||
will(returnValue(state));
|
||||
@@ -218,19 +222,20 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
final BdfDictionary state = BdfDictionary.of(
|
||||
new BdfEntry(ROLE, ROLE_INTRODUCEE),
|
||||
new BdfEntry(GROUP_ID_1, introductionGroup1.getId()),
|
||||
new BdfEntry(GROUP_ID, introductionGroup1.getId()),
|
||||
new BdfEntry(GROUP_ID_2, introductionGroup2.getId()),
|
||||
new BdfEntry(SESSION_ID, sessionId),
|
||||
new BdfEntry(STORAGE_ID, sessionId),
|
||||
new BdfEntry(AUTHOR_ID_1,introducee1.getAuthor().getId()),
|
||||
new BdfEntry(AUTHOR_ID_1, introducee1.getAuthor().getId()),
|
||||
new BdfEntry(CONTACT_1, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(CONTACT_ID_1, introducee1.getId().getInt()),
|
||||
new BdfEntry(AUTHOR_ID_2,introducee2.getAuthor().getId() ),
|
||||
new BdfEntry(AUTHOR_ID_2, introducee2.getAuthor().getId()),
|
||||
new BdfEntry(CONTACT_2, introducee2.getAuthor().getName()),
|
||||
new BdfEntry(CONTACT_ID_2, introducee2.getId().getInt()),
|
||||
new BdfEntry(STATE, AWAIT_REQUEST.getValue()),
|
||||
new BdfEntry(TIME, time),
|
||||
new BdfEntry(OUR_TIME, time),
|
||||
new BdfEntry(NAME, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(OUR_TIME, time),
|
||||
new BdfEntry(NAME, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(LOCAL_AUTHOR_ID, introducee1.getLocalAuthorId()),
|
||||
new BdfEntry(INTRODUCER, introducee1.getAuthor().getName()),
|
||||
new BdfEntry(EXISTS, false),
|
||||
@@ -244,7 +249,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, introducee1.getId());
|
||||
will(returnValue(introducee1));
|
||||
oneOf(introductionGroupFactory).createIntroductionGroup(introducee1);
|
||||
oneOf(introductionGroupFactory)
|
||||
.createIntroductionGroup(introducee1);
|
||||
will(returnValue(introductionGroup1));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, sessionId);
|
||||
will(returnValue(state));
|
||||
@@ -273,7 +279,8 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
will(returnValue(txn));
|
||||
oneOf(db).getContact(txn, introducee1.getId());
|
||||
will(returnValue(introducee1));
|
||||
oneOf(introductionGroupFactory).createIntroductionGroup(introducee1);
|
||||
oneOf(introductionGroupFactory)
|
||||
.createIntroductionGroup(introducee1);
|
||||
will(returnValue(introductionGroup1));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
introductionGroup1.getId());
|
||||
@@ -330,9 +337,6 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
|
||||
final IntroducerSessionState sessionState = initializeIntroducerSS();
|
||||
final BdfDictionary state = sessionState.toBdfDictionary();
|
||||
state.put(ROLE, ROLE_INTRODUCER);
|
||||
state.put(GROUP_ID_1, introductionGroup1.getId());
|
||||
state.put(GROUP_ID_2, introductionGroup2.getId());
|
||||
|
||||
txn = new Transaction(null, false);
|
||||
|
||||
@@ -359,7 +363,7 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
final Contact introducer = new Contact(cid, author, aid, true, false);
|
||||
final IntroduceeSessionState state = new IntroduceeSessionState(
|
||||
new MessageId(TestUtils.getRandomId()),
|
||||
new SessionId(TestUtils.getRandomId()),
|
||||
new SessionId(TestUtils.getRandomId()),
|
||||
new GroupId(TestUtils.getRandomId()),
|
||||
introducer.getId(), introducer.getAuthor().getId(),
|
||||
introducer.getAuthor().getName(), introducer.getLocalAuthorId(),
|
||||
@@ -368,9 +372,9 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
state.setContactExists(true);
|
||||
state.setRemoteAuthorIsUs(false);
|
||||
state.setRemoteAuthorId(introducee2.getAuthor().getId());
|
||||
state.setName(introducee2.getAuthor().getName());
|
||||
|
||||
return state;
|
||||
state.setIntroducedName(introducee2.getAuthor().getName());
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private IntroducerSessionState initializeIntroducerSS() {
|
||||
@@ -382,10 +386,12 @@ public class IntroductionManagerImplTest extends BriarTestCase {
|
||||
return new IntroducerSessionState(
|
||||
new MessageId(TestUtils.getRandomId()),
|
||||
new SessionId(TestUtils.getRandomId()),
|
||||
new GroupId(TestUtils.getRandomId()),
|
||||
new GroupId(TestUtils.getRandomId()),
|
||||
introducer.getId(), introducer.getAuthor().getId(), introducer.getAuthor().getName(),
|
||||
introducer.getId(), introducer.getAuthor().getId(), introducer.getAuthor().getName(),
|
||||
introductionGroup1.getId(),
|
||||
introductionGroup2.getId(),
|
||||
introducer.getId(), introducer.getAuthor().getId(),
|
||||
introducer.getAuthor().getName(),
|
||||
introducer.getId(), introducer.getAuthor().getId(),
|
||||
introducer.getAuthor().getName(),
|
||||
IntroducerProtocolState.AWAIT_RESPONSES);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user