@ -22,12 +22,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.buffer.ByteBuf ;
import io.netty.buffer.ByteBuf ;
import io.netty.buffer.Unpooled ;
import io.netty.buffer.Unpooled ;
import org.junit.Test ;
import org.junit.Test ;
import org.xerial.snappy.Snappy ;
public class FramerTest {
public class FramerTest {
private static final ObjectMapper MAPPER = new ObjectMapper ( ) ;
private static final ObjectMapper MAPPER = new ObjectMapper ( ) ;
@Test
@Test
public void shouldThrowExceptionWhenMessageTooLong ( ) {
public void shouldThrowExceptionWhenFraming MessageTooLong ( ) {
final byte [ ] aes = {
final byte [ ] aes = {
0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa ,
0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa ,
0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2
0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2 , 0xa , 0x2
@ -50,6 +51,34 @@ public class FramerTest {
. withMessageContaining ( "Message size in excess of maximum length." ) ;
. withMessageContaining ( "Message size in excess of maximum length." ) ;
}
}
@Test
public void shouldThrowExceptionWhenDeframingCompressedMessageTooLong ( ) throws IOException {
// This is a circular test.
//
// This test frames a too-large message; it then impersonates the sending end
// by swapping the ingress and egress MACs and frames the plaintext messages.
// The expected result is an exception on deframing not relating to encryption.
//
final JsonNode td = MAPPER . readTree ( FramerTest . class . getResource ( "/peer1.json" ) ) ;
final HandshakeSecrets secrets = secretsFrom ( td , false ) ;
final Framer framer = new Framer ( secrets ) ;
framer . enableCompression ( ) ;
final byte [ ] byteArray = Snappy . compress ( new byte [ 0x1000000 ] ) ;
final ByteBuf buf = wrappedBuffer ( byteArray ) ;
final MessageData ethMessage = new RawMessage ( 0x00 , buf ) ;
final ByteBuf framedMessage = framer . frameAndReleaseMessage ( ethMessage ) ;
final HandshakeSecrets deframeSecrets = secretsFrom ( td , true ) ;
final Framer deframer = new Framer ( deframeSecrets ) ;
deframer . enableCompression ( ) ;
assertThatExceptionOfType ( IllegalStateException . class )
. isThrownBy ( ( ) - > deframer . deframe ( framedMessage ) )
. withMessageContaining ( "Message size in excess of maximum length." ) ;
}
@Test
@Test
public void deframeOne ( ) throws IOException {
public void deframeOne ( ) throws IOException {
// Load test data.
// Load test data.