Skip to content

Commit

Permalink
Issue #10388 - add DistributionTest for InetAccessHandler
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Aug 25, 2023
1 parent 764c817 commit b89398d
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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());
}
}
}
}

0 comments on commit b89398d

Please sign in to comment.