From 1f2ccda0566afaebd176fb813a05727b6a188155 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 28 Sep 2020 17:58:57 -0500 Subject: [PATCH 1/2] Adding missing tests post-merge Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/demos/ProxyWebAppTest.java | 96 +++++++++++++++++++ .../test/resources/jetty-logging.properties | 5 + 2 files changed, 101 insertions(+) create mode 100644 demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java create mode 100644 demos/demo-proxy-webapp/src/test/resources/jetty-logging.properties diff --git a/demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java b/demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java new file mode 100644 index 00000000000..a9156382f1b --- /dev/null +++ b/demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java @@ -0,0 +1,96 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.demos; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.util.component.LifeCycle; +import org.eclipse.jetty.webapp.WebAppContext; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; + +/** + * Test the configuration found in WEB-INF/web.xml for purposes of the demo-base + */ +public class ProxyWebAppTest +{ + private Server server; + private HttpClient client; + + @BeforeEach + public void setup() throws Exception + { + server = new Server(); + + ServerConnector connector = new ServerConnector(server); + connector.setPort(0); + server.addConnector(connector); + + WebAppContext webapp = new WebAppContext(); + // This is a pieced together WebApp. + // We don't have a valid WEB-INF/lib to rely on at this point. + // So, open up server classes here, for purposes of this testcase. + webapp.getServerClassMatcher().add("-org.eclipse.jetty.proxy."); + webapp.setWar(MavenTestingUtils.getProjectDirPath("src/main/webapp").toString()); + webapp.setExtraClasspath(MavenTestingUtils.getTargetPath().resolve("classes").toString()); + server.setHandler(webapp); + + server.start(); + + client = new HttpClient(); + client.start(); + } + + @AfterEach + public void teardown() + { + LifeCycle.stop(client); + LifeCycle.stop(server); + } + + @Test + @Tag("external") + public void testProxyRequest() throws InterruptedException, ExecutionException, TimeoutException + { + ContentResponse response = client.newRequest(server.getURI().resolve("/proxy/current/")) + .followRedirects(false) + .send(); + + // Expecting a 200 OK (not a 302 redirect or other error) + // If we got an error here, that means our configuration in web.xml is bad / out of date. + // Such as the redirect from the eclipse website, we want all of the requests to go through + // this proxy configuration, not redirected to the actual website. + assertThat("response status", response.getStatus(), is(HttpStatus.OK_200)); + // Expecting a Javadoc / APIDoc response - look for something unique for APIdoc. + assertThat("response", response.getContentAsString(), containsString("All Classes")); + } +} diff --git a/demos/demo-proxy-webapp/src/test/resources/jetty-logging.properties b/demos/demo-proxy-webapp/src/test/resources/jetty-logging.properties new file mode 100644 index 00000000000..bf725104bbd --- /dev/null +++ b/demos/demo-proxy-webapp/src/test/resources/jetty-logging.properties @@ -0,0 +1,5 @@ +org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +#org.eclipse.jetty.LEVEL=WARN +#org.eclipse.jetty.client.LEVEL=DEBUG +#org.eclipse.jetty.http.LEVEL=DEBUG +#org.eclipse.jetty.proxy.LEVEL=DEBUG From 9e54e9a08148f365c5089e8bc7f4b009964533a0 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 28 Sep 2020 18:04:20 -0500 Subject: [PATCH 2/2] Post merge cleanup. Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/demos/ProxyWebAppTest.java | 24 ++--- .../org/eclipse/jetty/ProxyWebAppTest.java | 96 ------------------- .../test/resources/jetty-logging.properties | 5 - 3 files changed, 12 insertions(+), 113 deletions(-) delete mode 100644 tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/ProxyWebAppTest.java delete mode 100644 tests/test-webapps/test-proxy-webapp/src/test/resources/jetty-logging.properties diff --git a/demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java b/demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java index a9156382f1b..5e6c738588d 100644 --- a/demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java +++ b/demos/demo-proxy-webapp/src/test/java/org/eclipse/jetty/demos/ProxyWebAppTest.java @@ -1,19 +1,19 @@ // -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. // -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html +// This program and the accompanying materials are made available under +// the terms of the Eclipse Public License 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0 // -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php +// This Source Code may also be made available under the following +// Secondary Licenses when the conditions for such availability set +// forth in the Eclipse Public License, v. 2.0 are satisfied: +// the Apache License v2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0 // -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== // package org.eclipse.jetty.demos; diff --git a/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/ProxyWebAppTest.java b/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/ProxyWebAppTest.java deleted file mode 100644 index 0e4206e53d6..00000000000 --- a/tests/test-webapps/test-proxy-webapp/src/test/java/org/eclipse/jetty/ProxyWebAppTest.java +++ /dev/null @@ -1,96 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.eclipse.jetty.client.HttpClient; -import org.eclipse.jetty.client.api.ContentResponse; -import org.eclipse.jetty.http.HttpStatus; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.toolchain.test.MavenTestingUtils; -import org.eclipse.jetty.util.component.LifeCycle; -import org.eclipse.jetty.webapp.WebAppContext; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; - -/** - * Test the configuration found in WEB-INF/web.xml for purposes of the demo-base - */ -public class ProxyWebAppTest -{ - private Server server; - private HttpClient client; - - @BeforeEach - public void setup() throws Exception - { - server = new Server(); - - ServerConnector connector = new ServerConnector(server); - connector.setPort(0); - server.addConnector(connector); - - WebAppContext webapp = new WebAppContext(); - // This is a pieced together WebApp. - // We don't have a valid WEB-INF/lib to rely on at this point. - // So, open up server classes here, for purposes of this testcase. - webapp.getServerClasspathPattern().add("-org.eclipse.jetty.proxy."); - webapp.setWar(MavenTestingUtils.getProjectDirPath("src/main/webapp").toString()); - webapp.setExtraClasspath(MavenTestingUtils.getTargetPath().resolve("classes").toString()); - server.setHandler(webapp); - - server.start(); - - client = new HttpClient(); - client.start(); - } - - @AfterEach - public void teardown() - { - LifeCycle.stop(client); - LifeCycle.stop(server); - } - - @Test - @Tag("external") - public void testProxyRequest() throws InterruptedException, ExecutionException, TimeoutException - { - ContentResponse response = client.newRequest(server.getURI().resolve("/proxy/current/")) - .followRedirects(false) - .send(); - - // Expecting a 200 OK (not a 302 redirect or other error) - // If we got an error here, that means our configuration in web.xml is bad / out of date. - // Such as the redirect from the eclipse website, we want all of the requests to go through - // this proxy configuration, not redirected to the actual website. - assertThat("response status", response.getStatus(), is(HttpStatus.OK_200)); - // Expecting a Javadoc / APIDoc response - look for something unique for APIdoc. - assertThat("response", response.getContentAsString(), containsString("All Classes")); - } -} diff --git a/tests/test-webapps/test-proxy-webapp/src/test/resources/jetty-logging.properties b/tests/test-webapps/test-proxy-webapp/src/test/resources/jetty-logging.properties deleted file mode 100644 index bf725104bbd..00000000000 --- a/tests/test-webapps/test-proxy-webapp/src/test/resources/jetty-logging.properties +++ /dev/null @@ -1,5 +0,0 @@ -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -#org.eclipse.jetty.LEVEL=WARN -#org.eclipse.jetty.client.LEVEL=DEBUG -#org.eclipse.jetty.http.LEVEL=DEBUG -#org.eclipse.jetty.proxy.LEVEL=DEBUG