mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-22 07:39:53 +01:00
Address review comments
This commit is contained in:
@@ -315,7 +315,7 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongJoinMessages() throws Exception {
|
public void testWrongJoinMessages1() throws Exception {
|
||||||
addDefaultIdentities();
|
addDefaultIdentities();
|
||||||
addDefaultContacts();
|
addDefaultContacts();
|
||||||
listenToEvents();
|
listenToEvents();
|
||||||
@@ -377,15 +377,24 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongJoinMessageSignature() throws Exception {
|
public void testWrongJoinMessages2() throws Exception {
|
||||||
addDefaultIdentities();
|
addDefaultIdentities();
|
||||||
addDefaultContacts();
|
addDefaultContacts();
|
||||||
listenToEvents();
|
listenToEvents();
|
||||||
|
|
||||||
// author0 joins privateGroup0 properly
|
// author0 joins privateGroup0 with wrong member's join message
|
||||||
long joinTime = clock.currentTimeMillis();
|
long joinTime = clock.currentTimeMillis();
|
||||||
|
long inviteTime = joinTime - 1;
|
||||||
|
Group invitationGroup = contactGroupFactory
|
||||||
|
.createContactGroup(groupInvitationManager.getClientId(),
|
||||||
|
author0.getId(), author0.getId());
|
||||||
|
BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(),
|
||||||
|
privateGroup0.getId());
|
||||||
|
byte[] creatorSignature =
|
||||||
|
clientHelper.sign(toSign, author0.getPrivateKey());
|
||||||
GroupMessage joinMsg0 = groupMessageFactory
|
GroupMessage joinMsg0 = groupMessageFactory
|
||||||
.createJoinMessage(privateGroup0.getId(), joinTime, author0);
|
.createJoinMessage(privateGroup0.getId(), joinTime, author0,
|
||||||
|
inviteTime, creatorSignature);
|
||||||
groupManager0.addPrivateGroup(privateGroup0, joinMsg0);
|
groupManager0.addPrivateGroup(privateGroup0, joinMsg0);
|
||||||
assertEquals(joinMsg0.getMessage().getId(),
|
assertEquals(joinMsg0.getMessage().getId(),
|
||||||
groupManager0.getPreviousMsgId(groupId0));
|
groupManager0.getPreviousMsgId(groupId0));
|
||||||
@@ -395,19 +404,18 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
t0.getDatabaseComponent()
|
t0.getDatabaseComponent()
|
||||||
.setVisibleToContact(txn0, contactId1, privateGroup0.getId(),
|
.setVisibleToContact(txn0, contactId1, privateGroup0.getId(),
|
||||||
true);
|
true);
|
||||||
txn0.setComplete();
|
t0.getDatabaseComponent().commitTransaction(txn0);
|
||||||
t0.getDatabaseComponent().endTransaction(txn0);
|
t0.getDatabaseComponent().endTransaction(txn0);
|
||||||
|
|
||||||
// author1 joins privateGroup0 with wrong timestamp
|
// author1 joins privateGroup0 with wrong own signature
|
||||||
joinTime = clock.currentTimeMillis();
|
joinTime = clock.currentTimeMillis();
|
||||||
long inviteTime = joinTime - 1;
|
inviteTime = joinTime - 1;
|
||||||
Group invitationGroup = contactGroupFactory
|
invitationGroup = contactGroupFactory
|
||||||
.createContactGroup(groupInvitationManager.getClientId(),
|
.createContactGroup(groupInvitationManager.getClientId(),
|
||||||
author0.getId(), author1.getId());
|
author0.getId(), author1.getId());
|
||||||
BdfList toSign = BdfList.of(0, inviteTime, invitationGroup.getId(),
|
toSign = BdfList.of(0, inviteTime, invitationGroup.getId(),
|
||||||
privateGroup0.getId());
|
privateGroup0.getId());
|
||||||
byte[] creatorSignature =
|
creatorSignature = clientHelper.sign(toSign, author1.getPrivateKey());
|
||||||
clientHelper.sign(toSign, author1.getPrivateKey());
|
|
||||||
GroupMessage joinMsg1 = groupMessageFactory
|
GroupMessage joinMsg1 = groupMessageFactory
|
||||||
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
.createJoinMessage(privateGroup0.getId(), joinTime, author1,
|
||||||
inviteTime, creatorSignature);
|
inviteTime, creatorSignature);
|
||||||
@@ -420,15 +428,15 @@ public class PrivateGroupManagerTest extends BriarIntegrationTest {
|
|||||||
t1.getDatabaseComponent()
|
t1.getDatabaseComponent()
|
||||||
.setVisibleToContact(txn1, contactId0, privateGroup0.getId(),
|
.setVisibleToContact(txn1, contactId0, privateGroup0.getId(),
|
||||||
true);
|
true);
|
||||||
txn1.setComplete();
|
t1.getDatabaseComponent().commitTransaction(txn1);
|
||||||
t1.getDatabaseComponent().endTransaction(txn1);
|
t1.getDatabaseComponent().endTransaction(txn1);
|
||||||
|
|
||||||
// sync join messages
|
// sync join messages
|
||||||
sync0To1();
|
sync0To1();
|
||||||
deliveryWaiter.await(TIMEOUT, 1);
|
validationWaiter.await(TIMEOUT, 1);
|
||||||
|
|
||||||
// assert that 0 never joined the group from 1's perspective
|
// assert that 0 never joined the group from 1's perspective
|
||||||
assertEquals(2, groupManager1.getHeaders(groupId0).size());
|
assertEquals(1, groupManager1.getHeaders(groupId0).size());
|
||||||
|
|
||||||
sync1To0();
|
sync1To0();
|
||||||
validationWaiter.await(TIMEOUT, 1);
|
validationWaiter.await(TIMEOUT, 1);
|
||||||
|
|||||||
@@ -102,11 +102,14 @@ class GroupMessageValidator extends BdfMessageValidator {
|
|||||||
PrivateGroup pg = groupFactory.parsePrivateGroup(g);
|
PrivateGroup pg = groupFactory.parsePrivateGroup(g);
|
||||||
|
|
||||||
// invite is null if the member is the creator of the private group
|
// invite is null if the member is the creator of the private group
|
||||||
BdfList invite = body.getList(3, null);
|
BdfList invite = body.getOptionalList(3);
|
||||||
if (invite == null) {
|
if (invite == null) {
|
||||||
if (!member.equals(pg.getAuthor()))
|
if (!member.equals(pg.getAuthor()))
|
||||||
throw new InvalidMessageException();
|
throw new InvalidMessageException();
|
||||||
} else {
|
} else {
|
||||||
|
if (member.equals(pg.getAuthor()))
|
||||||
|
throw new InvalidMessageException();
|
||||||
|
|
||||||
// Otherwise invite is a list with two elements
|
// Otherwise invite is a list with two elements
|
||||||
checkSize(invite, 2);
|
checkSize(invite, 2);
|
||||||
|
|
||||||
@@ -164,7 +167,7 @@ class GroupMessageValidator extends BdfMessageValidator {
|
|||||||
Author member)
|
Author member)
|
||||||
throws InvalidMessageException, FormatException {
|
throws InvalidMessageException, FormatException {
|
||||||
|
|
||||||
// The content is a BDF list with six elements
|
// The content is a BDF list with seven elements
|
||||||
checkSize(body, 7);
|
checkSize(body, 7);
|
||||||
|
|
||||||
// parent_id (raw or null)
|
// parent_id (raw or null)
|
||||||
|
|||||||
Reference in New Issue
Block a user