From b89398d91c8cfdebf4f75d05f157d0f42a6a97a6 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 25 Aug 2023 14:19:38 +1000 Subject: [PATCH] Issue #10388 - add DistributionTest for InetAccessHandler Signed-off-by: Lachlan Roberts --- .../tests/distribution/DistributionTests.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java index e1f6feddea00..1424d5a044d8 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java @@ -1376,4 +1376,42 @@ public void testVirtualThreadPool() throws Exception } } } + + @Test + public void testInetAccessHandler() throws Exception + { + String jettyVersion = System.getProperty("jettyVersion"); + JettyHomeTester distribution = JettyHomeTester.Builder.newInstance() + .jettyVersion(jettyVersion) + .mavenLocalRepository(System.getProperty("mavenRepoPath")) + .build(); + + try (JettyHomeTester.Run run1 = distribution.start("--add-modules=inetaccess,http")) + { + assertTrue(run1.awaitFor(10, TimeUnit.SECONDS)); + assertEquals(0, run1.getExitValue()); + + int httpPort = distribution.freePort(); + List args = List.of( + "jetty.inetaccess.exclude=|/excludedPath/*", + "jetty.http.port=" + httpPort); + try (JettyHomeTester.Run run2 = distribution.start(args)) + { + assertTrue(run2.awaitConsoleLogsFor("Started Server@", 10, TimeUnit.SECONDS)); + startHttpClient(); + + // Excluded path returns 403 response. + ContentResponse response = client.newRequest("http://localhost:" + httpPort +"/excludedPath") + .timeout(15, TimeUnit.SECONDS) + .send(); + assertEquals(HttpStatus.FORBIDDEN_403, response.getStatus()); + + // Other paths return 404 response. + response = client.newRequest("http://localhost:" + httpPort +"/path") + .timeout(15, TimeUnit.SECONDS) + .send(); + assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus()); + } + } + } }