mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 23:29:52 +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
|
@Override
|
||||||
public boolean incomingMessage(Transaction txn, Message m, Metadata meta)
|
public boolean incomingMessage(Transaction txn, Message m, Metadata meta)
|
||||||
throws DbException, InvalidMessageException {
|
throws DbException, InvalidMessageException {
|
||||||
|
Group ourGroup = getOurGroup(txn);
|
||||||
|
if (m.getGroupId().equals(ourGroup.getId())) {
|
||||||
|
throw new InvalidMessageException(
|
||||||
|
"Received incoming message in my avatar group");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Find the latest update, if any
|
// Find the latest update, if any
|
||||||
BdfDictionary d = metadataParser.parse(meta);
|
BdfDictionary d = metadataParser.parse(meta);
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
|||||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expectGetOurGroup(txn);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(metadataParser).parse(meta);
|
oneOf(metadataParser).parse(meta);
|
||||||
will(returnValue(d));
|
will(returnValue(d));
|
||||||
@@ -211,6 +212,7 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
|||||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expectGetOurGroup(txn);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(metadataParser).parse(meta);
|
oneOf(metadataParser).parse(meta);
|
||||||
will(returnValue(d));
|
will(returnValue(d));
|
||||||
@@ -241,6 +243,7 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
|||||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expectGetOurGroup(txn);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(metadataParser).parse(meta);
|
oneOf(metadataParser).parse(meta);
|
||||||
will(returnValue(d));
|
will(returnValue(d));
|
||||||
@@ -256,6 +259,14 @@ public class AvatarManagerImplTest extends BrambleMockTestCase {
|
|||||||
assertEquals(0, txn.getActions().size());
|
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
|
@Test
|
||||||
public void testAddAvatar() throws Exception {
|
public void testAddAvatar() throws Exception {
|
||||||
byte[] avatarBytes = getRandomBytes(42);
|
byte[] avatarBytes = getRandomBytes(42);
|
||||||
|
|||||||
Reference in New Issue
Block a user