mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Don't accept incoming messages in our own avatar group
This commit is contained in:
@@ -135,6 +135,11 @@ class AvatarManagerImpl implements AvatarManager, OpenDatabaseHook, ContactHook,
|
||||
@Override
|
||||
public boolean incomingMessage(Transaction txn, Message m, Metadata meta)
|
||||
throws DbException, InvalidMessageException {
|
||||
Group ourGroup = getOurGroup(txn);
|
||||
if (m.getGroupId().equals(ourGroup.getId())) {
|
||||
throw new InvalidMessageException(
|
||||
"Received incoming message in my avatar group");
|
||||
}
|
||||
try {
|
||||
// Find the latest update, if any
|
||||
BdfDictionary d = metadataParser.parse(meta);
|
||||
|
||||
@@ -180,6 +180,7 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
||||
);
|
||||
|
||||
expectGetOurGroup(txn);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(metadataParser).parse(meta);
|
||||
will(returnValue(d));
|
||||
@@ -211,6 +212,7 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
||||
);
|
||||
|
||||
expectGetOurGroup(txn);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(metadataParser).parse(meta);
|
||||
will(returnValue(d));
|
||||
@@ -241,6 +243,7 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
||||
);
|
||||
|
||||
expectGetOurGroup(txn);
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(metadataParser).parse(meta);
|
||||
will(returnValue(d));
|
||||
@@ -256,6 +259,14 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
||||
assertEquals(0, txn.getActions().size());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidMessageException.class)
|
||||
public void testIncomingMessageInOwnGroup()
|
||||
throws DbException, InvalidMessageException, FormatException {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
expectGetOurGroup(txn);
|
||||
avatarManager.incomingMessage(txn, ourMsg, meta);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAvatar() throws Exception {
|
||||
byte[] avatarBytes = getRandomBytes(42);
|
||||
|
||||
Reference in New Issue
Block a user