mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Variable-length frames (untested).
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package org.briarproject.transport;
|
||||
|
||||
import static org.briarproject.api.transport.TransportConstants.HEADER_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAC_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAX_FRAME_LENGTH;
|
||||
import static org.briarproject.api.transport.TransportConstants.MAX_PAYLOAD_LENGTH;
|
||||
|
||||
import org.briarproject.BriarTestCase;
|
||||
import org.briarproject.api.crypto.StreamEncrypter;
|
||||
@@ -12,9 +10,6 @@ import org.junit.Test;
|
||||
|
||||
public class StreamWriterImplTest extends BriarTestCase {
|
||||
|
||||
private static final int MAX_PAYLOAD_LENGTH =
|
||||
MAX_FRAME_LENGTH - HEADER_LENGTH - MAC_LENGTH;
|
||||
|
||||
@Test
|
||||
public void testCloseWithoutWritingWritesFinalFrame() throws Exception {
|
||||
Mockery context = new Mockery();
|
||||
@@ -22,7 +17,7 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Write an empty final frame
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
|
||||
with(true));
|
||||
with(0), with(true));
|
||||
// Flush the stream
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
@@ -40,7 +35,7 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Write a non-final frame with an empty payload
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
|
||||
with(false));
|
||||
with(0), with(false));
|
||||
// Flush the stream
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
@@ -51,7 +46,7 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Closing the writer writes a final frame and flushes again
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
|
||||
with(true));
|
||||
with(0), with(true));
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
w.close();
|
||||
@@ -67,7 +62,7 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Write a non-final frame with one payload byte
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(1),
|
||||
with(false));
|
||||
with(0), with(false));
|
||||
// Flush the stream
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
@@ -79,7 +74,7 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Closing the writer writes a final frame and flushes again
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
|
||||
with(true));
|
||||
with(0), with(true));
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
w.close();
|
||||
@@ -94,18 +89,16 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Write a full non-final frame
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)),
|
||||
with(MAX_PAYLOAD_LENGTH), with(false));
|
||||
with(MAX_PAYLOAD_LENGTH), with(0), with(false));
|
||||
}});
|
||||
for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) {
|
||||
w.write(0);
|
||||
}
|
||||
for(int i = 0; i < MAX_PAYLOAD_LENGTH; i++) w.write(0);
|
||||
context.assertIsSatisfied();
|
||||
|
||||
// Clean up
|
||||
context.checking(new Expectations() {{
|
||||
// Closing the writer writes a final frame and flushes again
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
|
||||
with(true));
|
||||
with(0), with(true));
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
w.close();
|
||||
@@ -120,7 +113,7 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Write two full non-final frames
|
||||
exactly(2).of(encrypter).writeFrame(with(any(byte[].class)),
|
||||
with(MAX_PAYLOAD_LENGTH), with(false));
|
||||
with(MAX_PAYLOAD_LENGTH), with(0), with(false));
|
||||
}});
|
||||
// Sanity check
|
||||
assertEquals(0, MAX_PAYLOAD_LENGTH % 2);
|
||||
@@ -136,7 +129,7 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Closing the writer writes a final frame and flushes again
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(0),
|
||||
with(true));
|
||||
with(0), with(true));
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
w.close();
|
||||
@@ -151,10 +144,10 @@ public class StreamWriterImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
// Write two full non-final frames
|
||||
exactly(2).of(encrypter).writeFrame(with(any(byte[].class)),
|
||||
with(MAX_PAYLOAD_LENGTH), with(false));
|
||||
with(MAX_PAYLOAD_LENGTH), with(0), with(false));
|
||||
// Write a final frame with a one-byte payload
|
||||
oneOf(encrypter).writeFrame(with(any(byte[].class)), with(1),
|
||||
with(true));
|
||||
with(0), with(true));
|
||||
// Flush the stream
|
||||
oneOf(encrypter).flush();
|
||||
}});
|
||||
|
||||
Reference in New Issue
Block a user