diff --git a/build.gradle b/build.gradle index c565f1bdc..7ede11ac5 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" } // } //} -version = "9.2.2" +version = "9.2.3" repositories { diff --git a/src/main/java/io/supertokens/webserver/Webserver.java b/src/main/java/io/supertokens/webserver/Webserver.java index e22e9b754..4a59dffff 100644 --- a/src/main/java/io/supertokens/webserver/Webserver.java +++ b/src/main/java/io/supertokens/webserver/Webserver.java @@ -56,6 +56,7 @@ import org.apache.catalina.core.StandardContext; import org.apache.catalina.startup.Tomcat; import org.apache.tomcat.util.http.fileupload.FileUtils; +import org.jetbrains.annotations.TestOnly; import java.io.File; import java.util.UUID; @@ -364,6 +365,11 @@ public void closeLogger() { } } + @TestOnly + public TomcatReference getTomcatReference(){ + return tomcatReference; + } + public static class TomcatReference { private Tomcat tomcat; private StandardContext context; @@ -377,6 +383,11 @@ Tomcat getTomcat() { return tomcat; } + @TestOnly + public Tomcat getTomcatForTest(){ + return tomcat; + } + StandardContext getContext() { return context; } diff --git a/src/test/java/io/supertokens/test/CLIOptionsTest.java b/src/test/java/io/supertokens/test/CLIOptionsTest.java index d783c63be..94e489ed5 100644 --- a/src/test/java/io/supertokens/test/CLIOptionsTest.java +++ b/src/test/java/io/supertokens/test/CLIOptionsTest.java @@ -287,4 +287,32 @@ public void testMultipleInstancesAtTheSameTime() throws Exception { } + @Test + public void cli2TempLocationTest() throws Exception { + + String[] args = {"../"}; + + TestingProcess process = TestingProcessManager.start(args); + assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STARTED)); + + assertEquals(Config.getConfig(process.getProcess()).getHost(process.getProcess()), "localhost"); + assertEquals(Config.getConfig(process.getProcess()).getPort(process.getProcess()), 3567); + + process.kill(); + assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED)); + + //process starts with tempDirLocation param too. + args = new String[]{"../", "tempDirLocation=" + new File("../temp/").getAbsolutePath()}; + + process = TestingProcessManager.start(args); + assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STARTED)); + + assertEquals(Config.getConfig(process.getProcess()).getHost(process.getProcess()), "localhost"); + assertEquals(Config.getConfig(process.getProcess()).getPort(process.getProcess()), 3567); + + process.kill(); + assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED)); + + } + } diff --git a/src/test/java/io/supertokens/test/DotStartedFileTest.java b/src/test/java/io/supertokens/test/DotStartedFileTest.java index b812863b1..5463ba1fd 100644 --- a/src/test/java/io/supertokens/test/DotStartedFileTest.java +++ b/src/test/java/io/supertokens/test/DotStartedFileTest.java @@ -185,4 +185,36 @@ public void processFailToStartDotStartedFileTest() throws Exception { process.kill(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); } + + @Test + public void dotStartedFileAtTempDirLocation() throws Exception { + String tempDirLocation = new File("../temp/").getAbsolutePath(); + String[] args = {"../", "tempDirLocation=" + tempDirLocation}; + + String host = "localhost"; + String port = "8081"; + String hostPortNameCheck = host + "-" + port; + + Utils.setValueInConfig("port", port); + + TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); + + File loc = new File(tempDirLocation + "/.started"); + + File[] dotStartedNameAndContent = loc.listFiles(); + assert dotStartedNameAndContent != null; + assertEquals(1, dotStartedNameAndContent.length); + assertEquals(dotStartedNameAndContent[0].getName(), hostPortNameCheck); + + String[] dotStartedContent = Files.readString(Paths.get(dotStartedNameAndContent[0].getPath())).split("\n"); + String line = dotStartedContent[0]; + assertEquals(line, Long.toString(ProcessHandle.current().pid())); + line = dotStartedContent.length > 1 ? dotStartedContent[1] : ""; + assertEquals(line, Config.getConfig(process.main).getBasePath()); + assertEquals(line, ""); + + process.kill(); + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); + } } diff --git a/src/test/java/io/supertokens/test/WebserverTest.java b/src/test/java/io/supertokens/test/WebserverTest.java index 66592385b..cbb4ea963 100644 --- a/src/test/java/io/supertokens/test/WebserverTest.java +++ b/src/test/java/io/supertokens/test/WebserverTest.java @@ -35,6 +35,7 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.apache.catalina.startup.Tomcat; import org.junit.AfterClass; import org.junit.Before; import org.junit.Rule; @@ -42,6 +43,7 @@ import org.junit.rules.TestRule; import org.mockito.Mockito; +import java.io.File; import java.io.IOException; import java.net.ConnectException; import java.net.InetAddress; @@ -963,6 +965,25 @@ public void validBasePath() throws InterruptedException, IOException, HttpRespon } + @Test + public void tempDirLocationWebserverStarts() throws InterruptedException, HttpResponseException, IOException { + String tempDirLocation = new File("../temp/").getCanonicalPath(); + String[] args = {"../", "tempDirLocation=" + tempDirLocation}; + TestingProcess process = TestingProcessManager.start(args); + assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STARTED)); + + Webserver.TomcatReference reference = Webserver.getInstance(process.getProcess()).getTomcatReference(); + File catalinaBase = reference.getTomcatForTest().getServer().getCatalinaBase(); + assertEquals(tempDirLocation, catalinaBase.getAbsolutePath()); + + String response = HttpRequest.sendGETRequest(process.getProcess(), "", "http://localhost:3567/", null, + 1000, 1000, null); + assertEquals("Hello", response); + + process.kill(); + assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED)); + } + @Test public void validBasePathWithEmptyHelloPath() throws InterruptedException, IOException, HttpResponseException { {