From eb84c244d22fcb978ff10b2ebe2a6cceb7356f9d Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Jun 2020 09:23:46 -0500 Subject: [PATCH 1/4] Ensuring that usage of "/**/" within tests don't trigger checkstyle violation. Example: arguments.add(Arguments.of("glob:/**/*.jar", true)); Signed-off-by: Joakim Erdfelt --- build-resources/src/main/resources/jetty-checkstyle.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-resources/src/main/resources/jetty-checkstyle.xml b/build-resources/src/main/resources/jetty-checkstyle.xml index 16338ac3327..c95d421a03d 100644 --- a/build-resources/src/main/resources/jetty-checkstyle.xml +++ b/build-resources/src/main/resources/jetty-checkstyle.xml @@ -135,7 +135,7 @@ - + From cb898ac74a391669cb208c06c00dcf11c40b3658 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Jun 2020 09:24:36 -0500 Subject: [PATCH 2/4] Bumping up to Checkstyle 8.29 + This is in response to a dependabot notification of vulnerabilities in Checkstyle 8.20 Signed-off-by: Joakim Erdfelt --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6de899bec15..ca03a78b827 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ http://www.eclipse.org/jetty UTF-8 1.4 - 8.20 + 8.29 1.7.30 2.11.2 3.4.2 From 3adec35cf590841a73105637426d2093472154eb Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Jun 2020 09:25:05 -0500 Subject: [PATCH 3/4] Fixing CustomImportOrder checkstyle violations Signed-off-by: Joakim Erdfelt --- .../TestSecurityAnnotationConversions.java | 23 ++-- .../HazelcastSessionDataStoreFactory.java | 9 +- .../org/eclipse/jetty/http/HttpCookie.java | 17 ++- .../jaas/spi/PropertyFileLoginModule.java | 1 - .../jaas/spi/PropertyFileLoginModuleTest.java | 1 - .../session/TestMemcachedSessions.java | 1 - .../LifeCycleCallbackCollectionTest.java | 35 +++-- .../eclipse/jetty/server/ProxyCustomizer.java | 1 - .../server/session/DefaultSessionCache.java | 3 +- .../server/session/NullSessionCache.java | 1 - .../eclipse/jetty/server/ResponseTest.java | 23 ++-- .../server/handler/ContextHandlerTest.java | 7 +- .../server/session/SessionCookieTest.java | 1 - .../servlet/ServletContextHandlerTest.java | 127 +++++++++--------- .../server/session/DuplicateCookieTest.java | 19 ++- .../session/SessionInvalidationTest.java | 6 +- 16 files changed, 129 insertions(+), 146 deletions(-) diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java index a5bdcb76774..f78949abc2f 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java @@ -54,23 +54,28 @@ public class TestSecurityAnnotationConversions { } - @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = { - "tom", "dick", "harry" - })) + @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = + { + "tom", "dick", "harry" + })) public static class RolesServlet extends HttpServlet { } - @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = { - "tom", "dick", "harry" - }), httpMethodConstraints = {@HttpMethodConstraint(value = "GET")}) + @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = + { + "tom", "dick", "harry" + }), httpMethodConstraints = {@HttpMethodConstraint(value = "GET")}) public static class Method1Servlet extends HttpServlet { } - @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = { - "tom", "dick", "harry" - }), httpMethodConstraints = {@HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL)}) + @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = + { + "tom", "dick", "harry" + }), httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL) + }) public static class Method2Servlet extends HttpServlet { } diff --git a/jetty-hazelcast/src/main/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreFactory.java b/jetty-hazelcast/src/main/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreFactory.java index e0e4b56ab81..32d5e6a5259 100644 --- a/jetty-hazelcast/src/main/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreFactory.java +++ b/jetty-hazelcast/src/main/java/org/eclipse/jetty/hazelcast/session/HazelcastSessionDataStoreFactory.java @@ -30,7 +30,6 @@ import com.hazelcast.config.SerializerConfig; import com.hazelcast.config.XmlConfigBuilder; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; - import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory; import org.eclipse.jetty.server.session.SessionData; import org.eclipse.jetty.server.session.SessionDataStore; @@ -61,7 +60,7 @@ public class HazelcastSessionDataStoreFactory private boolean scavengeZombies = false; private String addresses; - + public boolean isScavengeZombies() { return scavengeZombies; @@ -86,12 +85,12 @@ public class HazelcastSessionDataStoreFactory if (StringUtil.isEmpty(configurationLocation)) { ClientConfig config = new ClientConfig(); - + if (addresses != null && !addresses.isEmpty()) { config.getNetworkConfig().setAddresses(Arrays.asList(addresses.split(","))); } - + SerializerConfig sc = new SerializerConfig() .setImplementation(new SessionDataSerializer()) .setTypeClass(SessionData.class); @@ -212,7 +211,7 @@ public class HazelcastSessionDataStoreFactory { this.hazelcastInstanceName = hazelcastInstanceName; } - + public String getAddresses() { return addresses; diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java index 4a906cc0a7e..ecbc8ede59d 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCookie.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.http; import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; - import javax.servlet.ServletContext; import org.eclipse.jetty.util.QuotedStringTokenizer; @@ -33,22 +32,22 @@ import org.eclipse.jetty.util.log.Logger; public class HttpCookie { private static final Logger LOG = Log.getLogger(HttpCookie.class); - + private static final String __COOKIE_DELIM = "\",;\\ \t"; private static final String __01Jan1970_COOKIE = DateGenerator.formatCookieDate(0).trim(); /** - *If this string is found within the comment parsed with {@link #isHttpOnlyInComment(String)} the check will return true + * If this string is found within the comment parsed with {@link #isHttpOnlyInComment(String)} the check will return true **/ public static final String HTTP_ONLY_COMMENT = "__HTTP_ONLY__"; /** - *These strings are used by {@link #getSameSiteFromComment(String)} to check for a SameSite specifier in the comment + * These strings are used by {@link #getSameSiteFromComment(String)} to check for a SameSite specifier in the comment **/ private static final String SAME_SITE_COMMENT = "__SAME_SITE_"; public static final String SAME_SITE_NONE_COMMENT = SAME_SITE_COMMENT + "NONE__"; public static final String SAME_SITE_LAX_COMMENT = SAME_SITE_COMMENT + "LAX__"; public static final String SAME_SITE_STRICT_COMMENT = SAME_SITE_COMMENT + "STRICT__"; - + /** * Name of context attribute with default SameSite cookie value */ @@ -82,7 +81,7 @@ public class HttpCookie private final boolean _httpOnly; private final long _expiration; private final SameSite _sameSite; - + public HttpCookie(String name, String value) { this(name, value, -1); @@ -463,7 +462,7 @@ public class HttpCookie /** * Get the default value for SameSite cookie attribute, if one * has been set for the given context. - * + * * @param context the context to check for default SameSite value * @return the default SameSite value or null if one does not exist * @throws IllegalStateException if the default value is not a permitted value @@ -479,10 +478,10 @@ public class HttpCookie LOG.debug("No default value for SameSite"); return null; } - + if (o instanceof SameSite) return (SameSite)o; - + try { SameSite samesite = Enum.valueOf(SameSite.class, o.toString().trim().toUpperCase(Locale.ENGLISH)); diff --git a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModule.java b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModule.java index e6791cbcf1a..79d59fd3626 100644 --- a/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModule.java +++ b/jetty-jaas/src/main/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModule.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; - import javax.security.auth.Subject; import javax.security.auth.callback.CallbackHandler; diff --git a/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java b/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java index d63adef87b5..49fad3f36df 100644 --- a/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java +++ b/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.jaas.spi; import java.io.File; import java.util.HashMap; - import javax.security.auth.Subject; import org.eclipse.jetty.jaas.callback.DefaultCallbackHandler; diff --git a/jetty-memcached/jetty-memcached-sessions/src/test/java/org/eclipse/jetty/memcached/session/TestMemcachedSessions.java b/jetty-memcached/jetty-memcached-sessions/src/test/java/org/eclipse/jetty/memcached/session/TestMemcachedSessions.java index 92e9153393f..d6bdebf1ec8 100644 --- a/jetty-memcached/jetty-memcached-sessions/src/test/java/org/eclipse/jetty/memcached/session/TestMemcachedSessions.java +++ b/jetty-memcached/jetty-memcached-sessions/src/test/java/org/eclipse/jetty/memcached/session/TestMemcachedSessions.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.memcached.session; import java.io.IOException; import java.io.PrintWriter; - import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java b/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java index 9916b57ab09..3f11a32cc79 100644 --- a/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java +++ b/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.plus.annotation; import java.lang.reflect.Method; - import javax.servlet.http.HttpServlet; import org.eclipse.jetty.plus.webapp.PlusDecorator; @@ -41,12 +40,12 @@ public class LifeCycleCallbackCollectionTest { public static int postConstructCount = 0; public static int preDestroyCount = 0; - + public void postconstruct() { ++postConstructCount; } - + public void predestroy() { ++preDestroyCount; @@ -55,7 +54,6 @@ public class LifeCycleCallbackCollectionTest /** * An unsupported lifecycle callback type - * */ public class TestLifeCycleCallback extends LifeCycleCallback { @@ -79,7 +77,6 @@ public class LifeCycleCallbackCollectionTest /** * A class that we can use to simulate having PostConstruct and * PreDestroy annotations on. - * */ public class SomeTestClass { @@ -177,7 +174,7 @@ public class LifeCycleCallbackCollectionTest //expected } } - + @Test public void testServletPostConstructPreDestroy() throws Exception { @@ -186,7 +183,7 @@ public class LifeCycleCallbackCollectionTest context.setResourceBase(MavenTestingUtils.getTargetTestingDir("predestroy-test").toURI().toURL().toString()); context.setContextPath("/"); server.setHandler(context); - + //add a non-async servlet ServletHolder notAsync = new ServletHolder(); notAsync.setHeldClass(TestServlet.class); @@ -194,7 +191,7 @@ public class LifeCycleCallbackCollectionTest notAsync.setAsyncSupported(false); notAsync.setInitOrder(1); context.getServletHandler().addServletWithMapping(notAsync, "/notasync/*"); - + //add an async servlet ServletHolder async = new ServletHolder(); async.setHeldClass(TestServlet.class); @@ -202,7 +199,7 @@ public class LifeCycleCallbackCollectionTest async.setAsyncSupported(true); async.setInitOrder(1); context.getServletHandler().addServletWithMapping(async, "/async/*"); - + //add a run-as servlet ServletHolder runas = new ServletHolder(); runas.setHeldClass(TestServlet.class); @@ -210,7 +207,7 @@ public class LifeCycleCallbackCollectionTest runas.setRunAsRole("admin"); runas.setInitOrder(1); context.getServletHandler().addServletWithMapping(runas, "/runas/*"); - + //add both run-as and non async servlet ServletHolder both = new ServletHolder(); both.setHeldClass(TestServlet.class); @@ -219,7 +216,7 @@ public class LifeCycleCallbackCollectionTest both.setAsyncSupported(false); both.setInitOrder(1); context.getServletHandler().addServletWithMapping(both, "/both/*"); - + //Make fake lifecycle callbacks for all servlets LifeCycleCallbackCollection collection = new LifeCycleCallbackCollection(); context.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION, collection); @@ -227,31 +224,31 @@ public class LifeCycleCallbackCollectionTest collection.add(pcNotAsync); PreDestroyCallback pdNotAsync = new PreDestroyCallback(TestServlet.class, "predestroy"); collection.add(pdNotAsync); - + PostConstructCallback pcAsync = new PostConstructCallback(TestServlet.class, "postconstruct"); collection.add(pcAsync); PreDestroyCallback pdAsync = new PreDestroyCallback(TestServlet.class, "predestroy"); collection.add(pdAsync); - + PostConstructCallback pcRunAs = new PostConstructCallback(TestServlet.class, "postconstruct"); collection.add(pcRunAs); PreDestroyCallback pdRunAs = new PreDestroyCallback(TestServlet.class, "predestroy"); collection.add(pdRunAs); - + PostConstructCallback pcBoth = new PostConstructCallback(TestServlet.class, "postconstruct"); collection.add(pcBoth); PreDestroyCallback pdBoth = new PreDestroyCallback(TestServlet.class, "predestroy"); collection.add(pdBoth); - + //ensure we invoke the lifecyclecallbacks context.getObjectFactory().addDecorator(new PlusDecorator(context)); - + server.start(); - + assertEquals(4, TestServlet.postConstructCount); - + server.stop(); - + assertEquals(4, TestServlet.preDestroyCount); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyCustomizer.java index a2893eaf85a..b2494bcca97 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyCustomizer.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ProxyCustomizer.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.server; import java.net.InetSocketAddress; import java.util.HashSet; import java.util.Set; - import javax.servlet.ServletRequest; import org.eclipse.jetty.io.EndPoint; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java index c2e3306514a..9670dbed621 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionCache.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; - import javax.servlet.http.HttpServletRequest; import org.eclipse.jetty.util.annotation.ManagedAttribute; @@ -134,7 +133,7 @@ public class DefaultSessionCache extends AbstractSessionCache { if (LOG.isDebugEnabled()) LOG.debug("Shutdown sessions, invalidating = {}", isInvalidateOnShutdown()); - + // loop over all the sessions in memory (a few times if necessary to catch sessions that have been // added while we're running int loop = 100; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionCache.java index 28acda2b3b6..254778667af 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/NullSessionCache.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.server.session; import java.util.function.Function; - import javax.servlet.http.HttpServletRequest; /** diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java index 08e48bac746..5a8ff294ace 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java @@ -38,7 +38,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.stream.Stream; - import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; @@ -967,7 +966,7 @@ public class ResponseTest assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly", set); } - + @Test public void testAddCookieInInclude() throws Exception { @@ -984,7 +983,7 @@ public class ResponseTest assertNull(response.getHttpFields().get("Set-Cookie")); } - + @Test public void testAddCookieSameSiteDefault() throws Exception { @@ -1001,12 +1000,12 @@ public class ResponseTest response.addCookie(cookie); String set = response.getHttpFields().get("Set-Cookie"); assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly; SameSite=Strict", set); - + response.getHttpFields().remove("Set-Cookie"); - + //test bad default samesite value context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "FooBar"); - + assertThrows(IllegalStateException.class, () -> response.addCookie(cookie)); } @@ -1081,7 +1080,7 @@ public class ResponseTest response.setContentType("some/type"); response.setContentLength(3); - response.setHeader(HttpHeader.EXPIRES,"never"); + response.setHeader(HttpHeader.EXPIRES, "never"); response.setHeader("SomeHeader", "SomeValue"); @@ -1149,7 +1148,7 @@ public class ResponseTest List actual = Collections.list(response.getHttpFields().getValues("Set-Cookie")); assertThat("HttpCookie order", actual, hasItems(expected)); } - + @Test public void testReplaceHttpCookieSameSite() { @@ -1191,7 +1190,7 @@ public class ResponseTest actual = Collections.list(response.getHttpFields().getValues("Set-Cookie")); assertThat(actual, hasItems(new String[]{"Foo=replaced; Path=/path; Domain=Bah"})); } - + @Test public void testReplaceParsedHttpCookieSiteDefault() { @@ -1199,7 +1198,7 @@ public class ResponseTest TestServletContextHandler context = new TestServletContextHandler(); context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "LAX"); _channel.getRequest().setContext(context.getServletContext()); - + response.addHeader(HttpHeader.SET_COOKIE.asString(), "Foo=123456"); response.replaceCookie(new HttpCookie("Foo", "value")); String set = response.getHttpFields().get("Set-Cookie"); @@ -1233,7 +1232,7 @@ public class ResponseTest super(handler, new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300)); } } - + private static class TestServletContextHandler extends ContextHandler { private class Context extends ContextHandler.Context @@ -1255,7 +1254,7 @@ public class ResponseTest @Override public void setAttribute(String name, Object object) { - _attributes.put(name,object); + _attributes.put(name, object); } @Override diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java index dbc2973e3a8..7f702540071 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java @@ -27,7 +27,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.List; - import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.http.HttpServletRequest; @@ -448,7 +447,7 @@ public class ContextHandlerTest assertThat(connector.getResponse("GET /foo/xxx HTTP/1.0\n\n"), Matchers.containsString("ctx='/foo'")); assertThat(connector.getResponse("GET /foo/bar/xxx HTTP/1.0\n\n"), Matchers.containsString("ctx='/foo/bar'")); } - + @Test public void testContextInitializationDestruction() throws Exception { @@ -859,12 +858,12 @@ public class ContextHandlerTest writer.println("ctx='" + request.getContextPath() + "'"); } } - + private static class TestServletContextListener implements ServletContextListener { public int initialized = 0; public int destroyed = 0; - + @Override public void contextInitialized(ServletContextEvent sce) { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java index ceb6fb0ef76..344783b3922 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionCookieTest.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session; import java.util.concurrent.TimeUnit; import java.util.function.Function; - import javax.servlet.SessionCookieConfig; import javax.servlet.http.HttpServletRequest; diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java index 7b9a4e885e9..08590cd51b1 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java @@ -29,7 +29,6 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; - import javax.servlet.DispatcherType; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -109,12 +108,12 @@ public class ServletContextHandlerTest private static final AtomicInteger __testServlets = new AtomicInteger(); private static int __initIndex = 0; private static int __destroyIndex = 0; - + public class StopTestFilter implements Filter { int _initIndex; int _destroyIndex; - + @Override public void init(FilterConfig filterConfig) throws ServletException { @@ -135,7 +134,7 @@ public class ServletContextHandlerTest } public class StopTestServlet extends GenericServlet - { + { int _initIndex; int _destroyIndex; @@ -251,7 +250,7 @@ public class ServletContextHandlerTest } public static class MyTestSessionListener implements HttpSessionAttributeListener, HttpSessionListener - { + { @Override public void sessionCreated(HttpSessionEvent se) { @@ -277,13 +276,13 @@ public class ServletContextHandlerTest { } } - + public static class MySCAListener implements ServletContextAttributeListener { public static int adds = 0; public static int removes = 0; public static int replaces = 0; - + @Override public void attributeAdded(ServletContextAttributeEvent event) { @@ -310,7 +309,7 @@ public class ServletContextHandlerTest @Override public void requestDestroyed(ServletRequestEvent sre) - { + { ++destroys; } @@ -320,13 +319,13 @@ public class ServletContextHandlerTest ++inits; } } - + public static class MyRAListener implements ServletRequestAttributeListener { public static int adds = 0; public static int removes = 0; public static int replaces = 0; - + @Override public void attributeAdded(ServletRequestAttributeEvent srae) { @@ -345,7 +344,7 @@ public class ServletContextHandlerTest ++replaces; } } - + public static class MySListener implements HttpSessionListener { public static int creates = 0; @@ -362,15 +361,14 @@ public class ServletContextHandlerTest { ++destroys; } - } - + public static class MySAListener implements HttpSessionAttributeListener { public static int adds = 0; public static int removes = 0; public static int replaces = 0; - + @Override public void attributeAdded(HttpSessionBindingEvent event) { @@ -387,20 +385,20 @@ public class ServletContextHandlerTest public void attributeReplaced(HttpSessionBindingEvent event) { ++replaces; - } + } } public static class MySIListener implements HttpSessionIdListener { public static int changes = 0; - + @Override public void sessionIdChanged(HttpSessionEvent event, String oldSessionId) { ++changes; } } - + public class InitialListener implements ServletContextListener { @Override @@ -446,16 +444,15 @@ public class ServletContextHandlerTest { fail(x); } - + sce.getServletContext().setAttribute("foo", "bar"); } @Override public void contextDestroyed(ServletContextEvent sce) { - + } - } @BeforeEach @@ -496,7 +493,7 @@ public class ServletContextHandlerTest root.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); _server.start(); _server.stop(); - + assertEquals(0, stopTestListener._initIndex); //listeners contextInitialized called first assertEquals(1, stopTestFilter._initIndex); //filters init assertEquals(2, stopTestServlet._initIndex); //servlets init @@ -505,7 +502,7 @@ public class ServletContextHandlerTest assertEquals(1, stopTestServlet._destroyIndex); //servlets destroyed next assertEquals(2, stopTestListener._destroyIndex); //listener contextDestroyed last } - + @Test public void testAddSessionListener() throws Exception { @@ -536,7 +533,7 @@ public class ServletContextHandlerTest assertTrue((Boolean)root.getServletContext().getAttribute("MySCI.startup")); assertTrue((Boolean)root.getServletContext().getAttribute("MyContextListener.contextInitialized")); } - + @Test public void testContextInitializationDestruction() throws Exception { @@ -549,7 +546,7 @@ public class ServletContextHandlerTest { public int initialized = 0; public int destroyed = 0; - + @Override public void contextInitialized(ServletContextEvent sce) { @@ -562,7 +559,7 @@ public class ServletContextHandlerTest destroyed++; } } - + TestServletContextListener listener = new TestServletContextListener(); root.addEventListener(listener); server.start(); @@ -571,7 +568,7 @@ public class ServletContextHandlerTest server.stop(); assertEquals(1, listener.destroyed); } - + @Test public void testListenersFromContextListener() throws Exception { @@ -584,7 +581,7 @@ public class ServletContextHandlerTest root.getServletHandler().addListener(initialListener); ServletHolder holder0 = root.addServlet(TestServlet.class, "/test"); _server.start(); - + ListenerHolder[] listenerHolders = root.getServletHandler().getListeners(); assertNotNull(listenerHolders); for (ListenerHolder l : listenerHolders) @@ -598,27 +595,29 @@ public class ServletContextHandlerTest assertTrue(root.isProgrammaticListener(l.getListener())); } } - + EventListener[] listeners = root.getEventListeners(); assertNotNull(listeners); List listenerClassNames = new ArrayList<>(); for (EventListener l : listeners) + { listenerClassNames.add(l.getClass().getName()); - + } + assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySCAListener")); assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MyRequestListener")); assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MyRAListener")); assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySListener")); assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySAListener")); assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySIListener")); - + //test ServletRequestAttributeListener String response = _connector.getResponse("GET /test?req=all HTTP/1.0\r\n\r\n"); assertThat(response, Matchers.containsString("200 OK")); assertEquals(1, MyRAListener.adds); assertEquals(1, MyRAListener.replaces); assertEquals(1, MyRAListener.removes); - + //test HttpSessionAttributeListener response = _connector.getResponse("GET /test?session=create HTTP/1.0\r\n\r\n"); String sessionid = response.substring(response.indexOf("JSESSIONID"), response.indexOf(";")); @@ -649,7 +648,7 @@ public class ServletContextHandlerTest assertEquals(1, MySAListener.adds); assertEquals(1, MySAListener.replaces); assertEquals(1, MySAListener.removes); - + //test HttpSessionIdListener.sessionIdChanged request = new StringBuffer(); request.append("GET /test?session=change HTTP/1.0\n"); @@ -660,7 +659,7 @@ public class ServletContextHandlerTest assertThat(response, Matchers.containsString("200 OK")); assertEquals(1, MySIListener.changes); sessionid = response.substring(response.indexOf("JSESSIONID"), response.indexOf(";")); - + //test HttpServletListener.sessionDestroyed request = new StringBuffer(); request.append("GET /test?session=delete HTTP/1.0\n"); @@ -670,7 +669,7 @@ public class ServletContextHandlerTest response = _connector.getResponse(request.toString()); assertThat(response, Matchers.containsString("200 OK")); assertEquals(1, MySListener.destroys); - + //test ServletContextAttributeListener //attribute was set when context listener registered assertEquals(1, MySCAListener.adds); @@ -749,7 +748,7 @@ public class ServletContextHandlerTest { //A servlet cannot be added by another servlet Logger logger = Log.getLogger(ContextHandler.class.getName() + "ROOT"); - + try (StacklessLogging stackless = new StacklessLogging(logger)) { ServletContextHandler context = new ServletContextHandler(); @@ -769,7 +768,7 @@ public class ServletContextHandlerTest assertTrue(e.getCause() instanceof IllegalStateException); } else - fail(e); + fail(e); } } @@ -829,9 +828,8 @@ public class ServletContextHandlerTest @Override public void destroy() - { + { } - }); context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST)); context.getServletHandler().setStartWithUnavailable(false); @@ -881,9 +879,8 @@ public class ServletContextHandlerTest @Override public void destroy() - { + { } - }); context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST)); context.getServletHandler().setStartWithUnavailable(false); @@ -933,9 +930,8 @@ public class ServletContextHandlerTest @Override public void destroy() - { + { } - }); context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST)); context.getServletHandler().setStartWithUnavailable(false); @@ -956,7 +952,7 @@ public class ServletContextHandlerTest fail(e); } } - } + } @Test public void testAddServletFromSCL() throws Exception @@ -977,9 +973,8 @@ public class ServletContextHandlerTest @Override public void contextDestroyed(ServletContextEvent sce) - { + { } - }); _server.setHandler(context); _server.start(); @@ -1010,10 +1005,10 @@ public class ServletContextHandlerTest rego.addMapping("/hello/*"); } } - + root.addBean(new MySCIStarter(root.getServletContext(), new ServletAddingSCI()), true); _server.start(); - + StringBuffer request = new StringBuffer(); request.append("GET /hello HTTP/1.0\n"); request.append("Host: localhost\n"); @@ -1050,7 +1045,7 @@ public class ServletContextHandlerTest response = _connector.getResponse(request.toString()); assertThat("Response", response, containsString("Hello World")); } - + @Test public void testServletRegistrationByClass() throws Exception { @@ -1090,7 +1085,7 @@ public class ServletContextHandlerTest String response = _connector.getResponse(request.toString()); assertThat("Response", response, containsString("Test")); } - + @Test public void testPartialServletRegistrationByName() throws Exception { @@ -1099,7 +1094,7 @@ public class ServletContextHandlerTest ServletHolder partial = new ServletHolder(); partial.setName("test"); context.addServlet(partial, "/test"); - + //complete partial servlet registration by providing name of the servlet class ServletRegistration reg = context.getServletContext().addServlet("test", TestServlet.class.getName()); assertNotNull(reg); @@ -1116,7 +1111,7 @@ public class ServletContextHandlerTest String response = _connector.getResponse(request.toString()); assertThat("Response", response, containsString("Test")); } - + @Test public void testPartialServletRegistrationByClass() throws Exception { @@ -1125,7 +1120,7 @@ public class ServletContextHandlerTest ServletHolder partial = new ServletHolder(); partial.setName("test"); context.addServlet(partial, "/test"); - + //complete partial servlet registration by providing the servlet class ServletRegistration reg = context.getServletContext().addServlet("test", TestServlet.class); assertNotNull(reg); @@ -1143,7 +1138,7 @@ public class ServletContextHandlerTest String response = _connector.getResponse(request.toString()); assertThat("Response", response, containsString("Test")); } - + @Test public void testNullServletRegistration() throws Exception { @@ -1153,7 +1148,7 @@ public class ServletContextHandlerTest full.setName("test"); full.setHeldClass(TestServlet.class); context.addServlet(full, "/test"); - + //Must return null if the servlet has been fully defined previously ServletRegistration reg = context.getServletContext().addServlet("test", TestServlet.class); assertNull(reg); @@ -1169,7 +1164,7 @@ public class ServletContextHandlerTest String response = _connector.getResponse(request.toString()); assertThat("Response", response, containsString("Test")); } - + @Test public void testHandlerBeforeServletHandler() throws Exception { @@ -1261,7 +1256,7 @@ public class ServletContextHandlerTest SecurityHandler securityHandler = context.getSecurityHandler(); assertNotNull(context.getGzipHandler()); GzipHandler gzipHandler = context.getGzipHandler(); - + //check the handler linking order HandlerWrapper h = (HandlerWrapper)context.getHandler(); assertSame(h, sessionHandler); @@ -1297,16 +1292,16 @@ public class ServletContextHandlerTest @Override protected boolean checkWebResourcePermissions(String pathInContext, Request request, Response response, Object constraintInfo, UserIdentity userIdentity) - throws IOException + throws IOException { return false; } }; - + //check the linking order context.setSecurityHandler(myHandler); assertSame(myHandler, context.getSecurityHandler()); - + h = (HandlerWrapper)context.getHandler(); assertSame(h, sessionHandler); @@ -1316,7 +1311,7 @@ public class ServletContextHandlerTest h = (HandlerWrapper)h.getHandler(); assertSame(h, gzipHandler); } - + @Test public void testReplaceServletHandlerWithoutServlet() throws Exception { @@ -1491,7 +1486,7 @@ public class ServletContextHandlerTest writer.write("Hello World"); } } - + public static class MyFilter implements Filter { @@ -1590,7 +1585,7 @@ public class ServletContextHandlerTest dynamic.addMapping("/added/*"); } } - + public static class FilterAddingServlet extends HttpServlet { @Override @@ -1643,7 +1638,7 @@ public class ServletContextHandlerTest resp.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = resp.getWriter(); writer.write("Test"); - + String action = req.getParameter("session"); if (!Objects.isNull(action)) { @@ -1675,7 +1670,7 @@ public class ServletContextHandlerTest } else resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); - + return; } @@ -1686,10 +1681,10 @@ public class ServletContextHandlerTest req.setAttribute("some", "value"); req.setAttribute("some", "other"); req.removeAttribute("some"); - + return; } - + action = req.getParameter("ctx"); if (!Objects.isNull(action)) { diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java index 7181689b722..a9097ce065d 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DuplicateCookieTest.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session; import java.io.IOException; import java.util.concurrent.TimeUnit; - import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -51,7 +50,7 @@ public class DuplicateCookieTest String contextPath = ""; String servletMapping = "/server"; HttpClient client = null; - + DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); SessionDataStoreFactory storeFactory = new TestSessionDataStoreFactory(); @@ -69,7 +68,7 @@ public class DuplicateCookieTest createUnExpiredSession(contextHandler.getSessionHandler().getSessionCache(), contextHandler.getSessionHandler().getSessionCache().getSessionDataStore(), "4422"); - + client = new HttpClient(); client.start(); @@ -87,14 +86,14 @@ public class DuplicateCookieTest client.stop(); } } - + @Test public void testMultipleSessionCookiesOnlyOneValid() throws Exception { String contextPath = ""; String servletMapping = "/server"; HttpClient client = null; - + DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); SessionDataStoreFactory storeFactory = new TestSessionDataStoreFactory(); @@ -116,7 +115,7 @@ public class DuplicateCookieTest createInvalidSession(contextHandler.getSessionHandler().getSessionCache(), contextHandler.getSessionHandler().getSessionCache().getSessionDataStore(), "2233"); - + client = new HttpClient(); client.start(); @@ -134,7 +133,7 @@ public class DuplicateCookieTest client.stop(); } } - + @Test public void testMultipleSessionCookiesMultipleExists() throws Exception { @@ -165,7 +164,7 @@ public class DuplicateCookieTest createUnExpiredSession(contextHandler.getSessionHandler().getSessionCache(), contextHandler.getSessionHandler().getSessionCache().getSessionDataStore(), "9111"); - + client = new HttpClient(); client.start(); @@ -192,14 +191,14 @@ public class DuplicateCookieTest cache.add(id, s); return s; } - + public Session createInvalidSession(SessionCache cache, SessionDataStore store, String id) throws Exception { Session session = createUnExpiredSession(cache, store, id); session._state = Session.State.INVALID; return session; } - + public static class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L; diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionInvalidationTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionInvalidationTest.java index 0587cb125cf..9cce3bbf0ef 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionInvalidationTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionInvalidationTest.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.server.session; import java.io.IOException; - import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -96,7 +95,7 @@ public class SessionInvalidationTest server.stop(); } } - + public static class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L; @@ -118,7 +117,7 @@ public class SessionInvalidationTest //invalidate existing session session.invalidate(); - + assertThrows(IllegalStateException.class, () -> session.invalidate()); assertThrows(IllegalStateException.class, () -> session.getLastAccessedTime()); assertThrows(IllegalStateException.class, () -> session.getCreationTime()); @@ -131,7 +130,6 @@ public class SessionInvalidationTest assertThrows(IllegalStateException.class, () -> session.removeValue("foo")); assertThrows(IllegalStateException.class, () -> session.setAttribute("a", "b")); assertDoesNotThrow(() -> session.getId()); - } } } From 49615156f99908347f6b39a721108f71a5a207f5 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Mon, 29 Jun 2020 10:39:58 +0200 Subject: [PATCH 4/4] Fix blank line in import. --- .../src/test/java/org/eclipse/jetty/http/HttpCookieTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java index a0156afc065..e76878aeb93 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpCookieTest.java @@ -28,7 +28,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.stream.Stream; - import javax.servlet.Filter; import javax.servlet.FilterRegistration; import javax.servlet.RequestDispatcher;