mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Added more private group invitation validation tests.
This commit is contained in:
@@ -42,199 +42,276 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
|||||||
private final MessageEncoder messageEncoder =
|
private final MessageEncoder messageEncoder =
|
||||||
context.mock(MessageEncoder.class);
|
context.mock(MessageEncoder.class);
|
||||||
|
|
||||||
private final String groupName = "Group Name";
|
private final String groupName = getRandomString(MAX_GROUP_NAME_LENGTH);
|
||||||
private final String creatorName = "Creator Name";
|
private final String creatorName = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||||
private final byte[] creatorKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
private final byte[] creatorKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||||
private final Author creator =
|
private final Author creator =
|
||||||
new Author(new AuthorId(getRandomId()), creatorName, creatorKey);
|
new Author(new AuthorId(getRandomId()), creatorName, creatorKey);
|
||||||
private final byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
|
private final byte[] salt = getRandomBytes(GROUP_SALT_LENGTH);
|
||||||
private final PrivateGroup privateGroup =
|
private final PrivateGroup privateGroup =
|
||||||
new PrivateGroup(group, groupName, creator, salt);
|
new PrivateGroup(group, groupName, creator, salt);
|
||||||
private final String inviteText = "Invitation Text";
|
private final String inviteText =
|
||||||
|
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH);
|
||||||
private final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
|
private final byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH);
|
||||||
private final BdfDictionary meta =
|
private final BdfDictionary meta =
|
||||||
BdfDictionary.of(new BdfEntry("meta", "data"));
|
BdfDictionary.of(new BdfEntry("meta", "data"));
|
||||||
private final MessageId previousMessageId = new MessageId(getRandomId());
|
private final MessageId previousMessageId = new MessageId(getRandomId());
|
||||||
|
|
||||||
private GroupInvitationValidator validator =
|
private final GroupInvitationValidator validator =
|
||||||
new GroupInvitationValidator(clientHelper, metadataEncoder,
|
new GroupInvitationValidator(clientHelper, metadataEncoder,
|
||||||
clock, authorFactory, privateGroupFactory, messageEncoder);
|
clock, authorFactory, privateGroupFactory, messageEncoder);
|
||||||
|
|
||||||
|
// INVITE Message
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooShortInviteMessage() throws Exception {
|
public void testRejectsTooShortInviteMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, salt, inviteText);
|
creatorKey, salt, inviteText);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooLongInviteMessage() throws Exception {
|
public void testRejectsTooLongInviteMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, salt, inviteText, signature, "");
|
creatorKey, salt, inviteText, signature, "");
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithTooShortGroupName()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), "", creatorName,
|
||||||
|
creatorKey, salt, inviteText, signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithTooLongGroupName()
|
public void testRejectsInviteMessageWithTooLongGroupName()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(),
|
BdfList body = BdfList.of(INVITE.getValue(),
|
||||||
getRandomString(MAX_GROUP_NAME_LENGTH + 1), creatorName,
|
getRandomString(MAX_GROUP_NAME_LENGTH + 1), creatorName,
|
||||||
creatorKey, salt, inviteText, signature);
|
creatorKey, salt, inviteText, signature);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithEmptyGroupName()
|
public void testRejectsInviteMessageWithNullGroupName()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), "", creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), null, creatorName,
|
||||||
creatorKey, salt, inviteText, signature);
|
creatorKey, salt, inviteText, signature);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithNonStringGroupName()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), getRandomBytes(5),
|
||||||
|
creatorName, creatorKey, salt, inviteText, signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithTooShortCreatorName()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, "", creatorKey,
|
||||||
|
salt, inviteText, signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithTooLongCreatorName()
|
public void testRejectsInviteMessageWithTooLongCreatorName()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName,
|
||||||
getRandomString(MAX_AUTHOR_NAME_LENGTH + 1), creatorKey, salt,
|
getRandomString(MAX_AUTHOR_NAME_LENGTH + 1), creatorKey, salt,
|
||||||
inviteText, signature);
|
inviteText, signature);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithEmptyCreatorName()
|
public void testRejectsInviteMessageWithNullCreatorName()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list =
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, null,
|
||||||
BdfList.of(INVITE.getValue(), groupName, "", creatorKey, salt,
|
creatorKey, salt, inviteText, signature);
|
||||||
inviteText, signature);
|
validator.validateMessage(message, group, body);
|
||||||
validator.validateMessage(message, group, list);
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithNonStringCreatorName()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName,
|
||||||
|
getRandomBytes(5), creatorKey, salt, inviteText, signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithTooShortCreatorKey()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
new byte[0], salt, inviteText, signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithTooLongCreatorKey()
|
public void testRejectsInviteMessageWithTooLongCreatorKey()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
getRandomBytes(MAX_PUBLIC_KEY_LENGTH + 1), salt, inviteText,
|
getRandomBytes(MAX_PUBLIC_KEY_LENGTH + 1), salt, inviteText,
|
||||||
signature);
|
signature);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithEmptyCreatorKey()
|
public void testRejectsInviteMessageWithNullCreatorKey()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
new byte[0], salt, inviteText, signature);
|
null, salt, inviteText, signature);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithTooLongGroupSalt()
|
public void testRejectsInviteMessageWithNonRawCreatorKey()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, getRandomBytes(GROUP_SALT_LENGTH + 1), inviteText,
|
"not raw", salt, inviteText, signature);
|
||||||
signature);
|
validator.validateMessage(message, group, body);
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithTooShortGroupSalt()
|
public void testRejectsInviteMessageWithTooShortGroupSalt()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, getRandomBytes(GROUP_SALT_LENGTH - 1), inviteText,
|
creatorKey, getRandomBytes(GROUP_SALT_LENGTH - 1), inviteText,
|
||||||
signature);
|
signature);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithTooLongMessage()
|
public void testRejectsInviteMessageWithTooLongGroupSalt()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
creatorKey, getRandomBytes(GROUP_SALT_LENGTH + 1), inviteText,
|
||||||
|
signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithNullGroupSalt()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
creatorKey, null, inviteText, signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithNonRawGroupSalt()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
creatorKey, "not raw", inviteText, signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithTooShortContent() throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
creatorKey, salt, "", signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithTooLongContent() throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, salt,
|
creatorKey, salt,
|
||||||
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH + 1),
|
getRandomString(MAX_GROUP_INVITATION_MSG_LENGTH + 1),
|
||||||
signature);
|
signature);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAcceptsInviteMessageWithNullContent() throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
creatorKey, salt, null, signature);
|
||||||
|
expectInviteMessage(false);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithNonStringContent()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
creatorKey, salt, getRandomBytes(5), signature);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsInviteMessageWithTooShortSignature()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
|
creatorKey, salt, inviteText, new byte[0]);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithTooLongSignature()
|
public void testRejectsInviteMessageWithTooLongSignature()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, salt, inviteText,
|
creatorKey, salt, inviteText,
|
||||||
getRandomBytes(MAX_SIGNATURE_LENGTH + 1));
|
getRandomBytes(MAX_SIGNATURE_LENGTH + 1));
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
|
||||||
public void testRejectsInviteMessageWithEmptySignature()
|
|
||||||
throws Exception {
|
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
|
||||||
creatorKey, salt, inviteText, new byte[0]);
|
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithNullSignature()
|
public void testRejectsInviteMessageWithNullSignature()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, salt, inviteText, null);
|
creatorKey, salt, inviteText, null);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithNonRawSignature()
|
public void testRejectsInviteMessageWithNonRawSignature()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
creatorKey, salt, inviteText, "non raw signature");
|
creatorKey, salt, inviteText, "not raw");
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAcceptsInviteMessageWithNullMessage()
|
|
||||||
throws Exception {
|
|
||||||
expectInviteMessage(false);
|
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
|
||||||
creatorKey, salt, null, signature);
|
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsInviteMessageWithInvalidSignature()
|
public void testRejectsInviteMessageWithInvalidSignature()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
expectInviteMessage(true);
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
|
||||||
creatorKey, salt, null, signature);
|
creatorKey, salt, null, signature);
|
||||||
validator.validateMessage(message, group, list);
|
expectInviteMessage(true);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptsProperInviteMessage()
|
public void testAcceptsValidInviteMessage() throws Exception {
|
||||||
throws Exception {
|
BdfList body = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
||||||
expectInviteMessage(false);
|
|
||||||
BdfList list = BdfList.of(INVITE.getValue(), groupName, creatorName,
|
|
||||||
creatorKey, salt, inviteText, signature);
|
creatorKey, salt, inviteText, signature);
|
||||||
|
expectInviteMessage(false);
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
assertTrue(messageContext.getDependencies().isEmpty());
|
assertTrue(messageContext.getDependencies().isEmpty());
|
||||||
assertEquals(meta ,messageContext.getDictionary());
|
assertEquals(meta, messageContext.getDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectInviteMessage(final boolean exception) throws Exception {
|
private void expectInviteMessage(final boolean exception) throws Exception {
|
||||||
final BdfList toSign =
|
final BdfList signed = BdfList.of(message.getTimestamp(),
|
||||||
BdfList.of(message.getTimestamp(), message.getGroupId(),
|
message.getGroupId(), privateGroup.getId());
|
||||||
privateGroup.getId());
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(authorFactory).createAuthor(creatorName, creatorKey);
|
oneOf(authorFactory).createAuthor(creatorName, creatorKey);
|
||||||
will(returnValue(creator));
|
will(returnValue(creator));
|
||||||
oneOf(privateGroupFactory)
|
oneOf(privateGroupFactory).createPrivateGroup(groupName, creator,
|
||||||
.createPrivateGroup(groupName, creator, salt);
|
salt);
|
||||||
will(returnValue(privateGroup));
|
will(returnValue(privateGroup));
|
||||||
oneOf(clientHelper).verifySignature(SIGNING_LABEL_INVITE, signature,
|
oneOf(clientHelper).verifySignature(SIGNING_LABEL_INVITE, signature,
|
||||||
creatorKey, toSign);
|
creatorKey, signed);
|
||||||
if (exception) will(throwException(new GeneralSecurityException()));
|
if (exception) {
|
||||||
else {
|
will(throwException(new GeneralSecurityException()));
|
||||||
oneOf(messageEncoder)
|
} else {
|
||||||
.encodeMetadata(INVITE, message.getGroupId(),
|
oneOf(messageEncoder).encodeMetadata(INVITE,
|
||||||
message.getTimestamp(), false, false, false,
|
message.getGroupId(), message.getTimestamp(), false,
|
||||||
false);
|
false, false, false);
|
||||||
will(returnValue(meta));
|
will(returnValue(meta));
|
||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
@@ -244,181 +321,262 @@ public class GroupInvitationValidatorTest extends ValidatorTestCase {
|
|||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooShortJoinMessage() throws Exception {
|
public void testRejectsTooShortJoinMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(JOIN.getValue(), privateGroup.getId());
|
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId());
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooLongJoinMessage() throws Exception {
|
public void testRejectsTooLongJoinMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
||||||
previousMessageId, "");
|
previousMessageId, "");
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
|
||||||
public void testRejectsJoinMessageWithTooLongGroupId() throws Exception {
|
|
||||||
BdfList list =
|
|
||||||
BdfList.of(JOIN.getValue(), getRandomBytes(GroupId.LENGTH + 1),
|
|
||||||
previousMessageId);
|
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsJoinMessageWithTooShortGroupId() throws Exception {
|
public void testRejectsJoinMessageWithTooShortGroupId() throws Exception {
|
||||||
BdfList list =
|
BdfList body = BdfList.of(JOIN.getValue(),
|
||||||
BdfList.of(JOIN.getValue(), getRandomBytes(GroupId.LENGTH - 1),
|
getRandomBytes(GroupId.LENGTH - 1), previousMessageId);
|
||||||
previousMessageId);
|
validator.validateMessage(message, group, body);
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsJoinMessageWithTooLongPreviousMessageId()
|
public void testRejectsJoinMessageWithTooLongGroupId() throws Exception {
|
||||||
throws Exception {
|
BdfList body = BdfList.of(JOIN.getValue(),
|
||||||
BdfList list = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
getRandomBytes(GroupId.LENGTH + 1), previousMessageId);
|
||||||
getRandomBytes(UniqueId.LENGTH + 1));
|
validator.validateMessage(message, group, body);
|
||||||
validator.validateMessage(message, group, list);
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsJoinMessageWithNullGroupId() throws Exception {
|
||||||
|
BdfList body = BdfList.of(JOIN.getValue(), null, previousMessageId);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsJoinMessageWithNonRawGroupId() throws Exception {
|
||||||
|
BdfList body = BdfList.of(JOIN.getValue(), "not raw",
|
||||||
|
previousMessageId);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsJoinMessageWithTooShortPreviousMessageId()
|
public void testRejectsJoinMessageWithTooShortPreviousMessageId()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
||||||
getRandomBytes(UniqueId.LENGTH - 1));
|
getRandomBytes(UniqueId.LENGTH - 1));
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsJoinMessageWithTooLongPreviousMessageId()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
||||||
|
getRandomBytes(UniqueId.LENGTH + 1));
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsJoinMessageWithNonRawPreviousMessageId()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
||||||
|
"not raw");
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptsProperJoinMessage()
|
public void testAcceptsJoinMessageWithNullPreviousMessageId()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId(), null);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(messageEncoder)
|
oneOf(messageEncoder).encodeMetadata(JOIN, message.getGroupId(),
|
||||||
.encodeMetadata(JOIN, message.getGroupId(),
|
message.getTimestamp(), false, false, false, false);
|
||||||
message.getTimestamp(), false, false, false,
|
|
||||||
false);
|
|
||||||
will(returnValue(meta));
|
will(returnValue(meta));
|
||||||
}});
|
}});
|
||||||
BdfList list = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
|
||||||
previousMessageId);
|
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
assertEquals(0, messageContext.getDependencies().size());
|
||||||
|
assertEquals(meta, messageContext.getDictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAcceptsValidJoinMessage() throws Exception {
|
||||||
|
BdfList body = BdfList.of(JOIN.getValue(), privateGroup.getId(),
|
||||||
|
previousMessageId);
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(messageEncoder).encodeMetadata(JOIN, message.getGroupId(),
|
||||||
|
message.getTimestamp(), false, false, false, false);
|
||||||
|
will(returnValue(meta));
|
||||||
|
}});
|
||||||
|
BdfMessageContext messageContext =
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
assertEquals(1, messageContext.getDependencies().size());
|
assertEquals(1, messageContext.getDependencies().size());
|
||||||
assertEquals(previousMessageId,
|
assertEquals(previousMessageId,
|
||||||
messageContext.getDependencies().iterator().next());
|
messageContext.getDependencies().iterator().next());
|
||||||
assertEquals(meta ,messageContext.getDictionary());
|
assertEquals(meta, messageContext.getDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
// LEAVE message
|
// LEAVE message
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooShortLeaveMessage() throws Exception {
|
public void testRejectsTooShortLeaveMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(LEAVE.getValue(), privateGroup.getId());
|
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId());
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooLongLeaveMessage() throws Exception {
|
public void testRejectsTooLongLeaveMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
||||||
previousMessageId, "");
|
previousMessageId, "");
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
|
||||||
public void testRejectsLeaveMessageWithTooLongGroupId() throws Exception {
|
|
||||||
BdfList list =
|
|
||||||
BdfList.of(LEAVE.getValue(), getRandomBytes(GroupId.LENGTH + 1),
|
|
||||||
previousMessageId);
|
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsLeaveMessageWithTooShortGroupId() throws Exception {
|
public void testRejectsLeaveMessageWithTooShortGroupId() throws Exception {
|
||||||
BdfList list =
|
BdfList body = BdfList.of(LEAVE.getValue(),
|
||||||
BdfList.of(LEAVE.getValue(), getRandomBytes(GroupId.LENGTH - 1),
|
getRandomBytes(GroupId.LENGTH - 1), previousMessageId);
|
||||||
previousMessageId);
|
validator.validateMessage(message, group, body);
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsLeaveMessageWithTooLongPreviousMessageId()
|
public void testRejectsLeaveMessageWithTooLongGroupId() throws Exception {
|
||||||
throws Exception {
|
BdfList body = BdfList.of(LEAVE.getValue(),
|
||||||
BdfList list = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
getRandomBytes(GroupId.LENGTH + 1), previousMessageId);
|
||||||
getRandomBytes(UniqueId.LENGTH + 1));
|
validator.validateMessage(message, group, body);
|
||||||
validator.validateMessage(message, group, list);
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsLeaveMessageWithNullGroupId() throws Exception {
|
||||||
|
BdfList body = BdfList.of(LEAVE.getValue(), null, previousMessageId);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsLeaveMessageWithNonRawGroupId() throws Exception {
|
||||||
|
BdfList body = BdfList.of(LEAVE.getValue(), "not raw",
|
||||||
|
previousMessageId);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsLeaveMessageWithTooShortPreviousMessageId()
|
public void testRejectsLeaveMessageWithTooShortPreviousMessageId()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
BdfList list = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
||||||
getRandomBytes(UniqueId.LENGTH - 1));
|
getRandomBytes(UniqueId.LENGTH - 1));
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsLeaveMessageWithTooLongPreviousMessageId()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
||||||
|
getRandomBytes(UniqueId.LENGTH + 1));
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsLeaveMessageWithNonRawPreviousMessageId()
|
||||||
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
||||||
|
"not raw");
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptsProperLeaveMessage()
|
public void testAcceptsLeaveMessageWithNullPreviousMessageId()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(), null);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(messageEncoder).encodeMetadata(LEAVE, message.getGroupId(),
|
oneOf(messageEncoder).encodeMetadata(LEAVE, message.getGroupId(),
|
||||||
message.getTimestamp(), false, false, false, false);
|
message.getTimestamp(), false, false, false, false);
|
||||||
will(returnValue(meta));
|
will(returnValue(meta));
|
||||||
}});
|
}});
|
||||||
BdfList list = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
BdfMessageContext messageContext =
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
assertEquals(0, messageContext.getDependencies().size());
|
||||||
|
assertEquals(meta, messageContext.getDictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAcceptsValidLeaveMessage() throws Exception {
|
||||||
|
context.checking(new Expectations() {{
|
||||||
|
oneOf(messageEncoder).encodeMetadata(LEAVE, message.getGroupId(),
|
||||||
|
message.getTimestamp(), false, false, false, false);
|
||||||
|
will(returnValue(meta));
|
||||||
|
}});
|
||||||
|
BdfList body = BdfList.of(LEAVE.getValue(), privateGroup.getId(),
|
||||||
previousMessageId);
|
previousMessageId);
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
assertEquals(1, messageContext.getDependencies().size());
|
assertEquals(1, messageContext.getDependencies().size());
|
||||||
assertEquals(previousMessageId,
|
assertEquals(previousMessageId,
|
||||||
messageContext.getDependencies().iterator().next());
|
messageContext.getDependencies().iterator().next());
|
||||||
assertEquals(meta ,messageContext.getDictionary());
|
assertEquals(meta, messageContext.getDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ABORT message
|
// ABORT message
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooShortAbortMessage() throws Exception {
|
public void testRejectsTooShortAbortMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(ABORT.getValue());
|
BdfList body = BdfList.of(ABORT.getValue());
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsTooLongAbortMessage() throws Exception {
|
public void testRejectsTooLongAbortMessage() throws Exception {
|
||||||
BdfList list = BdfList.of(ABORT.getValue(), privateGroup.getId(), "");
|
BdfList body = BdfList.of(ABORT.getValue(), privateGroup.getId(), "");
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
|
||||||
public void testRejectsAbortMessageWithTooLongGroupId() throws Exception {
|
|
||||||
BdfList list = BdfList.of(ABORT.getValue(),
|
|
||||||
getRandomBytes(GroupId.LENGTH + 1));
|
|
||||||
validator.validateMessage(message, group, list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsAbortMessageWithTooShortGroupId() throws Exception {
|
public void testRejectsAbortMessageWithTooShortGroupId() throws Exception {
|
||||||
BdfList list = BdfList.of(ABORT.getValue(),
|
BdfList body = BdfList.of(ABORT.getValue(),
|
||||||
getRandomBytes(GroupId.LENGTH - 1));
|
getRandomBytes(GroupId.LENGTH - 1));
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsAbortMessageWithTooLongGroupId() throws Exception {
|
||||||
|
BdfList body = BdfList.of(ABORT.getValue(),
|
||||||
|
getRandomBytes(GroupId.LENGTH + 1));
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsAbortMessageWithNullGroupId() throws Exception {
|
||||||
|
BdfList body = BdfList.of(ABORT.getValue(), null);
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsAbortMessageWithNonRawGroupId() throws Exception {
|
||||||
|
BdfList body = BdfList.of(ABORT.getValue(), "not raw");
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAcceptsProperAbortMessage()
|
public void testAcceptsValidAbortMessage() throws Exception {
|
||||||
throws Exception {
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(messageEncoder).encodeMetadata(ABORT, message.getGroupId(),
|
oneOf(messageEncoder).encodeMetadata(ABORT, message.getGroupId(),
|
||||||
message.getTimestamp(), false, false, false, false);
|
message.getTimestamp(), false, false, false, false);
|
||||||
will(returnValue(meta));
|
will(returnValue(meta));
|
||||||
}});
|
}});
|
||||||
BdfList list = BdfList.of(ABORT.getValue(), privateGroup.getId());
|
BdfList body = BdfList.of(ABORT.getValue(), privateGroup.getId());
|
||||||
BdfMessageContext messageContext =
|
BdfMessageContext messageContext =
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
assertEquals(0, messageContext.getDependencies().size());
|
assertEquals(0, messageContext.getDependencies().size());
|
||||||
assertEquals(meta ,messageContext.getDictionary());
|
assertEquals(meta, messageContext.getDictionary());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = FormatException.class)
|
@Test(expected = FormatException.class)
|
||||||
public void testRejectsMessageWithUnknownType() throws Exception {
|
public void testRejectsMessageWithUnknownType() throws Exception {
|
||||||
BdfList list = BdfList.of(ABORT.getValue() + 1);
|
BdfList body = BdfList.of(ABORT.getValue() + 1);
|
||||||
validator.validateMessage(message, group, list);
|
validator.validateMessage(message, group, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FormatException.class)
|
||||||
|
public void testRejectsEmptyMessage() throws Exception {
|
||||||
|
BdfList body = new BdfList();
|
||||||
|
validator.validateMessage(message, group, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user