Skip to content

Commit

Permalink
#9910 - add more combinations
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Jul 7, 2023
1 parent be8d4c6 commit d7171ee
Showing 1 changed file with 89 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,44 @@ public void init() throws Exception
{
docRoot = workDir.getEmptyPathDir().resolve("docroot");
FS.ensureDirExists(docRoot);
Path subdirPath = docRoot.resolve("subdir");
FS.ensureDirExists(subdirPath);
Files.writeString(docRoot.resolve("index.html"), "Static index.html at root", UTF_8);
Files.writeString(docRoot.resolve("foo.welcome"), "Static foo.welcome at root", UTF_8);
Files.writeString(subdirPath.resolve("index.html"), "Static index.html at subdir", UTF_8);
Files.writeString(subdirPath.resolve("foo.welcome"), "Static foo.welcome at subdir", UTF_8);

Path subdirPath = docRoot.resolve("subdir");
FS.ensureDirExists(subdirPath);
Files.writeString(subdirPath.resolve("index.html"), "Static index.html at root subdir", UTF_8);
Files.writeString(subdirPath.resolve("foo.welcome"), "Static foo.welcome at root subdir", UTF_8);

Path emptyPath = docRoot.resolve("empty");
FS.ensureDirExists(emptyPath);

Path staticPath = docRoot.resolve("static");
FS.ensureDirExists(staticPath);
Files.writeString(staticPath.resolve("index.html"), "Static index.html at static", UTF_8);
Files.writeString(staticPath.resolve("foo.welcome"), "Static foo.welcome at static", UTF_8);

Path staticsubdirPath = staticPath.resolve("subdir");
FS.ensureDirExists(staticsubdirPath);
Files.writeString(staticsubdirPath.resolve("index.html"), "Static index.html at static subdir", UTF_8);
Files.writeString(staticsubdirPath.resolve("foo.welcome"), "Static foo.welcome at static subdir", UTF_8);

Path subdirHtmlPath = docRoot.resolve("subdirHtml");
FS.ensureDirExists(subdirHtmlPath);
Files.writeString(subdirHtmlPath.resolve("index.html"), "Static index.html at root subdirHtml", UTF_8);
Path staticSubdirHtmlPath = staticPath.resolve("subdirHtml");
FS.ensureDirExists(staticSubdirHtmlPath);
Files.writeString(staticSubdirHtmlPath.resolve("index.html"), "Static index.html at static subdirHtml", UTF_8);

Path subdirWelcomePath = docRoot.resolve("subdirWelcome");
FS.ensureDirExists(subdirWelcomePath);
Files.writeString(subdirWelcomePath.resolve("foo.welcome"), "Static foo.welcome at root subdirWelcome", UTF_8);

Path staticSubdirWelcomePath = staticPath.resolve("subdirWelcome");
FS.ensureDirExists(staticSubdirWelcomePath);
Files.writeString(staticSubdirWelcomePath.resolve("foo.welcome"), "Static foo.welcome at static subdirWelcome", UTF_8);

Path subdirEmptyPath = staticPath.resolve("subdirEmpty");
FS.ensureDirExists(subdirEmptyPath);

server = new Server();

Expand All @@ -83,8 +115,9 @@ public void init() throws Exception

private void startServer(boolean pathInfoOnly, ResourceService.WelcomeMode welcomeMode) throws Exception
{
ServletHolder defaultHolder = context.addServlet(DefaultServlet.class, "/");
ServletHolder defaultHolder = context.addServlet(DefaultServlet.class, "/static/*");
defaultHolder.setInitParameter("pathInfoOnly", String.valueOf(pathInfoOnly));
defaultHolder.setInitParameter("dirAllowed", "false");

server.setHandler(context);
server.addConnector(connector);
Expand Down Expand Up @@ -118,40 +151,61 @@ record Data(boolean pathInfoOnly, ResourceService.WelcomeMode welcomeMode, Strin
public static Stream<Data> data()
{
return Stream.of(
new Data(false, SERVE, "/", HttpStatus.OK_200, "Static index.html at root"),
new Data(false, REDIRECT, "/", HttpStatus.FOUND_302, "http://local/index.html"),
new Data(false, REHANDLE, "/", HttpStatus.OK_200, "Static index.html at root"),
new Data(true, SERVE, "/", HttpStatus.FOUND_302, "http://local/index.html/"),
new Data(true, REDIRECT, "/", HttpStatus.FOUND_302, "http://local/index.html"),
new Data(true, REHANDLE, "/", HttpStatus.FOUND_302, "http://local/index.html/"),

new Data(false, SERVE, "/index.html", HttpStatus.OK_200, "Static index.html at root"),
new Data(false, REDIRECT, "/index.html", HttpStatus.OK_200, "Static index.html at root"),
new Data(false, REHANDLE, "/index.html", HttpStatus.OK_200, "Static index.html at root"),
new Data(true, SERVE, "/index.html", HttpStatus.FOUND_302, "http://local/index.html/"),
new Data(true, REDIRECT, "/index.html", HttpStatus.FOUND_302, "http://local/index.html/"),
new Data(true, REHANDLE, "/index.html", HttpStatus.FOUND_302, "http://local/index.html/"),

new Data(false, SERVE, "/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(false, REDIRECT, "/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(false, REHANDLE, "/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(true, SERVE, "/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(true, REDIRECT, "/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(true, REHANDLE, "/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),

new Data(false, SERVE, "/subdir/", HttpStatus.OK_200, "Static index.html at subdir"),
new Data(false, REDIRECT, "/subdir/", HttpStatus.FOUND_302, "http://local/subdir/index.html"),
new Data(false, REHANDLE, "/subdir/", HttpStatus.OK_200, "Static index.html at subdir"),
new Data(true, SERVE, "/subdir/", HttpStatus.FOUND_302, "http://local/subdir/index.html/"),
new Data(true, REDIRECT, "/subdir/", HttpStatus.FOUND_302, "http://local/subdir/subdir/index.html"),
new Data(true, REHANDLE, "/subdir/", HttpStatus.FOUND_302, "http://local/subdir/index.html/"),

new Data(false, SERVE, "/subdir/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(false, REDIRECT, "/subdir/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(false, REHANDLE, "/subdir/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(true, SERVE, "/subdir/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(true, REDIRECT, "/subdir/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(true, REHANDLE, "/subdir/foo.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(false, SERVE, "/static/foo.welcome", HttpStatus.OK_200, "Static foo.welcome at static"),
new Data(false, REDIRECT, "/static/foo.welcome", HttpStatus.OK_200, "Static foo.welcome at static"),
new Data(false, REHANDLE, "/static/foo.welcome", HttpStatus.OK_200, "Static foo.welcome at static"),
new Data(true, SERVE, "/static/foo.welcome", HttpStatus.OK_200, "Static foo.welcome at root"),
new Data(true, REDIRECT, "/static/foo.welcome", HttpStatus.OK_200, "Static foo.welcome at root"),
new Data(true, REHANDLE, "/static/foo.welcome", HttpStatus.OK_200, "Static foo.welcome at root"),

new Data(false, SERVE, "/static/", HttpStatus.OK_200, "Static index.html at static"),
new Data(false, REDIRECT, "/static/", HttpStatus.FOUND_302, "http://local/static/index.html"),
new Data(false, REHANDLE, "/static/", HttpStatus.OK_200, "Static index.html at static"),
new Data(true, SERVE, "/static/", HttpStatus.OK_200, "Static index.html at root"),
new Data(true, REDIRECT, "/static/", HttpStatus.FOUND_302, "http://local/static/static/index.html"),
new Data(true, REHANDLE, "/static/", HttpStatus.OK_200, "Static index.html at root"),

new Data(false, SERVE, "/static/subdir/", HttpStatus.OK_200, "Static index.html at static subdir"),
new Data(false, REDIRECT, "/static/subdir/", HttpStatus.FOUND_302, "http://local/static/subdir/index.html"),
new Data(false, REHANDLE, "/static/subdir/", HttpStatus.OK_200, "Static index.html at static subdir"),
new Data(true, SERVE, "/static/subdir/", HttpStatus.OK_200, "Static index.html at root subdir"),
new Data(true, REDIRECT, "/static/subdir/", HttpStatus.FOUND_302, "http://local/static/static/subdir/index.html"),
new Data(true, REHANDLE, "/static/subdir/", HttpStatus.OK_200, "Static index.html at root subdir"),

new Data(false, SERVE, "/static/subdirHtml/", HttpStatus.OK_200, "Static index.html at static subdirHtml"),
new Data(false, REDIRECT, "/static/subdirHtml/", HttpStatus.FOUND_302, "http://local/static/subdirHtml/index.html"),
new Data(false, REHANDLE, "/static/subdirHtml/", HttpStatus.OK_200, "Static index.html at static subdirHtml"),
new Data(true, SERVE, "/static/subdirHtml/", HttpStatus.OK_200, "Static index.html at root subdirHtml"),
new Data(true, REDIRECT, "/static/subdirHtml/", HttpStatus.FOUND_302, "http://local/static/static/subdirHtml/index.html"),
new Data(true, REHANDLE, "/static/subdirHtml/", HttpStatus.OK_200, "Static index.html at root subdirHtml"),

new Data(false, SERVE, "/static/subdirWelcome/", HttpStatus.FORBIDDEN_403, null),
new Data(false, REDIRECT, "/static/subdirWelcome/", HttpStatus.FORBIDDEN_403, null),
new Data(false, REHANDLE, "/static/subdirWelcome/", HttpStatus.FORBIDDEN_403, null),
new Data(true, SERVE, "/static/subdirWelcome/", HttpStatus.FORBIDDEN_403, null),
new Data(true, REDIRECT, "/static/subdirWelcome/", HttpStatus.FORBIDDEN_403, null),
new Data(true, REHANDLE, "/static/subdirWelcome/", HttpStatus.FORBIDDEN_403, null),

new Data(false, SERVE, "/static/subdirEmpty/", HttpStatus.FORBIDDEN_403, null),
new Data(false, REDIRECT, "/static/subdirEmpty/", HttpStatus.FORBIDDEN_403, null),
new Data(false, REHANDLE, "/static/subdirEmpty/", HttpStatus.FORBIDDEN_403, null),
new Data(true, SERVE, "/static/subdirEmpty/", HttpStatus.NOT_FOUND_404, null),
new Data(true, REDIRECT, "/static/subdirEmpty/", HttpStatus.NOT_FOUND_404, null),
new Data(true, REHANDLE, "/static/subdirEmpty/", HttpStatus.NOT_FOUND_404, null),

new Data(false, SERVE, "/empty/", HttpStatus.NOT_FOUND_404, null),
new Data(false, REDIRECT, "/empty/", HttpStatus.NOT_FOUND_404, null),
new Data(false, REHANDLE, "/empty/", HttpStatus.NOT_FOUND_404, null),
new Data(true, SERVE, "/empty/", HttpStatus.NOT_FOUND_404, null),
new Data(true, REDIRECT, "/empty/", HttpStatus.NOT_FOUND_404, null),
new Data(true, REHANDLE, "/empty/", HttpStatus.NOT_FOUND_404, null),

new Data(false, SERVE, "/nothing/index.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
new Data(false, REDIRECT, "/nothing/index.welcome", HttpStatus.OK_200, "Servlet at welcome extension"),
Expand All @@ -163,9 +217,9 @@ public static Stream<Data> data()
new Data(false, SERVE, "/nothing/", HttpStatus.NOT_FOUND_404, null),
new Data(false, REDIRECT, "/nothing/", HttpStatus.NOT_FOUND_404, null),
new Data(false, REHANDLE, "/nothing/", HttpStatus.NOT_FOUND_404, null),
new Data(true, SERVE, "/nothing/", HttpStatus.FOUND_302, "http://local/nothing/index.html/"),
new Data(true, REDIRECT, "/nothing/", HttpStatus.FOUND_302, "http://local/nothing/nothing/index.html"),
new Data(true, REHANDLE, "/nothing/", HttpStatus.FOUND_302, "http://local/nothing/index.html/")
new Data(true, SERVE, "/nothing/", HttpStatus.NOT_FOUND_404, null),
new Data(true, REDIRECT, "/nothing/", HttpStatus.NOT_FOUND_404, null),
new Data(true, REHANDLE, "/nothing/", HttpStatus.NOT_FOUND_404, null)
);
}

Expand Down

0 comments on commit d7171ee

Please sign in to comment.