diff --git a/runtime/runtime_impl_jetty9/src/main/java/com/google/apphosting/runtime/jetty9/JettyRequestAPIData.java b/runtime/runtime_impl_jetty9/src/main/java/com/google/apphosting/runtime/jetty9/JettyRequestAPIData.java index 43fd0e75..f14811a0 100644 --- a/runtime/runtime_impl_jetty9/src/main/java/com/google/apphosting/runtime/jetty9/JettyRequestAPIData.java +++ b/runtime/runtime_impl_jetty9/src/main/java/com/google/apphosting/runtime/jetty9/JettyRequestAPIData.java @@ -325,6 +325,8 @@ public boolean isSecure() { }; this.baseRequest = request; + this.baseRequest.setSecure(isSecure); + this.baseRequest.setHttpURI(httpUri); } public Request getBaseRequest() { diff --git a/runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/TransportGuarenteeTest.java b/runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/TransportGuaranteeTest.java similarity index 58% rename from runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/TransportGuarenteeTest.java rename to runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/TransportGuaranteeTest.java index 8fba8428..34f896c4 100644 --- a/runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/TransportGuarenteeTest.java +++ b/runtime/test/src/test/java/com/google/apphosting/runtime/jetty9/TransportGuaranteeTest.java @@ -16,6 +16,14 @@ package com.google.apphosting.runtime.jetty9; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.MatcherAssert.assertThat; + +import com.google.common.flogger.GoogleLogger; +import java.util.Arrays; +import java.util.Collection; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.http.HttpStatus; @@ -26,51 +34,72 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.runners.Parameterized; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.hamcrest.MatcherAssert.assertThat; +@RunWith(Parameterized.class) +public class TransportGuaranteeTest extends JavaRuntimeViaHttpBase { -@RunWith(JUnit4.class) -public class TransportGuarenteeTest extends JavaRuntimeViaHttpBase { + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList( + new Object[][] { + {"jetty94", false}, + {"jetty94", true}, + {"ee8", false}, + {"ee8", true}, + {"ee10", false}, + {"ee10", true}, + }); + } + private static final GoogleLogger logger = GoogleLogger.forEnclosingClass(); @Rule public TemporaryFolder temp = new TemporaryFolder(); private HttpClient httpClient; private RuntimeContext runtime; + private final boolean httpMode; + private final String environment; + + public TransportGuaranteeTest(String environment, boolean httpMode) { + this.environment = environment; + this.httpMode = httpMode; + System.setProperty("appengine.use.HttpConnector", Boolean.toString(httpMode)); + } private RuntimeContext runtimeContext() throws Exception { RuntimeContext.Config config = - RuntimeContext.Config.builder().setApplicationPath(temp.getRoot().toString()).build(); + RuntimeContext.Config.builder().setApplicationPath(temp.getRoot().toString()).build(); return RuntimeContext.create(config); } @Before public void before() throws Exception { - copyAppToDir("transportguaranteeapp", temp.getRoot().toPath()); + String app = "transportguaranteeapp-" + environment; + copyAppToDir(app, temp.getRoot().toPath()); SslContextFactory ssl = new SslContextFactory.Client(true); httpClient = new HttpClient(ssl); httpClient.start(); runtime = runtimeContext(); + logger.atInfo().log( + "%s: env=%s, httpMode=%s", this.getClass().getSimpleName(), environment, httpMode); } @After - public void after() throws Exception - { - httpClient.stop(); - runtime.close(); + public void after() throws Exception { + if (httpClient != null) { + httpClient.stop(); + } + if (runtime != null) { + runtime.close(); + } } @Test public void testSecureRequest() throws Exception { String url = runtime.jettyUrl("/"); assertThat(url, startsWith("http://")); - ContentResponse response = httpClient.newRequest(url) - .header("x-appengine-https", "on") - .send(); + ContentResponse response = httpClient.newRequest(url).header("x-appengine-https", "on").send(); assertThat(response.getStatus(), equalTo(HttpStatus.OK_200)); String expectedUrl = url.replace("http://", "https://"); assertThat(response.getContentAsString(), containsString("requestURL=" + expectedUrl)); @@ -82,10 +111,10 @@ public void testInsecureRequest() throws Exception { String url = runtime.jettyUrl("/"); assertThat(url, startsWith("http://")); - ContentResponse response = httpClient.newRequest(url) - .send(); - + ContentResponse response = httpClient.newRequest(url).send(); assertThat(response.getStatus(), equalTo(HttpStatus.FORBIDDEN_403)); - assertThat(response.getContentAsString(), containsString("!Secure")); + if (!"ee10".equals(environment)) { + assertThat(response.getContentAsString(), containsString("!Secure")); + } } } diff --git a/runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServletEE10.java b/runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServletEE10.java new file mode 100644 index 00000000..812674c6 --- /dev/null +++ b/runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServletEE10.java @@ -0,0 +1,35 @@ +/* + * Copyright 2021 Google LLC + * + * Licensed 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 + * + * https://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 com.google.apphosting.runtime.jetty9.transportguaranteeapp; + +import java.io.IOException; +import java.io.PrintWriter; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@SuppressWarnings("serial") +public class RequestUrlServletEE10 extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException { + response.setContentType("text/plain"); + response.setStatus(HttpServletResponse.SC_OK); + PrintWriter out = response.getWriter(); + out.println("requestURL=" + request.getRequestURL().toString()); + out.println("isSecure=" + request.isSecure()); + } +} diff --git a/runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServlet.java b/runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServletEE8.java similarity index 64% rename from runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServlet.java rename to runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServletEE8.java index 605a916f..25a120f8 100644 --- a/runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServlet.java +++ b/runtime/testapps/src/main/java/com/google/apphosting/runtime/jetty9/transportguaranteeapp/RequestUrlServletEE8.java @@ -22,16 +22,14 @@ import java.io.PrintWriter; @SuppressWarnings("serial") -public class RequestUrlServlet extends HttpServlet -{ - @Override - protected void doGet(HttpServletRequest request, - HttpServletResponse response) throws IOException - { - response.setContentType("text/plain"); - response.setStatus(HttpServletResponse.SC_OK); - PrintWriter out = response.getWriter(); - out.println("requestURL=" + request.getRequestURL().toString()); - out.println("isSecure=" + request.isSecure()); - } +public class RequestUrlServletEE8 extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException { + response.setContentType("text/plain"); + response.setStatus(HttpServletResponse.SC_OK); + PrintWriter out = response.getWriter(); + out.println("requestURL=" + request.getRequestURL().toString()); + out.println("isSecure=" + request.isSecure()); + } } diff --git a/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee10/WEB-INF/appengine-web.xml b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee10/WEB-INF/appengine-web.xml new file mode 100644 index 00000000..37a7d2c0 --- /dev/null +++ b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee10/WEB-INF/appengine-web.xml @@ -0,0 +1,27 @@ + + + + + java21 + transportguarantee + 1 + true + + + + + diff --git a/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee10/WEB-INF/web.xml b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee10/WEB-INF/web.xml new file mode 100644 index 00000000..59e75e72 --- /dev/null +++ b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee10/WEB-INF/web.xml @@ -0,0 +1,42 @@ + + + + + + RequestUrlServlet + com.google.apphosting.runtime.jetty9.transportguaranteeapp.RequestUrlServletEE10 + + + RequestUrlServlet + /* + + + + + Confidential + /* + + + CONFIDENTIAL + + + diff --git a/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp/WEB-INF/appengine-web.xml b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee8/WEB-INF/appengine-web.xml similarity index 100% rename from runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp/WEB-INF/appengine-web.xml rename to runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee8/WEB-INF/appengine-web.xml diff --git a/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp/WEB-INF/web.xml b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee8/WEB-INF/web.xml similarity index 77% rename from runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp/WEB-INF/web.xml rename to runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee8/WEB-INF/web.xml index 30225f6f..f4af6c03 100644 --- a/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp/WEB-INF/web.xml +++ b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-ee8/WEB-INF/web.xml @@ -15,12 +15,15 @@ limitations under the License. --> - + RequestUrlServlet - com.google.apphosting.runtime.jetty9.transportguaranteeapp.RequestUrlServlet + com.google.apphosting.runtime.jetty9.transportguaranteeapp.RequestUrlServletEE8 RequestUrlServlet diff --git a/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-jetty94/WEB-INF/appengine-web.xml b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-jetty94/WEB-INF/appengine-web.xml new file mode 100644 index 00000000..0f30346e --- /dev/null +++ b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-jetty94/WEB-INF/appengine-web.xml @@ -0,0 +1,28 @@ + + + + + java21 + transportguarantee + 1 + true + + + + + + diff --git a/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-jetty94/WEB-INF/web.xml b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-jetty94/WEB-INF/web.xml new file mode 100644 index 00000000..f4af6c03 --- /dev/null +++ b/runtime/testapps/src/main/resources/com/google/apphosting/runtime/jetty9/transportguaranteeapp-jetty94/WEB-INF/web.xml @@ -0,0 +1,42 @@ + + + + + + RequestUrlServlet + com.google.apphosting.runtime.jetty9.transportguaranteeapp.RequestUrlServletEE8 + + + RequestUrlServlet + /* + + + + + Confidential + /* + + + CONFIDENTIAL + + +