Ensure that attachment has expected group ID when loading.

This commit is contained in:
akwizgran
2021-01-22 13:29:29 +00:00
parent cae53a9fcc
commit aed5ac5bb4
11 changed files with 186 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
package org.briarproject.briar.api.attachment;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
import javax.annotation.concurrent.Immutable;
@@ -9,14 +10,21 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public class AttachmentHeader {
private final GroupId groupId;
private final MessageId messageId;
private final String contentType;
public AttachmentHeader(MessageId messageId, String contentType) {
public AttachmentHeader(GroupId groupId, MessageId messageId,
String contentType) {
this.groupId = groupId;
this.messageId = messageId;
this.contentType = contentType;
}
public GroupId getGroupId() {
return groupId;
}
public MessageId getMessageId() {
return messageId;
}
@@ -27,13 +35,15 @@ public class AttachmentHeader {
@Override
public boolean equals(Object o) {
return o instanceof AttachmentHeader &&
messageId.equals(((AttachmentHeader) o).messageId);
if (o instanceof AttachmentHeader) {
AttachmentHeader h = (AttachmentHeader) o;
return groupId.equals(h.groupId) && messageId.equals(h.messageId);
}
return false;
}
@Override
public int hashCode() {
return messageId.hashCode();
}
}

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.api.identity;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.test.BrambleTestCase;
import org.briarproject.briar.api.attachment.AttachmentHeader;
@@ -17,7 +18,8 @@ public class AuthorInfoTest extends BrambleTestCase {
private final String contentType = getRandomString(MAX_CONTENT_TYPE_BYTES);
private final AttachmentHeader avatarHeader =
new AttachmentHeader(new MessageId(getRandomId()), contentType);
new AttachmentHeader(new GroupId(getRandomId()),
new MessageId(getRandomId()), contentType);
@Test
public void testEquals() {