You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/02/15 15:00:35 UTC
[tomcat] 01/02: Code cleanup (format) - no functional change
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 0f22c1d60264735cba9500f7a1ccfc1d724694d2
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Feb 15 15:00:12 2023 +0000
Code cleanup (format) - no functional change
---
test/org/apache/catalina/valves/Benchmarks.java | 78 ++---
.../apache/catalina/valves/TestAccessLogValve.java | 11 +-
.../valves/TestCrawlerSessionManagerValve.java | 13 +-
.../catalina/valves/TestErrorReportValve.java | 31 +-
.../valves/TestLoadBalancerDrainingValve.java | 79 +++--
.../apache/catalina/valves/TestRemoteIpValve.java | 99 +++---
.../catalina/valves/TestRequestFilterValve.java | 340 ++++++++++-----------
.../valves/TestStuckThreadDetectionValve.java | 21 +-
.../catalina/valves/TesterAccessLogValve.java | 9 +-
9 files changed, 326 insertions(+), 355 deletions(-)
diff --git a/test/org/apache/catalina/valves/Benchmarks.java b/test/org/apache/catalina/valves/Benchmarks.java
index 973df0b946..431c73bc0c 100644
--- a/test/org/apache/catalina/valves/Benchmarks.java
+++ b/test/org/apache/catalina/valves/Benchmarks.java
@@ -22,20 +22,17 @@ import java.util.Date;
import org.junit.Test;
/**
- * Some simple micro-benchmarks to help determine best approach for thread
- * safety in valves, particularly the {@link AccessLogValve}. Implemented as
- * JUnit tests to make the simple to execute but does not used Test* as the
- * class name to avoid being included in the automated unit tests.
+ * Some simple micro-benchmarks to help determine best approach for thread safety in valves, particularly the
+ * {@link AccessLogValve}. Implemented as JUnit tests to make the simple to execute but does not used Test* as the class
+ * name to avoid being included in the automated unit tests.
*/
public class Benchmarks {
@Test
public void testAccessLogGetDate() throws Exception {
// Is it better to use a sync or a thread local here?
BenchmarkTest benchmark = new BenchmarkTest();
- Runnable[] tests = new Runnable[] { new GetDateBenchmarkTest_Sync(),
- new GetDateBenchmarkTest_Local(),
- new GetDateBenchmarkTest_LocalMutableLong(),
- new GetDateBenchmarkTest_LocalStruct() };
+ Runnable[] tests = new Runnable[] { new GetDateBenchmarkTest_Sync(), new GetDateBenchmarkTest_Local(),
+ new GetDateBenchmarkTest_LocalMutableLong(), new GetDateBenchmarkTest_LocalStruct() };
benchmark.doTest(5, tests);
}
@@ -99,8 +96,7 @@ public class Benchmarks {
}
}
- private static class GetDateBenchmarkTest_LocalMutableLong implements
- Runnable {
+ private static class GetDateBenchmarkTest_LocalMutableLong implements Runnable {
@Override
public String toString() {
@@ -175,17 +171,15 @@ public class Benchmarks {
public void testAccessLogTimeDateElement() throws Exception {
// Is it better to use a sync or a thread local here?
BenchmarkTest benchmark = new BenchmarkTest();
- Runnable[] tests = new Runnable[] {
- new TimeDateElementBenchmarkTest_Sync(),
- new TimeDateElementBenchmarkTest_Local(),
- new TimeDateElementBenchmarkTest_LocalStruct(),
+ Runnable[] tests = new Runnable[] { new TimeDateElementBenchmarkTest_Sync(),
+ new TimeDateElementBenchmarkTest_Local(), new TimeDateElementBenchmarkTest_LocalStruct(),
new TimeDateElementBenchmarkTest_LocalStruct_SBuilder() };
benchmark.doTest(5, tests);
}
private abstract static class TimeDateElementBenchmarkTestBase {
- protected static final String months[] = { "Jan", "Feb", "Mar", "Apr",
- "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+ protected static final String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
+ "Nov", "Dec" };
protected String lookup(String month) {
int index;
@@ -198,8 +192,8 @@ public class Benchmarks {
}
}
- private static class TimeDateElementBenchmarkTest_Sync extends
- TimeDateElementBenchmarkTestBase implements Runnable {
+ private static class TimeDateElementBenchmarkTest_Sync extends TimeDateElementBenchmarkTestBase
+ implements Runnable {
@Override
public String toString() {
@@ -211,8 +205,7 @@ public class Benchmarks {
private SimpleDateFormat dayFormatter = new SimpleDateFormat("dd");
private SimpleDateFormat monthFormatter = new SimpleDateFormat("MM");
private SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy");
- private SimpleDateFormat timeFormatter = new SimpleDateFormat(
- "hh:mm:ss");
+ private SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm:ss");
@Override
public void run() {
@@ -257,8 +250,8 @@ public class Benchmarks {
}
}
- private static class TimeDateElementBenchmarkTest_Local extends
- TimeDateElementBenchmarkTestBase implements Runnable {
+ private static class TimeDateElementBenchmarkTest_Local extends TimeDateElementBenchmarkTestBase
+ implements Runnable {
@Override
public String toString() {
@@ -308,17 +301,13 @@ public class Benchmarks {
if (currentDateStringLocal.get() == null) {
StringBuilder current = new StringBuilder(32);
current.append('[');
- current.append(dayFormatterLocal.get().format(
- currentDateLocal.get())); // Day
+ current.append(dayFormatterLocal.get().format(currentDateLocal.get())); // Day
current.append('/');
- current.append(lookup(monthFormatterLocal.get().format(
- currentDateLocal.get()))); // Month
+ current.append(lookup(monthFormatterLocal.get().format(currentDateLocal.get()))); // Month
current.append('/');
- current.append(yearFormatterLocal.get().format(
- currentDateLocal.get())); // Year
+ current.append(yearFormatterLocal.get().format(currentDateLocal.get())); // Year
current.append(':');
- current.append(timeFormatterLocal.get().format(
- currentDateLocal.get())); // Time
+ current.append(timeFormatterLocal.get().format(currentDateLocal.get())); // Time
current.append(']');
currentDateStringLocal.set(current.toString());
}
@@ -335,8 +324,8 @@ public class Benchmarks {
}
}
- private static class TimeDateElementBenchmarkTest_LocalStruct extends
- TimeDateElementBenchmarkTestBase implements Runnable {
+ private static class TimeDateElementBenchmarkTest_LocalStruct extends TimeDateElementBenchmarkTestBase
+ implements Runnable {
@Override
public String toString() {
@@ -349,8 +338,7 @@ public class Benchmarks {
public SimpleDateFormat dayFormatter = new SimpleDateFormat("dd");
public SimpleDateFormat monthFormatter = new SimpleDateFormat("MM");
public SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy");
- public SimpleDateFormat timeFormatter = new SimpleDateFormat(
- "hh:mm:ss");
+ public SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm:ss");
}
private ThreadLocal<Struct> structLocal = new ThreadLocal<>() {
@@ -373,8 +361,7 @@ public class Benchmarks {
current.append('[');
current.append(struct.dayFormatter.format(struct.currentDate)); // Day
current.append('/');
- current.append(lookup(struct.monthFormatter
- .format(struct.currentDate))); // Month
+ current.append(lookup(struct.monthFormatter.format(struct.currentDate))); // Month
current.append('/');
current.append(struct.yearFormatter.format(struct.currentDate)); // Year
current.append(':');
@@ -396,8 +383,8 @@ public class Benchmarks {
}
}
- private static class TimeDateElementBenchmarkTest_LocalStruct_SBuilder extends
- TimeDateElementBenchmarkTestBase implements Runnable {
+ private static class TimeDateElementBenchmarkTest_LocalStruct_SBuilder extends TimeDateElementBenchmarkTestBase
+ implements Runnable {
@Override
public String toString() {
@@ -410,8 +397,7 @@ public class Benchmarks {
public SimpleDateFormat dayFormatter = new SimpleDateFormat("dd");
public SimpleDateFormat monthFormatter = new SimpleDateFormat("MM");
public SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy");
- public SimpleDateFormat timeFormatter = new SimpleDateFormat(
- "hh:mm:ss");
+ public SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm:ss");
}
private ThreadLocal<Struct> structLocal = new ThreadLocal<>() {
@@ -434,8 +420,7 @@ public class Benchmarks {
current.append('[');
current.append(struct.dayFormatter.format(struct.currentDate)); // Day
current.append('/');
- current.append(lookup(struct.monthFormatter
- .format(struct.currentDate))); // Month
+ current.append(lookup(struct.monthFormatter.format(struct.currentDate))); // Month
current.append('/');
current.append(struct.yearFormatter.format(struct.currentDate)); // Year
current.append(':');
@@ -466,8 +451,7 @@ public class Benchmarks {
}
}
- private void doTestInternal(int threadCount, int iterations,
- Runnable test) throws Exception {
+ private void doTestInternal(int threadCount, int iterations, Runnable test) throws Exception {
long start = System.currentTimeMillis();
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
@@ -481,10 +465,8 @@ public class Benchmarks {
}
long end = System.currentTimeMillis();
- System.out.println(test.getClass().getSimpleName() + ": "
- + threadCount + " threads and " + iterations
- + " iterations using " + test + " took " + (end - start)
- + "ms");
+ System.out.println(test.getClass().getSimpleName() + ": " + threadCount + " threads and " + iterations +
+ " iterations using " + test + " took " + (end - start) + "ms");
}
}
diff --git a/test/org/apache/catalina/valves/TestAccessLogValve.java b/test/org/apache/catalina/valves/TestAccessLogValve.java
index 0fdfea44ba..d4b76e43f0 100644
--- a/test/org/apache/catalina/valves/TestAccessLogValve.java
+++ b/test/org/apache/catalina/valves/TestAccessLogValve.java
@@ -33,13 +33,10 @@ public class TestAccessLogValve {
final int cacheSize = 10;
- SimpleDateFormat sdf =
- new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]", Locale.US);
+ SimpleDateFormat sdf = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]", Locale.US);
sdf.setTimeZone(TimeZone.getDefault());
- AccessLogValve.DateFormatCache dfc =
- new AccessLogValve.DateFormatCache(
- cacheSize, Locale.US, null);
+ AccessLogValve.DateFormatCache dfc = new AccessLogValve.DateFormatCache(cacheSize, Locale.US, null);
// Create an array to hold the expected values
String[] expected = new String[cacheSize];
@@ -58,13 +55,13 @@ public class TestAccessLogValve {
Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
// Jump 2 ahead and then confirm (skipped value should be null)
- dfc.getFormat((cacheSize + 2)* 1000);
+ dfc.getFormat((cacheSize + 2) * 1000);
expected[1] = null;
expected[2] = generateExpected(sdf, cacheSize + 2);
Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
// Back 1 to fill in the gap
- dfc.getFormat((cacheSize + 1)* 1000);
+ dfc.getFormat((cacheSize + 1) * 1000);
expected[1] = generateExpected(sdf, cacheSize + 1);
Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
diff --git a/test/org/apache/catalina/valves/TestCrawlerSessionManagerValve.java b/test/org/apache/catalina/valves/TestCrawlerSessionManagerValve.java
index 9e53c4e35b..9c535ca416 100644
--- a/test/org/apache/catalina/valves/TestCrawlerSessionManagerValve.java
+++ b/test/org/apache/catalina/valves/TestCrawlerSessionManagerValve.java
@@ -52,7 +52,6 @@ public class TestCrawlerSessionManagerValve {
}
-
@Test
public void testCrawlerIpsPositive() throws Exception {
CrawlerSessionManagerValve valve = new CrawlerSessionManagerValve();
@@ -152,7 +151,8 @@ public class TestCrawlerSessionManagerValve {
private void verifyCrawlingContext(CrawlerSessionManagerValve valve, String contextPath)
throws IOException, ServletException {
HttpSession session = createSessionExpectations(valve, true);
- Request request = createRequestExpectations("127.0.0.1", session, true, "localhost", contextPath, "tomcatBot 1.0");
+ Request request = createRequestExpectations("127.0.0.1", session, true, "localhost", contextPath,
+ "tomcatBot 1.0");
EasyMock.replay(request, session);
@@ -166,7 +166,8 @@ public class TestCrawlerSessionManagerValve {
HttpSession session = EasyMock.createMock(HttpSession.class);
if (isBot) {
EasyMock.expect(session.getId()).andReturn("id").times(2);
- session.setAttribute(EasyMock.eq(valve.getClass().getName()), EasyMock.anyObject(HttpSessionBindingListener.class));
+ session.setAttribute(EasyMock.eq(valve.getClass().getName()),
+ EasyMock.anyObject(HttpSessionBindingListener.class));
EasyMock.expectLastCall();
session.setMaxInactiveInterval(60);
EasyMock.expectLastCall();
@@ -185,12 +186,12 @@ public class TestCrawlerSessionManagerValve {
EasyMock.expect(request.getRemoteAddr()).andReturn(ip);
EasyMock.expect(request.getHost()).andReturn(simpleHostWithName(hostname));
EasyMock.expect(request.getContext()).andReturn(simpleContextWithName(contextPath));
- IExpectationSetters<HttpSession> setter = EasyMock.expect(request.getSession(false))
- .andReturn(null);
+ IExpectationSetters<HttpSession> setter = EasyMock.expect(request.getSession(false)).andReturn(null);
if (isBot) {
setter.andReturn(session);
}
- EasyMock.expect(request.getHeaders("user-agent")).andAnswer(() -> Collections.enumeration(Arrays.asList(userAgent)));
+ EasyMock.expect(request.getHeaders("user-agent"))
+ .andAnswer(() -> Collections.enumeration(Arrays.asList(userAgent)));
return request;
}
diff --git a/test/org/apache/catalina/valves/TestErrorReportValve.java b/test/org/apache/catalina/valves/TestErrorReportValve.java
index 979d57a4da..762159dbf0 100644
--- a/test/org/apache/catalina/valves/TestErrorReportValve.java
+++ b/test/org/apache/catalina/valves/TestErrorReportValve.java
@@ -58,8 +58,8 @@ public class TestErrorReportValve extends TomcatBaseTest {
ByteChunk res = new ByteChunk();
res.setCharset(StandardCharsets.UTF_8);
getUrl("http://localhost:" + getPort(), res, null);
- Assert.assertTrue(res.toString().contains("<p><b>" + sm.getString("errorReportValve.message") + "</b> " +
- ErrorServlet.ERROR_TEXT + "</p>"));
+ Assert.assertTrue(res.toString().contains(
+ "<p><b>" + sm.getString("errorReportValve.message") + "</b> " + ErrorServlet.ERROR_TEXT + "</p>"));
}
@@ -67,11 +67,10 @@ public class TestErrorReportValve extends TomcatBaseTest {
private static final long serialVersionUID = 1L;
private static final String ERROR_TEXT = "The wheels fell off.";
+
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
- req.setAttribute(RequestDispatcher.ERROR_EXCEPTION,
- new Throwable(ERROR_TEXT));
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setAttribute(RequestDispatcher.ERROR_EXCEPTION, new Throwable(ERROR_TEXT));
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
@@ -128,8 +127,7 @@ public class TestErrorReportValve extends TomcatBaseTest {
}
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (setNotFound) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
@@ -170,8 +168,7 @@ public class TestErrorReportValve extends TomcatBaseTest {
private static final String ERROR_MESSAGE = "The sky is falling";
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.sendError(ERROR_STATUS, ERROR_MESSAGE);
}
}
@@ -185,8 +182,7 @@ public class TestErrorReportValve extends TomcatBaseTest {
Context ctx = tomcat.addContext("", null);
Bug56042Servlet bug56042Servlet = new Bug56042Servlet();
- Wrapper wrapper =
- Tomcat.addServlet(ctx, "bug56042Servlet", bug56042Servlet);
+ Wrapper wrapper = Tomcat.addServlet(ctx, "bug56042Servlet", bug56042Servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMappingDecoded("/bug56042Servlet", "bug56042Servlet");
@@ -208,8 +204,7 @@ public class TestErrorReportValve extends TomcatBaseTest {
private static final long serialVersionUID = 1L;
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException {
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Only set the status on the first call (the dispatch will trigger
// another call to this Servlet)
if (resp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) {
@@ -223,9 +218,9 @@ public class TestErrorReportValve extends TomcatBaseTest {
private static final class ExceptionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
+
@Override
- public void service(ServletRequest request, ServletResponse response)
- throws IOException {
+ public void service(ServletRequest request, ServletResponse response) throws IOException {
throw new RuntimeException();
}
}
@@ -234,9 +229,9 @@ public class TestErrorReportValve extends TomcatBaseTest {
private static final class ErrorPageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
+
@Override
- public void service(ServletRequest request, ServletResponse response)
- throws IOException {
+ public void service(ServletRequest request, ServletResponse response) throws IOException {
response.getWriter().print("OK");
}
}
diff --git a/test/org/apache/catalina/valves/TestLoadBalancerDrainingValve.java b/test/org/apache/catalina/valves/TestLoadBalancerDrainingValve.java
index 8ef57816ff..b2b1fa0683 100644
--- a/test/org/apache/catalina/valves/TestLoadBalancerDrainingValve.java
+++ b/test/org/apache/catalina/valves/TestLoadBalancerDrainingValve.java
@@ -53,22 +53,22 @@ public class TestLoadBalancerDrainingValve {
String[] queryStrings = new String[] { null, "foo=bar" };
List<Object[]> parameterSets = new ArrayList<>();
- for (String jkActivation : jkActivations) {
- for (Boolean validSessionId : booleans) {
- for (Boolean enableIgnore : booleans) {
- Boolean expectInvokeNext = Boolean.valueOf("ACT".equals(jkActivation) || enableIgnore.booleanValue() ||
- validSessionId.booleanValue());
- for (String queryString : queryStrings) {
- for (Boolean secureRequest : booleans) {
- for (Boolean secureSessionConfig : booleans) {
- parameterSets.add(new Object[] { jkActivation, validSessionId, expectInvokeNext,
- enableIgnore, queryString, secureRequest, secureSessionConfig});
- }
+ for (String jkActivation : jkActivations) {
+ for (Boolean validSessionId : booleans) {
+ for (Boolean enableIgnore : booleans) {
+ Boolean expectInvokeNext = Boolean.valueOf(
+ "ACT".equals(jkActivation) || enableIgnore.booleanValue() || validSessionId.booleanValue());
+ for (String queryString : queryStrings) {
+ for (Boolean secureRequest : booleans) {
+ for (Boolean secureSessionConfig : booleans) {
+ parameterSets.add(new Object[] { jkActivation, validSessionId, expectInvokeNext,
+ enableIgnore, queryString, secureRequest, secureSessionConfig });
}
}
}
}
}
+ }
return parameterSets;
}
@@ -117,19 +117,22 @@ public class TestLoadBalancerDrainingValve {
EasyMock.expect(ctx.getName()).andStubReturn("");
EasyMock.expect(ctx.getPipeline()).andStubReturn(new StandardPipeline());
EasyMock.expect(ctx.getDomain()).andStubReturn("foo");
- EasyMock.expect(ctx.getLogger()).andStubReturn(org.apache.juli.logging.LogFactory.getLog(LoadBalancerDrainingValve.class));
+ EasyMock.expect(ctx.getLogger())
+ .andStubReturn(org.apache.juli.logging.LogFactory.getLog(LoadBalancerDrainingValve.class));
EasyMock.expect(ctx.getServletContext()).andStubReturn(servletContext);
// Set up the actual test
- EasyMock.expect(request.getAttribute(LoadBalancerDrainingValve.ATTRIBUTE_KEY_JK_LB_ACTIVATION)).andStubReturn(jkActivation);
- EasyMock.expect(Boolean.valueOf(request.isRequestedSessionIdValid())).andStubReturn(Boolean.valueOf(validSessionId));
+ EasyMock.expect(request.getAttribute(LoadBalancerDrainingValve.ATTRIBUTE_KEY_JK_LB_ACTIVATION))
+ .andStubReturn(jkActivation);
+ EasyMock.expect(Boolean.valueOf(request.isRequestedSessionIdValid()))
+ .andStubReturn(Boolean.valueOf(validSessionId));
ArrayList<Cookie> cookies = new ArrayList<>();
- if(enableIgnore) {
+ if (enableIgnore) {
cookies.add(new Cookie("ignore", "true"));
}
- if(!validSessionId && jkActivation.equals("DIS")) {
+ if (!validSessionId && jkActivation.equals("DIS")) {
MyCookie cookie = new MyCookie(cookieConfig.getName(), sessionId);
cookie.setPath(cookieConfig.getPath());
cookie.setValue(sessionId);
@@ -146,7 +149,8 @@ public class TestLoadBalancerDrainingValve {
EasyMock.expect(ctx.getSessionCookiePath()).andStubReturn("/");
if (!enableIgnore) {
- EasyMock.expect(Boolean.valueOf(ctx.getSessionCookiePathUsesTrailingSlash())).andStubReturn(Boolean.TRUE);
+ EasyMock.expect(Boolean.valueOf(ctx.getSessionCookiePathUsesTrailingSlash()))
+ .andStubReturn(Boolean.TRUE);
EasyMock.expect(request.getQueryString()).andStubReturn(queryString);
// Response will have cookie deleted
MyCookie expectedCookie = new MyCookie(cookieConfig.getName(), "");
@@ -159,8 +163,8 @@ public class TestLoadBalancerDrainingValve {
response.addCookie(expectedCookie);
EasyMock.expect(ctx.getSessionCookieName()).andReturn(sessionCookieName); // Indirect call
String expectedRequestURI = requestURI;
- if(null != queryString) {
- expectedRequestURI = expectedRequestURI + '?' + queryString;
+ if (null != queryString) {
+ expectedRequestURI = expectedRequestURI + '?' + queryString;
}
response.setHeader("Location", expectedRequestURI);
response.setStatus(307);
@@ -169,7 +173,7 @@ public class TestLoadBalancerDrainingValve {
Valve next = control.createMock(Valve.class);
- if(expectInvokeNext) {
+ if (expectInvokeNext) {
// Expect the "next" Valve to fire
// Next 2 lines are basically EasyMock.expect(next.invoke(req,res)) but for a void method
next.invoke(request, response);
@@ -196,40 +200,48 @@ public class TestLoadBalancerDrainingValve {
private String name;
- private final Map<String,String> attributes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private final Map<String, String> attributes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
@Override
public String getName() {
return name;
}
+
@Override
public void setName(String name) {
this.name = name;
}
+
@Override
public String getDomain() {
return attributes.get(Constants.COOKIE_DOMAIN_ATTR);
}
+
@Override
public void setDomain(String domain) {
attributes.put(Constants.COOKIE_DOMAIN_ATTR, domain);
}
+
@Override
public String getPath() {
return attributes.get(Constants.COOKIE_PATH_ATTR);
}
+
@Override
public void setPath(String path) {
attributes.put(Constants.COOKIE_PATH_ATTR, path);
}
+
@Override
public String getComment() {
return null;
}
+
@Override
public void setComment(String comment) {
// NO-OP
}
+
@Override
public boolean isHttpOnly() {
String httpOnly = getAttribute(Constants.COOKIE_HTTP_ONLY_ATTR);
@@ -238,10 +250,12 @@ public class TestLoadBalancerDrainingValve {
}
return Boolean.parseBoolean(httpOnly);
}
+
@Override
public void setHttpOnly(boolean httpOnly) {
setAttribute(Constants.COOKIE_HTTP_ONLY_ATTR, Boolean.toString(httpOnly));
}
+
@Override
public boolean isSecure() {
String secure = getAttribute(Constants.COOKIE_SECURE_ATTR);
@@ -250,10 +264,12 @@ public class TestLoadBalancerDrainingValve {
}
return Boolean.parseBoolean(secure);
}
+
@Override
public void setSecure(boolean secure) {
setAttribute(Constants.COOKIE_SECURE_ATTR, Boolean.toString(secure));
}
+
@Override
public int getMaxAge() {
String maxAge = getAttribute(Constants.COOKIE_MAX_AGE_ATTR);
@@ -262,18 +278,22 @@ public class TestLoadBalancerDrainingValve {
}
return Integer.parseInt(maxAge);
}
+
@Override
public void setMaxAge(int maxAge) {
setAttribute(Constants.COOKIE_MAX_AGE_ATTR, Integer.toString(maxAge));
}
+
@Override
public void setAttribute(String name, String value) {
attributes.put(name, value);
}
+
@Override
public String getAttribute(String name) {
return attributes.get(name);
}
+
@Override
public Map<String, String> getAttributes() {
return Collections.unmodifiableMap(attributes);
@@ -285,19 +305,19 @@ public class TestLoadBalancerDrainingValve {
private static class MyCookie extends Cookie {
private static final long serialVersionUID = 1L;
- MyCookie(String name, String value) { super(name, value); }
+ MyCookie(String name, String value) {
+ super(name, value);
+ }
@Override
public boolean equals(Object o) {
- if(!(o instanceof MyCookie)) {
+ if (!(o instanceof MyCookie)) {
return false;
}
- MyCookie mc = (MyCookie)o;
- return mc.getName().equals(this.getName())
- && mc.getPath().equals(this.getPath())
- && mc.getValue().equals(this.getValue())
- && mc.getMaxAge() == this.getMaxAge();
+ MyCookie mc = (MyCookie) o;
+ return mc.getName().equals(this.getName()) && mc.getPath().equals(this.getPath()) &&
+ mc.getValue().equals(this.getValue()) && mc.getMaxAge() == this.getMaxAge();
}
@Override
@@ -314,7 +334,8 @@ public class TestLoadBalancerDrainingValve {
@Override
public String toString() {
- return "Cookie { name=" + getName() + ", value=" + getValue() + ", path=" + getPath() + ", maxAge=" + getMaxAge() + " }";
+ return "Cookie { name=" + getName() + ", value=" + getValue() + ", path=" + getPath() + ", maxAge=" +
+ getMaxAge() + " }";
}
}
}
diff --git a/test/org/apache/catalina/valves/TestRemoteIpValve.java b/test/org/apache/catalina/valves/TestRemoteIpValve.java
index ec225d7ac8..054dfe6fa8 100644
--- a/test/org/apache/catalina/valves/TestRemoteIpValve.java
+++ b/test/org/apache/catalina/valves/TestRemoteIpValve.java
@@ -166,7 +166,8 @@ public class TestRemoteIpValve {
request.setCoyoteRequest(new org.apache.coyote.Request());
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
- request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130, proxy1, proxy2");
+ request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
+ .setString("140.211.11.130, proxy1, proxy2");
// TEST
remoteIpValve.invoke(request, null);
@@ -176,7 +177,8 @@ public class TestRemoteIpValve {
Assert.assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = remoteAddrAndHostTrackerValve.getForwardedBy();
- Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2", actualXForwardedBy);
+ Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2",
+ actualXForwardedBy);
String actualRemoteAddr = remoteAddrAndHostTrackerValve.getRemoteAddr();
Assert.assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
@@ -207,7 +209,8 @@ public class TestRemoteIpValve {
request.setCoyoteRequest(new org.apache.coyote.Request());
request.setRemoteAddr("proxy3");
request.setRemoteHost("remote-host-original-value");
- request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130, proxy1, proxy2");
+ request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
+ .setString("140.211.11.130, proxy1, proxy2");
// TEST
remoteIpValve.invoke(request, null);
@@ -217,7 +220,8 @@ public class TestRemoteIpValve {
Assert.assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = remoteAddrAndHostTrackerValve.getForwardedBy();
- Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2,proxy3", actualXForwardedBy);
+ Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2,proxy3",
+ actualXForwardedBy);
String actualRemoteAddr = remoteAddrAndHostTrackerValve.getRemoteAddr();
Assert.assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
@@ -247,7 +251,8 @@ public class TestRemoteIpValve {
request.setCoyoteRequest(new org.apache.coyote.Request());
request.setRemoteAddr("proxy3");
request.setRemoteHost("remote-host-original-value");
- request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130, proxy1, proxy2");
+ request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
+ .setString("140.211.11.130, proxy1, proxy2");
// TEST
remoteIpValve.invoke(request, null);
@@ -257,7 +262,8 @@ public class TestRemoteIpValve {
Assert.assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = remoteAddrAndHostTrackerValve.getForwardedBy();
- Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2,proxy3", actualXForwardedBy);
+ Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2,proxy3",
+ actualXForwardedBy);
String actualRemoteAddr = remoteAddrAndHostTrackerValve.getRemoteAddr();
Assert.assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
@@ -289,7 +295,7 @@ public class TestRemoteIpValve {
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
- .setString("140.211.11.130, proxy1, proxy2, 192.168.0.10, 192.168.0.11");
+ .setString("140.211.11.130, proxy1, proxy2, 192.168.0.10, 192.168.0.11");
// TEST
remoteIpValve.invoke(request, null);
@@ -299,7 +305,8 @@ public class TestRemoteIpValve {
Assert.assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = remoteAddrAndHostTrackerValve.getForwardedBy();
- Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2", actualXForwardedBy);
+ Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2",
+ actualXForwardedBy);
String actualRemoteAddr = remoteAddrAndHostTrackerValve.getRemoteAddr();
Assert.assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
@@ -330,7 +337,8 @@ public class TestRemoteIpValve {
request.setCoyoteRequest(new org.apache.coyote.Request());
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
- request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130, 192.168.0.10, 192.168.0.11");
+ request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
+ .setString("140.211.11.130, 192.168.0.10, 192.168.0.11");
// TEST
remoteIpValve.invoke(request, null);
@@ -383,7 +391,8 @@ public class TestRemoteIpValve {
Assert.assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = remoteAddrAndHostTrackerValve.getForwardedBy();
- Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2", actualXForwardedBy);
+ Assert.assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1,proxy2",
+ actualXForwardedBy);
String actualRemoteAddr = remoteAddrAndHostTrackerValve.getRemoteAddr();
Assert.assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
@@ -403,7 +412,8 @@ public class TestRemoteIpValve {
// PREPARE
RemoteIpValve remoteIpValve = new RemoteIpValve();
- remoteIpValve.setInternalProxies("172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}");
+ remoteIpValve.setInternalProxies(
+ "172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}");
remoteIpValve.setRemoteIpHeader("x-forwarded-for");
remoteIpValve.setProtocolHeader("x-forwarded-proto");
RemoteAddrAndHostTrackerValve remoteAddrAndHostTrackerValve = new RemoteAddrAndHostTrackerValve();
@@ -439,7 +449,7 @@ public class TestRemoteIpValve {
Assert.assertTrue("request from internal proxy should be marked secure", isSecure);
String scheme = remoteAddrAndHostTrackerValve.getScheme();
- Assert.assertEquals("Scheme should be marked to https.","https",scheme);
+ Assert.assertEquals("Scheme should be marked to https.", "https", scheme);
request = new MockRequest();
request.setCoyoteRequest(new org.apache.coyote.Request());
@@ -471,7 +481,7 @@ public class TestRemoteIpValve {
Assert.assertTrue("request from internal proxy should be marked secure", isSecure);
scheme = remoteAddrAndHostTrackerValve.getScheme();
- Assert.assertEquals("Scheme should be marked to https.","https",scheme);
+ Assert.assertEquals("Scheme should be marked to https.", "https", scheme);
}
@@ -678,17 +688,20 @@ public class TestRemoteIpValve {
}
@Test
- public void testInvokeXforwardedProtoSaysMultipleForwardsWithFirstBeingHttpForIncomingHttpsRequest() throws Exception {
+ public void testInvokeXforwardedProtoSaysMultipleForwardsWithFirstBeingHttpForIncomingHttpsRequest()
+ throws Exception {
performXForwardedProtoWithMultipleForwardsTest("http,https", true, false);
}
@Test
- public void testInvokeXforwardedProtoSaysMultipleForwardsWithLastBeingHttpForIncomingHttpRequest() throws Exception {
+ public void testInvokeXforwardedProtoSaysMultipleForwardsWithLastBeingHttpForIncomingHttpRequest()
+ throws Exception {
performXForwardedProtoWithMultipleForwardsTest("https,http", false, false);
}
@Test
- public void testInvokeXforwardedProtoSaysMultipleForwardsWithMiddleBeingHttpForIncomingHttpsRequest() throws Exception {
+ public void testInvokeXforwardedProtoSaysMultipleForwardsWithMiddleBeingHttpForIncomingHttpsRequest()
+ throws Exception {
performXForwardedProtoWithMultipleForwardsTest("https,http,https", true, false);
}
@@ -702,8 +715,8 @@ public class TestRemoteIpValve {
performXForwardedProtoWithMultipleForwardsTest(",", false, false);
}
- private void performXForwardedProtoWithMultipleForwardsTest(String incomingHeaderValue,
- boolean arrivesAsSecure, boolean shouldBeSecure) throws Exception {
+ private void performXForwardedProtoWithMultipleForwardsTest(String incomingHeaderValue, boolean arrivesAsSecure,
+ boolean shouldBeSecure) throws Exception {
// PREPARE
String incomingScheme = arrivesAsSecure ? "https" : "http";
@@ -759,12 +772,12 @@ public class TestRemoteIpValve {
Assert.assertEquals("x-forwarded-proto says " + expectedScheme, expectedServerPort, actualServerPort);
boolean actualSecure = remoteAddrAndHostTrackerValve.isSecure();
- Assert.assertEquals("x-forwarded-proto says " + expectedScheme,
- Boolean.valueOf(shouldBeSecure), Boolean.valueOf(actualSecure));
+ Assert.assertEquals("x-forwarded-proto says " + expectedScheme, Boolean.valueOf(shouldBeSecure),
+ Boolean.valueOf(actualSecure));
boolean actualPostInvokeSecure = request.isSecure();
- Assert.assertEquals("postInvoke secure",
- Boolean.valueOf(arrivesAsSecure), Boolean.valueOf(actualPostInvokeSecure));
+ Assert.assertEquals("postInvoke secure", Boolean.valueOf(arrivesAsSecure),
+ Boolean.valueOf(actualPostInvokeSecure));
int actualPostInvokeServerPort = request.getServerPort();
Assert.assertEquals("postInvoke serverPort", incomingServerPort, actualPostInvokeServerPort);
@@ -965,7 +978,8 @@ public class TestRemoteIpValve {
request.setCoyoteRequest(new org.apache.coyote.Request());
request.setRemoteAddr("not-allowed-internal-proxy");
request.setRemoteHost("not-allowed-internal-proxy-host");
- request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130, proxy1, proxy2");
+ request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
+ .setString("140.211.11.130, proxy1, proxy2");
// TEST
remoteIpValve.invoke(request, null);
@@ -1006,17 +1020,19 @@ public class TestRemoteIpValve {
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
- .setString("140.211.11.130, proxy1, untrusted-proxy, proxy2");
+ .setString("140.211.11.130, proxy1, untrusted-proxy, proxy2");
// TEST
remoteIpValve.invoke(request, null);
// VERIFY
String actualXForwardedFor = remoteAddrAndHostTrackerValve.getForwardedFor();
- Assert.assertEquals("ip/host before untrusted-proxy must appear in x-forwarded-for", "140.211.11.130,proxy1", actualXForwardedFor);
+ Assert.assertEquals("ip/host before untrusted-proxy must appear in x-forwarded-for", "140.211.11.130,proxy1",
+ actualXForwardedFor);
String actualXForwardedBy = remoteAddrAndHostTrackerValve.getForwardedBy();
- Assert.assertEquals("ip/host after untrusted-proxy must appear in x-forwarded-by", "proxy2", actualXForwardedBy);
+ Assert.assertEquals("ip/host after untrusted-proxy must appear in x-forwarded-by", "proxy2",
+ actualXForwardedBy);
String actualRemoteAddr = remoteAddrAndHostTrackerValve.getRemoteAddr();
Assert.assertEquals("remoteAddr", "untrusted-proxy", actualRemoteAddr);
@@ -1034,18 +1050,14 @@ public class TestRemoteIpValve {
@Test
public void testCommaDelimitedListToStringArray() {
String[] actual = RemoteIpValve.commaDelimitedListToStringArray("element1, element2, element3");
- String[] expected = new String[] {
- "element1", "element2", "element3"
- };
+ String[] expected = new String[] { "element1", "element2", "element3" };
assertArrayEquals(expected, actual);
}
@Test
public void testCommaDelimitedListToStringArrayMixedSpaceChars() {
String[] actual = RemoteIpValve.commaDelimitedListToStringArray("element1 , element2,\t element3");
- String[] expected = new String[] {
- "element1", "element2", "element3"
- };
+ String[] expected = new String[] { "element1", "element2", "element3" };
assertArrayEquals(expected, actual);
}
@@ -1073,16 +1085,13 @@ public class TestRemoteIpValve {
remoteIpValve.invoke(request, null);
// VERIFY
- Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort",
- Integer.valueOf(8080),
+ Assert.assertEquals("org.apache.catalina.AccessLog.ServerPort", Integer.valueOf(8080),
request.getAttribute(AccessLog.SERVER_PORT_ATTRIBUTE));
- Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr",
- "140.211.11.130",
+ Assert.assertEquals("org.apache.catalina.AccessLog.RemoteAddr", "140.211.11.130",
request.getAttribute(AccessLog.REMOTE_ADDR_ATTRIBUTE));
- Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost",
- "140.211.11.130",
+ Assert.assertEquals("org.apache.catalina.AccessLog.RemoteHost", "140.211.11.130",
request.getAttribute(AccessLog.REMOTE_HOST_ATTRIBUTE));
}
@@ -1110,8 +1119,7 @@ public class TestRemoteIpValve {
remoteIpValve.invoke(request, null);
// VERIFY
- Assert.assertEquals("org.apache.tomcat.request.forwarded",
- Boolean.TRUE,
+ Assert.assertEquals("org.apache.tomcat.request.forwarded", Boolean.TRUE,
request.getAttribute(Globals.REQUEST_FORWARDED_ATTRIBUTE));
}
@@ -1139,15 +1147,15 @@ public class TestRemoteIpValve {
// VERIFY
Assert.assertEquals("140.211.11.130:1234", remoteAddrAndHostTrackerValve.getRemoteAddr());
- }
+ }
@Test
public void testRequestForwardedForWithProxyPortNumber() throws Exception {
// PREPARE
RemoteIpValve remoteIpValve = new RemoteIpValve();
- //remoteIpValve.setRemoteIpHeader("x-forwarded-for");
- //remoteIpValve.setProtocolHeader("x-forwarded-proto");
+ // remoteIpValve.setRemoteIpHeader("x-forwarded-for");
+ // remoteIpValve.setProtocolHeader("x-forwarded-proto");
RemoteAddrAndHostTrackerValve remoteAddrAndHostTrackerValve = new RemoteAddrAndHostTrackerValve();
remoteIpValve.setNext(remoteAddrAndHostTrackerValve);
@@ -1158,7 +1166,8 @@ public class TestRemoteIpValve {
request.setRemoteHost("192.168.0.10");
// Trust c.d
remoteIpValve.setTrustedProxies("foo\\.bar:123");
- request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for").setString("140.211.11.130:1234, foo.bar:123");
+ request.getCoyoteRequest().getMimeHeaders().addValue("x-forwarded-for")
+ .setString("140.211.11.130:1234, foo.bar:123");
// protocol
request.setServerPort(8080);
request.getCoyoteRequest().scheme().setString("http");
@@ -1169,7 +1178,7 @@ public class TestRemoteIpValve {
// VERIFY
Assert.assertEquals("140.211.11.130:1234", remoteAddrAndHostTrackerValve.getRemoteAddr());
- }
+ }
private void assertArrayEquals(String[] expected, String[] actual) {
if (expected == null) {
diff --git a/test/org/apache/catalina/valves/TestRequestFilterValve.java b/test/org/apache/catalina/valves/TestRequestFilterValve.java
index f4b1c3738b..2deb7db5a4 100644
--- a/test/org/apache/catalina/valves/TestRequestFilterValve.java
+++ b/test/org/apache/catalina/valves/TestRequestFilterValve.java
@@ -34,41 +34,41 @@ import org.apache.catalina.core.StandardContext;
*/
public class TestRequestFilterValve {
- private static final int OK = 200;
+ private static final int OK = 200;
private static final int FORBIDDEN = 403;
- private static final int CUSTOM = 499;
+ private static final int CUSTOM = 499;
- private static final String ADDR_ALLOW_PAT = "127\\.\\d*\\.\\d*\\.\\d*";
- private static final String ADDR_DENY_PAT = "\\d*\\.\\d*\\.\\d*\\.1";
- private static final String ADDR_ONLY_ALLOW = "127.0.0.2";
- private static final String ADDR_ONLY_DENY = "192.168.0.1";
- private static final String ADDR_ALLOW_AND_DENY = "127.0.0.1";
+ private static final String ADDR_ALLOW_PAT = "127\\.\\d*\\.\\d*\\.\\d*";
+ private static final String ADDR_DENY_PAT = "\\d*\\.\\d*\\.\\d*\\.1";
+ private static final String ADDR_ONLY_ALLOW = "127.0.0.2";
+ private static final String ADDR_ONLY_DENY = "192.168.0.1";
+ private static final String ADDR_ALLOW_AND_DENY = "127.0.0.1";
private static final String ADDR_NO_ALLOW_NO_DENY = "192.168.0.2";
- private static final String HOST_ALLOW_PAT = "www\\.example\\.[a-zA-Z0-9-]*";
- private static final String HOST_DENY_PAT = ".*\\.org";
- private static final String HOST_ONLY_ALLOW = "www.example.com";
- private static final String HOST_ONLY_DENY = "host.example.org";
- private static final String HOST_ALLOW_AND_DENY = "www.example.org";
+ private static final String HOST_ALLOW_PAT = "www\\.example\\.[a-zA-Z0-9-]*";
+ private static final String HOST_DENY_PAT = ".*\\.org";
+ private static final String HOST_ONLY_ALLOW = "www.example.com";
+ private static final String HOST_ONLY_DENY = "host.example.org";
+ private static final String HOST_ALLOW_AND_DENY = "www.example.org";
private static final String HOST_NO_ALLOW_NO_DENY = "host.example.com";
- private static final String CIDR_ALLOW_PROP = "127.0.0.0/16";
- private static final String CIDR_DENY_PROP = "192.168.0.0/24,127.0.0.0/24";
- private static final String CIDR_ONLY_ALLOW = "127.0.1.1";
- private static final String CIDR_ONLY_DENY = "192.168.0.1";
- private static final String CIDR_ALLOW_AND_DENY = "127.0.0.1";
+ private static final String CIDR_ALLOW_PROP = "127.0.0.0/16";
+ private static final String CIDR_DENY_PROP = "192.168.0.0/24,127.0.0.0/24";
+ private static final String CIDR_ONLY_ALLOW = "127.0.1.1";
+ private static final String CIDR_ONLY_DENY = "192.168.0.1";
+ private static final String CIDR_ALLOW_AND_DENY = "127.0.0.1";
private static final String CIDR_NO_ALLOW_NO_DENY = "192.168.1.1";
- private static final String CIDR6_ALLOW_PROP = "::/96";
- private static final String CIDR6_DENY_PROP = "::f:0:0/112,::/112";
- private static final String CIDR6_ONLY_ALLOW = "0:0:0:0:0:0:148f:1";
- private static final String CIDR6_ONLY_DENY = "0:0:0:0:0:F:0:a";
- private static final String CIDR6_ALLOW_AND_DENY = "0:0:0:0:0:0:0:fA8";
+ private static final String CIDR6_ALLOW_PROP = "::/96";
+ private static final String CIDR6_DENY_PROP = "::f:0:0/112,::/112";
+ private static final String CIDR6_ONLY_ALLOW = "0:0:0:0:0:0:148f:1";
+ private static final String CIDR6_ONLY_DENY = "0:0:0:0:0:F:0:a";
+ private static final String CIDR6_ALLOW_AND_DENY = "0:0:0:0:0:0:0:fA8";
private static final String CIDR6_NO_ALLOW_NO_DENY = "1:0:0:0:0:0:0:1";
private static final int PORT = 8080;
private static final String ADDR_OTHER = "1.2.3.4";
- private static final String PORT_MATCH_PATTERN = ";\\d*";
+ private static final String PORT_MATCH_PATTERN = ";\\d*";
private static final String PORT_NO_MATCH_PATTERN = ";8081";
@@ -92,22 +92,16 @@ public class TestRequestFilterValve {
}
}
- private void twoTests(String allow, String deny, boolean denyStatus,
- boolean addConnectorPort,
- boolean auth, String property, String type,
- boolean allowed) {
- oneTest(allow, deny, denyStatus, addConnectorPort, false,
- auth, property, type, allowed);
+ private void twoTests(String allow, String deny, boolean denyStatus, boolean addConnectorPort, boolean auth,
+ String property, String type, boolean allowed) {
+ oneTest(allow, deny, denyStatus, addConnectorPort, false, auth, property, type, allowed);
if (!type.equals("Host")) {
- oneTest(allow, deny, denyStatus, addConnectorPort, true,
- auth, property, type, allowed);
+ oneTest(allow, deny, denyStatus, addConnectorPort, true, auth, property, type, allowed);
}
}
- private void oneTest(String allow, String deny, boolean denyStatus,
- boolean addConnectorPort, boolean usePeerAddress,
- boolean auth, String property, String type,
- boolean allowed) {
+ private void oneTest(String allow, String deny, boolean denyStatus, boolean addConnectorPort,
+ boolean usePeerAddress, boolean auth, String property, String type, boolean allowed) {
// PREPARE
RequestFilterValve valve = null;
Connector connector = new Connector();
@@ -131,7 +125,7 @@ public class TestRequestFilterValve {
if (usePeerAddress) {
request.setRemoteAddr(ADDR_OTHER);
request.getCoyoteRequest().peerAddr().setString(property);
- ((RemoteAddrValve)valve).setUsePeerAddress(true);
+ ((RemoteAddrValve) valve).setUsePeerAddress(true);
msg.append(" peer='" + property + "'");
} else {
request.setRemoteAddr(property);
@@ -147,7 +141,7 @@ public class TestRequestFilterValve {
if (usePeerAddress) {
request.setRemoteAddr(ADDR_OTHER);
request.getCoyoteRequest().peerAddr().setString(property);
- ((RemoteCIDRValve)valve).setUsePeerAddress(true);
+ ((RemoteCIDRValve) valve).setUsePeerAddress(true);
msg.append(" peer='" + property + "'");
} else {
request.setRemoteAddr(property);
@@ -176,11 +170,11 @@ public class TestRequestFilterValve {
}
if (addConnectorPort) {
if (valve instanceof RemoteAddrValve) {
- ((RemoteAddrValve)valve).setAddConnectorPort(true);
+ ((RemoteAddrValve) valve).setAddConnectorPort(true);
} else if (valve instanceof RemoteHostValve) {
- ((RemoteHostValve)valve).setAddConnectorPort(true);
+ ((RemoteHostValve) valve).setAddConnectorPort(true);
} else if (valve instanceof RemoteCIDRValve) {
- ((RemoteCIDRValve)valve).setAddConnectorPort(true);
+ ((RemoteCIDRValve) valve).setAddConnectorPort(true);
} else {
Assert.fail("Can only set 'addConnectorPort' for RemoteAddrValve, RemoteHostValve and RemoteCIDRValve");
}
@@ -196,7 +190,7 @@ public class TestRequestFilterValve {
try {
valve.invoke(request, response);
} catch (IOException | ServletException ex) {
- //Ignore
+ // Ignore
}
// VERIFY
@@ -208,213 +202,195 @@ public class TestRequestFilterValve {
}
}
- private void standardTests(String allow_pat, String deny_pat,
- String OnlyAllow, String OnlyDeny,
- String AllowAndDeny, String NoAllowNoDeny,
- boolean auth, String type) {
+ private void standardTests(String allow_pat, String deny_pat, String OnlyAllow, String OnlyDeny,
+ String AllowAndDeny, String NoAllowNoDeny, boolean auth, String type) {
String apat;
String dpat;
// Test without ports
apat = allow_pat;
dpat = deny_pat;
- twoTests(null, null, false, false, auth, AllowAndDeny, type, false);
- twoTests(null, null, true, false, auth, AllowAndDeny, type, false);
- twoTests(apat, null, false, false, auth, AllowAndDeny, type, true);
+ twoTests(null, null, false, false, auth, AllowAndDeny, type, false);
+ twoTests(null, null, true, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, false, false, auth, AllowAndDeny, type, true);
twoTests(apat, null, false, false, auth, NoAllowNoDeny, type, false);
- twoTests(apat, null, true, false, auth, AllowAndDeny, type, true);
- twoTests(apat, null, true, false, auth, NoAllowNoDeny, type, false);
- twoTests(null, dpat, false, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, true, false, auth, AllowAndDeny, type, true);
+ twoTests(apat, null, true, false, auth, NoAllowNoDeny, type, false);
+ twoTests(null, dpat, false, false, auth, AllowAndDeny, type, false);
twoTests(null, dpat, false, false, auth, NoAllowNoDeny, type, true);
- twoTests(null, dpat, true, false, auth, AllowAndDeny, type, false);
- twoTests(null, dpat, true, false, auth, NoAllowNoDeny, type, true);
+ twoTests(null, dpat, true, false, auth, AllowAndDeny, type, false);
+ twoTests(null, dpat, true, false, auth, NoAllowNoDeny, type, true);
twoTests(apat, dpat, false, false, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, false, false, auth, OnlyAllow, type, true);
- twoTests(apat, dpat, false, false, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, false, false, auth, AllowAndDeny, type, false);
- twoTests(apat, dpat, true, false, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, true, false, auth, OnlyAllow, type, true);
- twoTests(apat, dpat, true, false, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, true, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, false, false, auth, OnlyAllow, type, true);
+ twoTests(apat, dpat, false, false, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, false, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, true, false, auth, NoAllowNoDeny, type, false);
+ twoTests(apat, dpat, true, false, auth, OnlyAllow, type, true);
+ twoTests(apat, dpat, true, false, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, true, false, auth, AllowAndDeny, type, false);
// Test with port in pattern but forgotten "addConnectorPort"
apat = allow_pat + PORT_MATCH_PATTERN;
dpat = deny_pat + PORT_MATCH_PATTERN;
- twoTests(null, null, false, false, auth, AllowAndDeny, type, false);
- twoTests(null, null, true, false, auth, AllowAndDeny, type, false);
- twoTests(apat, null, false, false, auth, AllowAndDeny, type, false);
+ twoTests(null, null, false, false, auth, AllowAndDeny, type, false);
+ twoTests(null, null, true, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, false, false, auth, AllowAndDeny, type, false);
twoTests(apat, null, false, false, auth, NoAllowNoDeny, type, false);
- twoTests(apat, null, true, false, auth, AllowAndDeny, type, false);
- twoTests(apat, null, true, false, auth, NoAllowNoDeny, type, false);
- twoTests(null, dpat, false, false, auth, AllowAndDeny, type, true);
+ twoTests(apat, null, true, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, true, false, auth, NoAllowNoDeny, type, false);
+ twoTests(null, dpat, false, false, auth, AllowAndDeny, type, true);
twoTests(null, dpat, false, false, auth, NoAllowNoDeny, type, true);
- twoTests(null, dpat, true, false, auth, AllowAndDeny, type, true);
- twoTests(null, dpat, true, false, auth, NoAllowNoDeny, type, true);
+ twoTests(null, dpat, true, false, auth, AllowAndDeny, type, true);
+ twoTests(null, dpat, true, false, auth, NoAllowNoDeny, type, true);
twoTests(apat, dpat, false, false, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, false, false, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, false, false, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, false, false, auth, AllowAndDeny, type, false);
- twoTests(apat, dpat, true, false, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, true, false, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, true, false, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, true, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, false, false, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, false, false, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, false, false, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, true, false, auth, NoAllowNoDeny, type, false);
+ twoTests(apat, dpat, true, false, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, true, false, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, true, false, auth, AllowAndDeny, type, false);
// Test with "addConnectorPort" but port not in pattern
apat = allow_pat;
dpat = deny_pat;
- twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
- twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, false, true, auth, AllowAndDeny, type, false);
twoTests(apat, null, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(null, dpat, false, true, auth, AllowAndDeny, type, true);
+ twoTests(apat, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(null, dpat, false, true, auth, AllowAndDeny, type, true);
twoTests(null, dpat, false, true, auth, NoAllowNoDeny, type, true);
- twoTests(null, dpat, true, true, auth, AllowAndDeny, type, true);
- twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
+ twoTests(null, dpat, true, true, auth, AllowAndDeny, type, true);
+ twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
twoTests(apat, dpat, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
- twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
// Test "addConnectorPort" and with port matching in both patterns
apat = allow_pat + PORT_MATCH_PATTERN;
dpat = deny_pat + PORT_MATCH_PATTERN;
- twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
- twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, false, true, auth, AllowAndDeny, type, true);
+ twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, false, true, auth, AllowAndDeny, type, true);
twoTests(apat, null, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, null, true, true, auth, AllowAndDeny, type, true);
- twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(null, dpat, false, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, true, true, auth, AllowAndDeny, type, true);
+ twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(null, dpat, false, true, auth, AllowAndDeny, type, false);
twoTests(null, dpat, false, true, auth, NoAllowNoDeny, type, true);
- twoTests(null, dpat, true, true, auth, AllowAndDeny, type, false);
- twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
+ twoTests(null, dpat, true, true, auth, AllowAndDeny, type, false);
+ twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
twoTests(apat, dpat, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyAllow, type, true);
- twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
- twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyAllow, type, true);
- twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, OnlyAllow, type, true);
+ twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyAllow, type, true);
+ twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
// Test "addConnectorPort" and with port not matching in both patterns
apat = allow_pat + PORT_NO_MATCH_PATTERN;
dpat = deny_pat + PORT_NO_MATCH_PATTERN;
- twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
- twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, false, true, auth, AllowAndDeny, type, false);
twoTests(apat, null, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(null, dpat, false, true, auth, AllowAndDeny, type, true);
+ twoTests(apat, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(null, dpat, false, true, auth, AllowAndDeny, type, true);
twoTests(null, dpat, false, true, auth, NoAllowNoDeny, type, true);
- twoTests(null, dpat, true, true, auth, AllowAndDeny, type, true);
- twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
+ twoTests(null, dpat, true, true, auth, AllowAndDeny, type, true);
+ twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
twoTests(apat, dpat, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
- twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
// Test "addConnectorPort" and with port matching only in allow
apat = allow_pat + PORT_MATCH_PATTERN;
dpat = deny_pat + PORT_NO_MATCH_PATTERN;
- twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
- twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, false, true, auth, AllowAndDeny, type, true);
+ twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, false, true, auth, AllowAndDeny, type, true);
twoTests(apat, null, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, null, true, true, auth, AllowAndDeny, type, true);
- twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(null, dpat, false, true, auth, AllowAndDeny, type, true);
+ twoTests(apat, null, true, true, auth, AllowAndDeny, type, true);
+ twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(null, dpat, false, true, auth, AllowAndDeny, type, true);
twoTests(null, dpat, false, true, auth, NoAllowNoDeny, type, true);
- twoTests(null, dpat, true, true, auth, AllowAndDeny, type, true);
- twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
+ twoTests(null, dpat, true, true, auth, AllowAndDeny, type, true);
+ twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
twoTests(apat, dpat, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyAllow, type, true);
- twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, true);
- twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyAllow, type, true);
- twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, true);
+ twoTests(apat, dpat, false, true, auth, OnlyAllow, type, true);
+ twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, true);
+ twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyAllow, type, true);
+ twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, true);
// Test "addConnectorPort" and with port matching only in deny
apat = allow_pat + PORT_NO_MATCH_PATTERN;
dpat = deny_pat + PORT_MATCH_PATTERN;
- twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
- twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, false, true, auth, AllowAndDeny, type, false);
+ twoTests(null, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, false, true, auth, AllowAndDeny, type, false);
twoTests(apat, null, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, null, true, true, auth, AllowAndDeny, type, false);
- twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(null, dpat, false, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, null, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(null, dpat, false, true, auth, AllowAndDeny, type, false);
twoTests(null, dpat, false, true, auth, NoAllowNoDeny, type, true);
- twoTests(null, dpat, true, true, auth, AllowAndDeny, type, false);
- twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
+ twoTests(null, dpat, true, true, auth, AllowAndDeny, type, false);
+ twoTests(null, dpat, true, true, auth, NoAllowNoDeny, type, true);
twoTests(apat, dpat, false, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
- twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyAllow, type, false);
- twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
- twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, false, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, false, true, auth, AllowAndDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, NoAllowNoDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyAllow, type, false);
+ twoTests(apat, dpat, true, true, auth, OnlyDeny, type, false);
+ twoTests(apat, dpat, true, true, auth, AllowAndDeny, type, false);
}
@Test
public void testRemoteAddrValveIPv4() {
- standardTests(ADDR_ALLOW_PAT, ADDR_DENY_PAT,
- ADDR_ONLY_ALLOW, ADDR_ONLY_DENY,
- ADDR_ALLOW_AND_DENY, ADDR_NO_ALLOW_NO_DENY,
- false, "Addr");
- standardTests(ADDR_ALLOW_PAT, ADDR_DENY_PAT,
- ADDR_ONLY_ALLOW, ADDR_ONLY_DENY,
- ADDR_ALLOW_AND_DENY, ADDR_NO_ALLOW_NO_DENY,
- true, "Addr");
+ standardTests(ADDR_ALLOW_PAT, ADDR_DENY_PAT, ADDR_ONLY_ALLOW, ADDR_ONLY_DENY, ADDR_ALLOW_AND_DENY,
+ ADDR_NO_ALLOW_NO_DENY, false, "Addr");
+ standardTests(ADDR_ALLOW_PAT, ADDR_DENY_PAT, ADDR_ONLY_ALLOW, ADDR_ONLY_DENY, ADDR_ALLOW_AND_DENY,
+ ADDR_NO_ALLOW_NO_DENY, true, "Addr");
}
@Test
public void testRemoteHostValve() {
- standardTests(HOST_ALLOW_PAT, HOST_DENY_PAT,
- HOST_ONLY_ALLOW, HOST_ONLY_DENY,
- HOST_ALLOW_AND_DENY, HOST_NO_ALLOW_NO_DENY,
- false, "Host");
- standardTests(HOST_ALLOW_PAT, HOST_DENY_PAT,
- HOST_ONLY_ALLOW, HOST_ONLY_DENY,
- HOST_ALLOW_AND_DENY, HOST_NO_ALLOW_NO_DENY,
- true, "Host");
+ standardTests(HOST_ALLOW_PAT, HOST_DENY_PAT, HOST_ONLY_ALLOW, HOST_ONLY_DENY, HOST_ALLOW_AND_DENY,
+ HOST_NO_ALLOW_NO_DENY, false, "Host");
+ standardTests(HOST_ALLOW_PAT, HOST_DENY_PAT, HOST_ONLY_ALLOW, HOST_ONLY_DENY, HOST_ALLOW_AND_DENY,
+ HOST_NO_ALLOW_NO_DENY, true, "Host");
}
@Test
public void testRemoteCIDRValve() {
- standardTests(CIDR_ALLOW_PROP, CIDR_DENY_PROP,
- CIDR_ONLY_ALLOW, CIDR_ONLY_DENY,
- CIDR_ALLOW_AND_DENY, CIDR_NO_ALLOW_NO_DENY,
- false, "CIDR");
- standardTests(CIDR_ALLOW_PROP, CIDR_DENY_PROP,
- CIDR_ONLY_ALLOW, CIDR_ONLY_DENY,
- CIDR_ALLOW_AND_DENY, CIDR_NO_ALLOW_NO_DENY,
- true, "CIDR");
+ standardTests(CIDR_ALLOW_PROP, CIDR_DENY_PROP, CIDR_ONLY_ALLOW, CIDR_ONLY_DENY, CIDR_ALLOW_AND_DENY,
+ CIDR_NO_ALLOW_NO_DENY, false, "CIDR");
+ standardTests(CIDR_ALLOW_PROP, CIDR_DENY_PROP, CIDR_ONLY_ALLOW, CIDR_ONLY_DENY, CIDR_ALLOW_AND_DENY,
+ CIDR_NO_ALLOW_NO_DENY, true, "CIDR");
}
@Test
public void testRemoteCIDR6Valve() {
- standardTests(CIDR6_ALLOW_PROP, CIDR6_DENY_PROP,
- CIDR6_ONLY_ALLOW, CIDR6_ONLY_DENY,
- CIDR6_ALLOW_AND_DENY, CIDR6_NO_ALLOW_NO_DENY,
- false, "CIDR");
- standardTests(CIDR6_ALLOW_PROP, CIDR6_DENY_PROP,
- CIDR6_ONLY_ALLOW, CIDR6_ONLY_DENY,
- CIDR6_ALLOW_AND_DENY, CIDR6_NO_ALLOW_NO_DENY,
- true, "CIDR");
+ standardTests(CIDR6_ALLOW_PROP, CIDR6_DENY_PROP, CIDR6_ONLY_ALLOW, CIDR6_ONLY_DENY, CIDR6_ALLOW_AND_DENY,
+ CIDR6_NO_ALLOW_NO_DENY, false, "CIDR");
+ standardTests(CIDR6_ALLOW_PROP, CIDR6_DENY_PROP, CIDR6_ONLY_ALLOW, CIDR6_ONLY_DENY, CIDR6_ALLOW_AND_DENY,
+ CIDR6_NO_ALLOW_NO_DENY, true, "CIDR");
}
}
diff --git a/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java b/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java
index cc59ad7d27..ae54e19421 100644
--- a/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java
+++ b/test/org/apache/catalina/valves/TestStuckThreadDetectionValve.java
@@ -44,16 +44,14 @@ public class TestStuckThreadDetectionValve extends TomcatBaseTest {
super.setUp();
tomcat = getTomcatInstance();
File docBase = new File(System.getProperty("java.io.tmpdir"));
- context = (StandardContext) tomcat.addContext("",
- docBase.getAbsolutePath());
+ context = (StandardContext) tomcat.addContext("", docBase.getAbsolutePath());
}
@Test
public void testDetection() throws Exception {
// second, we test the actual effect of the flag on the startup
StickingServlet stickingServlet = new StickingServlet(8000L);
- Wrapper servlet = Tomcat.addServlet(context, "myservlet",
- stickingServlet);
+ Wrapper servlet = Tomcat.addServlet(context, "myservlet", stickingServlet);
servlet.addMapping("/myservlet");
StuckThreadDetectionValve valve = new StuckThreadDetectionValve();
@@ -69,8 +67,7 @@ public class TestStuckThreadDetectionValve extends TomcatBaseTest {
@Override
public void run() {
try {
- getUrl("http://localhost:" + getPort() + "/myservlet",
- result, null);
+ getUrl("http://localhost:" + getPort() + "/myservlet", result, null);
} catch (IOException e) {
e.printStackTrace();
}
@@ -96,10 +93,8 @@ public class TestStuckThreadDetectionValve extends TomcatBaseTest {
@Test
public void testInterruption() throws Exception {
// second, we test the actual effect of the flag on the startup
- StickingServlet stickingServlet = new StickingServlet(
- TimeUnit.SECONDS.toMillis(20L));
- Wrapper servlet = Tomcat.addServlet(context, "myservlet",
- stickingServlet);
+ StickingServlet stickingServlet = new StickingServlet(TimeUnit.SECONDS.toMillis(20L));
+ Wrapper servlet = Tomcat.addServlet(context, "myservlet", stickingServlet);
servlet.addMapping("/myservlet");
StuckThreadDetectionValve valve = new StuckThreadDetectionValve();
@@ -116,8 +111,7 @@ public class TestStuckThreadDetectionValve extends TomcatBaseTest {
@Override
public void run() {
try {
- getUrl("http://localhost:" + getPort() + "/myservlet",
- result, null);
+ getUrl("http://localhost:" + getPort() + "/myservlet", result, null);
} catch (IOException e) {
e.printStackTrace();
}
@@ -150,8 +144,7 @@ public class TestStuckThreadDetectionValve extends TomcatBaseTest {
}
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws IOException {
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
diff --git a/test/org/apache/catalina/valves/TesterAccessLogValve.java b/test/org/apache/catalina/valves/TesterAccessLogValve.java
index b09a99e358..4ef6710459 100644
--- a/test/org/apache/catalina/valves/TesterAccessLogValve.java
+++ b/test/org/apache/catalina/valves/TesterAccessLogValve.java
@@ -45,8 +45,7 @@ public class TesterAccessLogValve extends ValveBase implements AccessLog {
@Override
public void log(Request request, Response response, long time) {
- entries.add(new Entry(request.getRequestURI(), response.getStatus(),
- TimeUnit.NANOSECONDS.toMillis(time)));
+ entries.add(new Entry(request.getRequestURI(), response.getStatus(), TimeUnit.NANOSECONDS.toMillis(time)));
}
@Override
@@ -61,8 +60,7 @@ public class TesterAccessLogValve extends ValveBase implements AccessLog {
}
@Override
- public void invoke(Request request, Response response) throws IOException,
- ServletException {
+ public void invoke(Request request, Response response) throws IOException, ServletException {
// Just invoke next - access logging happens via log() method
getNext().invoke(request, response);
}
@@ -71,8 +69,7 @@ public class TesterAccessLogValve extends ValveBase implements AccessLog {
return entries.size();
}
- public void validateAccessLog(int count, int status, long minTime,
- long maxTime) throws Exception {
+ public void validateAccessLog(int count, int status, long minTime, long maxTime) throws Exception {
// Wait (but not too long) until all expected entries appear (access log
// entry will be made after response has been returned to user)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org