Search in sources :

Example 51 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class HpackHuffmanTest method testDecodeEOS.

@Test
public void testDecodeEOS() throws Http2Exception {
    final byte[] buf = new byte[4];
    for (int i = 0; i < 4; i++) {
        buf[i] = (byte) 0xFF;
    }
    assertThrows(Http2Exception.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            decode(buf);
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 52 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class HpackHuffmanTest method testDecodeIllegalPadding.

@Test
public void testDecodeIllegalPadding() throws Http2Exception {
    final byte[] buf = new byte[1];
    // '0', invalid padding
    buf[0] = 0x00;
    assertThrows(Http2Exception.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            decode(buf);
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 53 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class HpackDecoderTest method testMissingDynamicTableSizeUpdate.

@Test
public void testMissingDynamicTableSizeUpdate() throws Http2Exception {
    hpackDecoder.setMaxHeaderTableSize(0);
    assertEquals(0, hpackDecoder.getMaxHeaderTableSize());
    assertThrows(Http2Exception.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            decode("81");
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 54 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class HpackDecoderTest method testDecodeULE128LongOverflow2.

@Test
public void testDecodeULE128LongOverflow2() throws Http2Exception {
    byte[] input = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x7F };
    final ByteBuf in = Unpooled.wrappedBuffer(input);
    final int readerIndex = in.readerIndex();
    try {
        assertThrows(Http2Exception.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                decodeULE128(in, 1L);
            }
        });
    } finally {
        assertEquals(readerIndex, in.readerIndex());
        in.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 55 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class HpackDecoderTest method failedValidationDoesntCorruptHpack.

@Test
public void failedValidationDoesntCorruptHpack() throws Exception {
    final ByteBuf in1 = Unpooled.buffer(200);
    ByteBuf in2 = Unpooled.buffer(200);
    try {
        HpackEncoder hpackEncoder = new HpackEncoder(true);
        Http2Headers toEncode = new DefaultHttp2Headers();
        toEncode.add(":method", "GET");
        toEncode.add(":status", "200");
        toEncode.add("foo", "bar");
        hpackEncoder.encodeHeaders(1, in1, toEncode, NEVER_SENSITIVE);
        final Http2Headers decoded = new DefaultHttp2Headers();
        Http2Exception.StreamException expected = assertThrows(Http2Exception.StreamException.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                hpackDecoder.decode(1, in1, decoded, true);
            }
        });
        assertEquals(1, expected.streamId());
        // Do it again, this time without validation, to make sure the HPACK state is still sane.
        decoded.clear();
        hpackEncoder.encodeHeaders(1, in2, toEncode, NEVER_SENSITIVE);
        hpackDecoder.decode(1, in2, decoded, false);
        assertEquals(3, decoded.size());
        assertEquals("GET", decoded.method().toString());
        assertEquals("200", decoded.status().toString());
        assertEquals("bar", decoded.get("foo").toString());
    } finally {
        in1.release();
        in2.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Aggregations

Executable (org.junit.jupiter.api.function.Executable)476 Test (org.junit.jupiter.api.Test)434 lombok.val (lombok.val)112 ByteBuf (io.netty.buffer.ByteBuf)83 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)42 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)36 CucumberException (io.cucumber.core.exception.CucumberException)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)15 Feature (io.cucumber.core.gherkin.Feature)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 StepDefinition (io.cucumber.core.backend.StepDefinition)14 Step (io.cucumber.core.gherkin.Step)14 Argument (io.cucumber.core.stepexpression.Argument)14 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 LocalChannel (io.netty.channel.local.LocalChannel)12 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)11 SSLEngine (javax.net.ssl.SSLEngine)11 Bootstrap (io.netty.bootstrap.Bootstrap)10