-
Notifications
You must be signed in to change notification settings - Fork 577
feat: Windows Support #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.12
Are you sure you want to change the base?
Changes from 8 commits
907d2ce
78bc0e9
f6d1c09
40165cf
07bb149
2ee4d6f
d99e0f4
3e295ef
63bc059
5f653d2
ed1fc78
e597766
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,8 +205,11 @@ public void paginationTest() throws Exception { | |
} | ||
|
||
UserInfo user1 = EmailPassword.signUp(process.getProcess(), "[email protected]", "password0"); | ||
Thread.sleep(1); // Sleep to remove race condition | ||
UserInfo user2 = EmailPassword.signUp(process.getProcess(), "[email protected]", "password1"); | ||
Thread.sleep(1); | ||
UserInfo user3 = EmailPassword.signUp(process.getProcess(), "[email protected]", "password2"); | ||
Thread.sleep(1); | ||
UserInfo user4 = EmailPassword.signUp(process.getProcess(), "[email protected]", "password3"); | ||
|
||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import com.google.gson.JsonObject; | ||
import io.supertokens.Main; | ||
import io.supertokens.exceptions.QuitProgramException; | ||
import io.supertokens.pluginInterface.PluginInterfaceTesting; | ||
import io.supertokens.storageLayer.StorageLayer; | ||
import io.supertokens.test.httpRequest.HttpRequestForTesting; | ||
|
@@ -31,22 +32,21 @@ | |
|
||
import java.io.*; | ||
import java.nio.charset.StandardCharsets; | ||
rishabhpoddar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import java.nio.file.Files; | ||
import java.nio.file.*; | ||
import java.util.Arrays; | ||
import java.util.regex.Pattern; | ||
|
||
public abstract class Utils extends Mockito { | ||
|
||
private static ByteArrayOutputStream byteArrayOutputStream; | ||
private static final String newLine = System.lineSeparator(); | ||
|
||
public static void afterTesting() { | ||
String installDir = "../"; | ||
try { | ||
|
||
// remove config.yaml file | ||
ProcessBuilder pb = new ProcessBuilder("rm", "config.yaml"); | ||
pb.directory(new File(installDir)); | ||
Process process = pb.start(); | ||
process.waitFor(); | ||
Files.delete(new File(installDir + "config.yaml").toPath()); // Use behavior of rm command | ||
|
||
// remove webserver-temp folders created by tomcat | ||
final File webserverTemp = new File(installDir + "webserver-temp"); | ||
|
@@ -104,23 +104,22 @@ public static void reset() { | |
PluginInterfaceTesting.isTesting = true; | ||
Main.makeConsolePrintSilent = true; | ||
String installDir = "../"; | ||
if (!new File(installDir + ".testEnvRunning").exists()) | ||
throw new QuitProgramException( | ||
"Testing environment is not running! Run the startTestingEnv script to start it."); | ||
try { | ||
|
||
// if the default config is not the same as the current config, we must reset the storage layer | ||
File ogConfig = new File("../temp/config.yaml"); | ||
File currentConfig = new File("../config.yaml"); | ||
if (currentConfig.isFile()) { | ||
byte[] ogConfigContent = Files.readAllBytes(ogConfig.toPath()); | ||
byte[] currentConfigContent = Files.readAllBytes(currentConfig.toPath()); | ||
Path ogConfig = new File(installDir + "temp/config.yaml").toPath(); | ||
Path currentConfig = new File(installDir + "config.yaml").toPath(); | ||
if (currentConfig.toFile().isFile()) { | ||
byte[] ogConfigContent = Files.readAllBytes(ogConfig); | ||
byte[] currentConfigContent = Files.readAllBytes(currentConfig); | ||
if (!Arrays.equals(ogConfigContent, currentConfigContent)) { | ||
StorageLayer.close(); | ||
} | ||
} | ||
|
||
ProcessBuilder pb = new ProcessBuilder("cp", "temp/config.yaml", "./config.yaml"); | ||
pb.directory(new File(installDir)); | ||
Process process = pb.start(); | ||
process.waitFor(); | ||
Files.copy(ogConfig, currentConfig, StandardCopyOption.REPLACE_EXISTING); // Use behavior of cp command | ||
|
||
// in devConfig, it's set to false. However, in config, it's commented. So we comment it out so that it | ||
// mimics production. Refer to https://github.com/supertokens/supertokens-core/issues/118 | ||
|
@@ -138,46 +137,26 @@ public static void reset() { | |
System.gc(); | ||
} | ||
|
||
static void commentConfigValue(String key) throws IOException { | ||
private static void replaceConfigValue(String regex, String newStr) throws IOException { | ||
// we close the storage layer since there might be a change in the db related config. | ||
StorageLayer.close(); | ||
Path configPath = new File("../config.yaml").toPath(); | ||
String originalFileContent = Files.readString(configPath); | ||
String modifiedFileContent = originalFileContent.replaceAll(regex, newStr); | ||
String normalizedFileContent = modifiedFileContent.replaceAll("\r?\n", newLine); // Normalize line endings | ||
Files.writeString(configPath, normalizedFileContent); | ||
} | ||
|
||
String oldStr = "\n((#\\s)?)" + key + "(:|((:\\s).+))\n"; | ||
String newStr = "\n# " + key + ":"; | ||
|
||
StringBuilder originalFileContent = new StringBuilder(); | ||
try (BufferedReader reader = new BufferedReader(new FileReader("../config.yaml"))) { | ||
String currentReadingLine = reader.readLine(); | ||
while (currentReadingLine != null) { | ||
originalFileContent.append(currentReadingLine).append(System.lineSeparator()); | ||
currentReadingLine = reader.readLine(); | ||
} | ||
String modifiedFileContent = originalFileContent.toString().replaceAll(oldStr, newStr); | ||
try (BufferedWriter writer = new BufferedWriter(new FileWriter("../config.yaml"))) { | ||
writer.write(modifiedFileContent); | ||
} | ||
} | ||
|
||
public static void commentConfigValue(String key) throws IOException { | ||
String find = "\r?\n#?\\s*" + Pattern.quote(key) + ":.*\r?\n"; | ||
String replace = newLine + "# " + key + ":" + newLine; | ||
replaceConfigValue(find, replace); | ||
} | ||
|
||
public static void setValueInConfig(String key, String value) throws IOException { | ||
// we close the storage layer since there might be a change in the db related config. | ||
StorageLayer.close(); | ||
|
||
String oldStr = "\n((#\\s)?)" + key + "(:|((:\\s).+))\n"; | ||
String newStr = "\n" + key + ": " + value + "\n"; | ||
StringBuilder originalFileContent = new StringBuilder(); | ||
try (BufferedReader reader = new BufferedReader(new FileReader("../config.yaml"))) { | ||
String currentReadingLine = reader.readLine(); | ||
while (currentReadingLine != null) { | ||
originalFileContent.append(currentReadingLine).append(System.lineSeparator()); | ||
currentReadingLine = reader.readLine(); | ||
} | ||
String modifiedFileContent = originalFileContent.toString().replaceAll(oldStr, newStr); | ||
try (BufferedWriter writer = new BufferedWriter(new FileWriter("../config.yaml"))) { | ||
writer.write(modifiedFileContent); | ||
} | ||
} | ||
String find = "\r?\n#?\\s*" + Pattern.quote(key) + ":.*\r?\n"; | ||
String replace = newLine + key + ": " + value + newLine; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to change the regex expression? The older one worked just fine. Did the older one cause issues in windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this change is necessary.
Issues with the Old Regex:
When reviewing this, I actually noticed one issue with the New Regex. It did not match commented lines with leading whitespace. I have committed this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. So this change would be required in the plugins repos as well. Since they too have a similar function in there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I see. I was thinking that the plugin repos called I was also thinking about renaming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should change them in the plugin repos too, just to be consistent. |
||
replaceConfigValue(find, replace); | ||
} | ||
|
||
public static TestRule getOnFailure() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,7 @@ | |
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.net.ConnectException; | ||
import java.net.InetAddress; | ||
import java.net.SocketTimeoutException; | ||
import java.net.*; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.Assert.*; | ||
|
@@ -597,26 +595,12 @@ public void differentHostNameTest() throws InterruptedException, IOException, Ht | |
Utils.setValueInConfig("host", "\"localhost\""); | ||
hello("localhost", "3567"); | ||
hello("127.0.0.1", "3567"); | ||
try { | ||
hello(inetAddress.getHostAddress(), "3567"); | ||
if (!inetAddress.getHostAddress().equals("127.0.0.1")) { | ||
fail(); | ||
} | ||
} catch (ConnectException ignored) { | ||
} | ||
|
||
Utils.reset(); | ||
|
||
Utils.setValueInConfig("host", "\"127.0.0.1\""); | ||
hello("localhost", "3567"); | ||
hello("127.0.0.1", "3567"); | ||
try { | ||
hello(inetAddress.getHostAddress(), "3567"); | ||
if (!inetAddress.getHostAddress().equals("127.0.0.1")) { | ||
fail(); | ||
} | ||
} catch (ConnectException ignored) { | ||
} | ||
Comment on lines
-600
to
-619
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing these tests cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was failing because the core was not visible to any of my local IP addresses when hosted on localhost due to my firewall settings. This may also be related to how Windows handles localhost addresses, but documentation is sparse on this issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I would require these tests to be there.. Maybe we can change the code here to not run if the OS is windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that, but wouldn't the situation be similar on other operating systems as well? If settings are strict (as they probably should be), access to localhost servers would not be visible to LAN addresses. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has more or less worked with all linux based systems, mac, CICD, GitHub action and everyone in our dev team.. so i don't think it's too much of a problem. I just want this to also run in CICD / GH action pipeline. It would be OK to have them skipped in local dev env. |
||
|
||
Utils.reset(); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.