From f48be470f8d42a162efeae917de8c3abd1bb35ae Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Thu, 31 Aug 2023 12:53:00 +0300 Subject: [PATCH] #534 protect /shutdown --- src/main/java/org/jpeek/web/TkApp.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jpeek/web/TkApp.java b/src/main/java/org/jpeek/web/TkApp.java index 48469e9d..bbd1a66b 100644 --- a/src/main/java/org/jpeek/web/TkApp.java +++ b/src/main/java/org/jpeek/web/TkApp.java @@ -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; + } + }