From bf52e7a99229d12f6ea9dcbabe59902d41670e69 Mon Sep 17 00:00:00 2001 From: Nanne Baars Date: Mon, 9 Sep 2019 11:37:26 +0200 Subject: [PATCH] Fixed checking of server already running --- .../java/org/owasp/webgoat/IntegrationTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/webgoat-integration-tests/src/test/java/org/owasp/webgoat/IntegrationTest.java b/webgoat-integration-tests/src/test/java/org/owasp/webgoat/IntegrationTest.java index 6d41a6b34..9114fcad1 100644 --- a/webgoat-integration-tests/src/test/java/org/owasp/webgoat/IntegrationTest.java +++ b/webgoat-integration-tests/src/test/java/org/owasp/webgoat/IntegrationTest.java @@ -13,7 +13,7 @@ import org.owasp.webwolf.WebWolf; import org.springframework.boot.builder.SpringApplicationBuilder; import java.io.IOException; -import java.net.ServerSocket; +import java.net.Socket; import java.util.Map; import java.util.UUID; @@ -43,10 +43,12 @@ public abstract class IntegrationTest { public static void beforeAll() { if (!started) { started = true; - if (!isAlreadyRunning()) { + if (!isAlreadyRunning(WG_PORT)) { SpringApplicationBuilder wgs = new SpringApplicationBuilder(StartWebGoat.class) .properties(Map.of("spring.config.name", "application-webgoat", "WEBGOAT_PORT", WG_PORT)); wgs.run(); + } + if (!isAlreadyRunning(WW_PORT)) { SpringApplicationBuilder wws = new SpringApplicationBuilder(WebWolf.class) .properties(Map.of("spring.config.name", "application-webwolf", "WEBWOLF_PORT", WW_PORT)); wws.run(); @@ -54,11 +56,11 @@ public abstract class IntegrationTest { } } - private static boolean isAlreadyRunning() { - try (var ignored = new ServerSocket(WG_PORT)) { - return false; - } catch (IOException e) { + private static boolean isAlreadyRunning(int port) { + try (var ignored = new Socket("127.0.0.1", port)) { return true; + } catch (IOException e) { + return false; } }