mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Throw NoSuchMessageException if attachment is invalid.
This commit is contained in:
@@ -10,7 +10,6 @@ import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.attachment.Attachment;
|
||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||
import org.briarproject.briar.api.attachment.AttachmentReader;
|
||||
import org.briarproject.briar.api.attachment.InvalidAttachmentException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -44,13 +43,13 @@ public class AttachmentReaderImpl implements AttachmentReader {
|
||||
BdfDictionary meta = clientHelper.getMessageMetadataAsDictionary(m);
|
||||
String contentType = meta.getString(MSG_KEY_CONTENT_TYPE);
|
||||
if (!contentType.equals(h.getContentType()))
|
||||
throw new InvalidAttachmentException();
|
||||
throw new NoSuchMessageException();
|
||||
int offset = meta.getLong(MSG_KEY_DESCRIPTOR_LENGTH).intValue();
|
||||
InputStream stream = new ByteArrayInputStream(body, offset,
|
||||
body.length - offset);
|
||||
return new Attachment(h, stream);
|
||||
} catch (FormatException e) {
|
||||
throw new InvalidAttachmentException(e);
|
||||
throw new NoSuchMessageException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.briarproject.bramble.api.sync.Message;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.briar.api.attachment.Attachment;
|
||||
import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||
import org.briarproject.briar.api.attachment.InvalidAttachmentException;
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -51,14 +50,14 @@ public class AttachmentReaderImplTest extends BrambleMockTestCase {
|
||||
attachmentReader.getAttachment(wrongGroup);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAttachmentException.class)
|
||||
@Test(expected = NoSuchMessageException.class)
|
||||
public void testMissingContentType() throws Exception {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
|
||||
testInvalidMetadata(meta);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAttachmentException.class)
|
||||
@Test(expected = NoSuchMessageException.class)
|
||||
public void testWrongContentType() throws Exception {
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, "image/png"));
|
||||
@@ -66,7 +65,7 @@ public class AttachmentReaderImplTest extends BrambleMockTestCase {
|
||||
testInvalidMetadata(meta);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidAttachmentException.class)
|
||||
@Test(expected = NoSuchMessageException.class)
|
||||
public void testMissingDescriptorLength() throws Exception {
|
||||
BdfDictionary meta = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_CONTENT_TYPE, contentType));
|
||||
|
||||
Reference in New Issue
Block a user