Skip to content

Commit

Permalink
#534 protect /shutdown
Browse files Browse the repository at this point in the history
yegor256 committed Aug 31, 2023
1 parent 513ea76 commit f48be47
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main/java/org/jpeek/web/TkApp.java
Original file line number Diff line number Diff line change
@@ -112,7 +112,13 @@ private static Take make(final Path home) {
new FkRegex("/", new TkIndex()),
new FkRegex(
"/shutdown",
(Take) req -> new RsText(Boolean.toString(futures.shutdown()))
(Take) req -> {
String html = "Can't do this, sorry :)";
if (TkApp.isRunningTest()) {
html = Boolean.toString(futures.shutdown());
}
return new RsText(html);
}
),
new FkRegex("/robots.txt", new TkText("")),
new FkRegex("/mistakes", new TkMistakes()),
@@ -181,4 +187,18 @@ private static Take make(final Path home) {
);
}

/**
* Is it JUnit testing?
* @return TRUE if we are testing
*/
private static boolean isRunningTest() {
boolean testing = true;
try {
Class.forName("org.junit.jupiter.api.Test");
} catch (final ClassNotFoundException ex) {
testing = false;
}
return testing;
}

}

0 comments on commit f48be47

Please sign in to comment.