Search in sources :

Example 56 with Executable

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

the class HpackDecoderTest method responsePseudoHeaderInRequest.

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

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

Example 57 with Executable

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

the class HpackDecoderTest method testAccountForHeaderOverhead.

@Test
public void testAccountForHeaderOverhead() throws Exception {
    final ByteBuf in = Unpooled.buffer(100);
    try {
        String headerName = "12345";
        String headerValue = "56789";
        long headerSize = headerName.length() + headerValue.length();
        hpackDecoder.setMaxHeaderListSize(headerSize);
        HpackEncoder hpackEncoder = new HpackEncoder(true);
        Http2Headers toEncode = new DefaultHttp2Headers();
        toEncode.add(headerName, headerValue);
        hpackEncoder.encodeHeaders(1, in, toEncode, NEVER_SENSITIVE);
        final Http2Headers decoded = new DefaultHttp2Headers();
        // SETTINGS_MAX_HEADER_LIST_SIZE is big enough for the header to fit...
        assertThat(hpackDecoder.getMaxHeaderListSize(), is(greaterThanOrEqualTo(headerSize)));
        // ... but decode should fail because we add some overhead for each header entry
        assertThrows(Http2Exception.HeaderListSizeException.class, new Executable() {

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

Example 58 with Executable

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

the class HpackDecoderTest method testSetTableSizeOverLimitFails.

@Test
public void testSetTableSizeOverLimitFails() throws Http2Exception {
    byte[] input = { (byte) 0x3F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x0E };
    final ByteBuf in = Unpooled.wrappedBuffer(input);
    try {
        // based on the input above ... 1 less than is above.
        hpackDecoder.setMaxHeaderTableSize(4026531870L - 1);
        assertThrows(Http2Exception.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                hpackDecoder.decode(0, in, mockHeaders, true);
            }
        });
    } finally {
        in.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 59 with Executable

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

the class HpackDecoderTest method pseudoHeaderAfterRegularHeader.

@Test
public void pseudoHeaderAfterRegularHeader() throws Exception {
    final ByteBuf in = Unpooled.buffer(200);
    try {
        HpackEncoder hpackEncoder = new HpackEncoder(true);
        Http2Headers toEncode = new InOrderHttp2Headers();
        toEncode.add("test", "1");
        toEncode.add(":method", "GET");
        hpackEncoder.encodeHeaders(1, in, toEncode, NEVER_SENSITIVE);
        final Http2Headers decoded = new DefaultHttp2Headers();
        assertThrows(Http2Exception.StreamException.class, new Executable() {

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

Example 60 with Executable

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

the class HpackDecoderTest method testIncompleteHeaderFieldRepresentation.

@Test
public void testIncompleteHeaderFieldRepresentation() throws Http2Exception {
    // Incomplete Literal Header Field with Incremental Indexing
    byte[] input = { (byte) 0x40 };
    final ByteBuf in = Unpooled.wrappedBuffer(input);
    try {
        assertThrows(Http2Exception.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                hpackDecoder.decode(0, in, mockHeaders, true);
            }
        });
    } finally {
        in.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