|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.coyote.http2; |
| 18 | + |
| 19 | +import java.nio.ByteBuffer; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.List; |
| 22 | + |
| 23 | +import org.junit.Assert; |
| 24 | +import org.junit.Test; |
| 25 | + |
| 26 | +import org.apache.tomcat.util.http.Method; |
| 27 | + |
| 28 | +/** |
| 29 | + * Unit tests for Section 8.3 of <a href="https://tools.ietf.org/html/rfc9113#section-8.3">RFC 9113</a>. |
| 30 | + */ |
| 31 | +public class TestHttp2Section_8_3 extends Http2TestBase { |
| 32 | + |
| 33 | + /* |
| 34 | + * Not explicitly specified in section 8.3 but closely aligned to it. |
| 35 | + */ |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testSchemeInconsistencyNonTLS() throws Exception { |
| 39 | + testSchemeInconsistenct(false); |
| 40 | + } |
| 41 | + |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testSchemeInconsistencyTLS() throws Exception { |
| 45 | + testSchemeInconsistenct(true); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + private void testSchemeInconsistenct(boolean connectionUsesTls) throws Exception { |
| 50 | + // Start HTTP/2 over non-TLS connection |
| 51 | + http2Connect(connectionUsesTls); |
| 52 | + |
| 53 | + byte[] frameHeader = new byte[9]; |
| 54 | + ByteBuffer headersPayload = ByteBuffer.allocate(128); |
| 55 | + |
| 56 | + List<Header> headers = new ArrayList<>(4); |
| 57 | + headers.add(new Header(":method", Method.GET)); |
| 58 | + if (connectionUsesTls) { |
| 59 | + headers.add(new Header(":scheme", "http")); |
| 60 | + } else { |
| 61 | + headers.add(new Header(":scheme", "https")); |
| 62 | + } |
| 63 | + headers.add(new Header(":path", "/simple")); |
| 64 | + headers.add(new Header(":authority", "localhost:" + getPort())); |
| 65 | + |
| 66 | + buildGetRequest(frameHeader, headersPayload, null, headers, 3); |
| 67 | + |
| 68 | + writeFrame(frameHeader, headersPayload); |
| 69 | + |
| 70 | + parser.readFrame(); |
| 71 | + |
| 72 | + Assert.assertEquals("3-RST-[1]\n", output.getTrace()); |
| 73 | + } |
| 74 | +} |
0 commit comments