Address last review comments

This commit is contained in:
Torsten Grote
2018-04-27 11:04:08 -03:00
parent 80a9689316
commit 44f5a9db1e
8 changed files with 79 additions and 8 deletions

View File

@@ -63,6 +63,7 @@ import static org.briarproject.briar.introduction.IntroductionConstants.SESSION_
import static org.briarproject.briar.introduction.IntroductionConstants.SESSION_KEY_SESSION_ID;
import static org.briarproject.briar.introduction.MessageType.ACCEPT;
import static org.briarproject.briar.introduction.MessageType.AUTH;
import static org.briarproject.briar.introduction.MessageType.DECLINE;
import static org.briarproject.briar.test.BriarTestUtils.assertGroupCount;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -681,6 +682,41 @@ public class IntroductionIntegrationTest
assertTrue(listener0.aborted);
}
/**
* One introducee sends an DECLINE and then another DECLINE message.
* The introducer should notice this and ABORT the session.
*/
@Test
public void testDoubleDecline() throws Exception {
addListeners(false, true);
// make the introduction
long time = clock.currentTimeMillis();
introductionManager0
.makeIntroduction(contact1From0, contact2From0, null, time);
// sync REQUEST to introducee1
sync0To1(1, true);
// save DECLINE from introducee1
DeclineMessage m = (DeclineMessage) getMessageFor(c1.getClientHelper(),
contact0From1, DECLINE);
// sync DECLINE back to introducer
sync1To0(1, true);
// fake a second DECLINE message also from introducee1
Message msg = c1.getMessageEncoder()
.encodeDeclineMessage(m.getGroupId(), m.getTimestamp() + 1,
m.getMessageId(), m.getSessionId());
c1.getClientHelper().addLocalMessage(msg, new BdfDictionary(), true);
// sync fake DECLINE back to introducer
sync1To0(1, true);
assertTrue(listener0.aborted);
}
/**
* One introducee sends two AUTH messages.
* The introducer should notice this and ABORT the session.
@@ -1093,6 +1129,9 @@ public class IntroductionIntegrationTest
if (type == ACCEPT) {
//noinspection ConstantConditions
return c0.getMessageParser().parseAcceptMessage(m, body);
} else if (type == DECLINE) {
//noinspection ConstantConditions
return c0.getMessageParser().parseDeclineMessage(m, body);
} else if (type == AUTH) {
//noinspection ConstantConditions
return c0.getMessageParser().parseAuthMessage(m, body);

View File

@@ -268,6 +268,21 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInvalidPreviousMsgIdForAuth() throws Exception {
BdfList body = BdfList.of(AUTH.getValue(), sessionId.getBytes(),
1, getRandomBytes(MAC_BYTES),
signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsPreviousMsgIdNullForAuth() throws Exception {
BdfList body = BdfList.of(AUTH.getValue(), sessionId.getBytes(), null,
getRandomBytes(MAC_BYTES), signature);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsTooShortMacForAuth() throws Exception {
BdfList body = BdfList.of(AUTH.getValue(), sessionId.getBytes(),
@@ -358,6 +373,14 @@ public class IntroductionValidatorTest extends ValidatorTestCase {
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsPreviousMsgIdNullForActivate() throws Exception {
BdfList body =
BdfList.of(ACTIVATE.getValue(), sessionId.getBytes(), null,
mac);
validator.validateMessage(message, group, body);
}
@Test(expected = FormatException.class)
public void testRejectsInvalidMacForActivate() throws Exception {
BdfList body = BdfList.of(ACTIVATE.getValue(), sessionId.getBytes(),