ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/coyote/http2/TestStreamQueryString.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/coyote/http2/TestStreamQueryString.java
Status
scanned
Type
file
Name
TestStreamQueryString.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
6449 (6.3 KB)
MD5
b85acabcd350fa11c46aaef1c007c9fb
SHA1
ccf7e680c38dfc6340e75e8a76620de2227fb6aa
SHA256
94a6ca982e71ffc50b559e1ac8873d0aa8f83c5a58b6ee12ddb365af83387741
SHA512

      
    
SHA1_git
ee7ba4312c7c948e93d32920a6395eb33922fcb4
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestStreamQueryString.java | 6.3 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.coyote.http2; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; import org.apache.tomcat.util.buf.HexUtils; /* * See https://bz.apache.org/bugzilla/show_bug.cgi?id=60482 */ @RunWith(Parameterized.class) public class TestStreamQueryString extends Http2TestBase { @Parameters public static Collection<Object[]> inputs() { List<Object[]> result = new ArrayList<>(); Collection<Object[]> baseData = data(); for (Object[] base : baseData) { // Test ASCII characters from 32 to 126 inclusive for (int i = 32; i < 128; i++) { result.add(new Object[] { base[0], base[1], "%" + HexUtils.toHexString(new byte[] { (byte) i }) }); } } return result; } @Parameter(2) public String queryValueToTest; @Test public void testQueryString() throws Exception { String queryValue = "xxx" + queryValueToTest + "xxx"; enableHttp2(); Tomcat tomcat = getTomcatInstance(); Context ctxt = getProgrammaticRootContext(); Tomcat.addServlet(ctxt, "query", new Query(queryValue)); ctxt.addServletMappingDecoded("/query", "query"); tomcat.start(); openClientConnection(); doHttpUpgrade(queryValue); sendClientPreface(); validateHttp2InitialResponse(); byte[] frameHeader = new byte[9]; ByteBuffer headersPayload = ByteBuffer.allocate(128); buildGetRequest(frameHeader, headersPayload, null, 3, "/query?" + Query.PARAM_NAME + "=" + queryValue); writeFrame(frameHeader, headersPayload); readSimpleGetResponse(); Assert.assertEquals(queryValue, "3-HeadersStart " + "3-Header-[:status]-[200] " + "3-Header-[content-type]-[text/plain;charset=UTF-8] " + "3-Header-[content-length]-[2] " + "3-Header-[date]-[Wed, 11 Nov 2015 19:18:42 GMT] " + "3-HeadersEnd " + "3-Body-2 " + "3-EndOfStream ", output.getTrace()); } protected void doHttpUpgrade(String queryValue) throws IOException { byte[] upgradeRequest = ("GET /query?" + Query.PARAM_NAME + "=" + queryValue + " HTTP/1.1 " + "Host: localhost:" + getPort() + " " + "Connection: " + DEFAULT_CONNECTION_HEADER_VALUE + " " + "Upgrade: h2c " + EMPTY_HTTP2_SETTINGS_HEADER + " ").getBytes(StandardCharsets.ISO_8859_1); os.write(upgradeRequest); os.flush(); Assert.assertTrue("Failed to read HTTP Upgrade response", readHttpUpgradeResponse()); } @Override protected void validateHttp2InitialResponse() throws Exception { // - 101 response acts as acknowledgement of the HTTP2-Settings header // Need to read 5 frames // - settings (server settings - must be first) // - settings ack (for the settings frame in the client preface) // - ping // - headers (for response) // - data (for response body) parser.readFrame(); parser.readFrame(); parser.readFrame(); parser.readFrame(); parser.readFrame(); Assert.assertEquals("0-Settings-[3]-[200] " + "0-Settings-End " + "0-Settings-Ack " + "0-Ping-[0,0,0,0,0,0,0,1] " + "1-HeadersStart " + "1-Header-[:status]-[200] " + "1-Header-[content-type]-[text/plain;charset=UTF-8] " + "1-Header-[content-length]-[2] " + "1-Header-[date]-[Wed, 11 Nov 2015 19:18:42 GMT] " + "1-HeadersEnd " + "1-Body-2 " + "1-EndOfStream ", output.getTrace()); output.clearTrace(); } private static final class Query extends HttpServlet { private static final long serialVersionUID = 1L; private static final String PARAM_NAME = "param"; private final String expectedValue; Query(String expectedValue) { String decoded; try { decoded = URLDecoder.decode(expectedValue, "UTF-8"); } catch (UnsupportedEncodingException e) { // Can't happen with UTF-8 decoded = null; } this.expectedValue = decoded; } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); if (expectedValue.equals(request.getParameter(PARAM_NAME))) { response.getWriter().write("OK"); } else { response.getWriter().write("FAIL"); } } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
18.31
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9
https://bz.apache.org/bugzilla/show_bug.cgi?id=60482 45 45