Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 91 additions & 91 deletions src/main/java/io/supertokens/config/CoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,97 +393,6 @@ void normalizeAndValidate(Main main) throws InvalidConfigException {
return;
}

// Normalize
if (ip_allow_regex != null) {
ip_allow_regex = ip_allow_regex.trim();
if (ip_allow_regex.equals("")) {
ip_allow_regex = null;
}
}
if (ip_deny_regex != null) {
ip_deny_regex = ip_deny_regex.trim();
if (ip_deny_regex.equals("")) {
ip_deny_regex = null;
}
}

if (log_level != null) {
log_level = log_level.trim().toUpperCase();
}

{ // info_log_path
if (info_log_path == null || info_log_path.equalsIgnoreCase("null")) {
info_log_path = "null";
} else {
if (info_log_path.equals(logDefault)) {
// this works for windows as well
info_log_path = CLIOptions.get(main).getInstallationPath() + "logs/info.log";
}
}
}

{ // error_log_path
if (error_log_path == null || error_log_path.equalsIgnoreCase("null")) {
error_log_path = "null";
} else {
if (error_log_path.equals(logDefault)) {
// this works for windows as well
error_log_path = CLIOptions.get(main).getInstallationPath() + "logs/error.log";
}
}
}

{ // base_path
String n_base_path = this.base_path; // Don't modify the original value from the config
if (n_base_path == null || n_base_path.equals("/") || n_base_path.isEmpty()) {
base_path = "";
} else {
while (n_base_path.contains("//")) { // Catch corner case where there are multiple '/' together
n_base_path = n_base_path.replace("//", "/");
}
if (!n_base_path.startsWith("/")) { // Add leading '/'
n_base_path = "/" + n_base_path;
}
if (n_base_path.endsWith("/")) { // Remove trailing '/'
n_base_path = n_base_path.substring(0, n_base_path.length() - 1);
}
base_path = n_base_path;
}
}

// the reason we do Math.max below is that if the password hashing algo is
// bcrypt,
// then we don't check the argon2 hashing pool size config at all. In this case,
// if the user gives a <= 0 number, it crashes the core (since it creates a
// blockedqueue in PaswordHashing
// .java with length <= 0). So we do a Math.max
argon2_hashing_pool_size = Math.max(1, argon2_hashing_pool_size);

firebase_password_hashing_pool_size = Math.max(1, firebase_password_hashing_pool_size);

if (api_keys != null) {
String[] apiKeys = api_keys.trim().replaceAll("\\s", "").split(",");
Arrays.sort(apiKeys);
api_keys = String.join(",", apiKeys);
}
if (supertokens_saas_secret != null) {
supertokens_saas_secret = supertokens_saas_secret.trim();
}

Integer cliPort = CLIOptions.get(main).getPort();
if (cliPort != null) {
port = cliPort;
}

String cliHost = CLIOptions.get(main).getHost();
if (cliHost != null) {
host = cliHost;
}

access_token_validity = access_token_validity * 1000;
access_token_dynamic_signing_key_update_interval = access_token_dynamic_signing_key_update_interval * 3600 * 1000;
refresh_token_validity = refresh_token_validity * 60 * 1000;

// Validate
if (core_config_version == -1) {
throw new InvalidConfigException(
Expand Down Expand Up @@ -661,6 +570,97 @@ void normalizeAndValidate(Main main) throws InvalidConfigException {
}
}

// Normalize
if (ip_allow_regex != null) {
ip_allow_regex = ip_allow_regex.trim();
if (ip_allow_regex.equals("")) {
ip_allow_regex = null;
}
}
if (ip_deny_regex != null) {
ip_deny_regex = ip_deny_regex.trim();
if (ip_deny_regex.equals("")) {
ip_deny_regex = null;
}
}

if (log_level != null) {
log_level = log_level.trim().toUpperCase();
}

{ // info_log_path
if (info_log_path == null || info_log_path.equalsIgnoreCase("null")) {
info_log_path = "null";
} else {
if (info_log_path.equals(logDefault)) {
// this works for windows as well
info_log_path = CLIOptions.get(main).getInstallationPath() + "logs/info.log";
}
}
}

{ // error_log_path
if (error_log_path == null || error_log_path.equalsIgnoreCase("null")) {
error_log_path = "null";
} else {
if (error_log_path.equals(logDefault)) {
// this works for windows as well
error_log_path = CLIOptions.get(main).getInstallationPath() + "logs/error.log";
}
}
}

{ // base_path
String n_base_path = this.base_path; // Don't modify the original value from the config
if (n_base_path == null || n_base_path.equals("/") || n_base_path.isEmpty()) {
base_path = "";
} else {
while (n_base_path.contains("//")) { // Catch corner case where there are multiple '/' together
n_base_path = n_base_path.replace("//", "/");
}
if (!n_base_path.startsWith("/")) { // Add leading '/'
n_base_path = "/" + n_base_path;
}
if (n_base_path.endsWith("/")) { // Remove trailing '/'
n_base_path = n_base_path.substring(0, n_base_path.length() - 1);
}
base_path = n_base_path;
}
}

// the reason we do Math.max below is that if the password hashing algo is
// bcrypt,
// then we don't check the argon2 hashing pool size config at all. In this case,
// if the user gives a <= 0 number, it crashes the core (since it creates a
// blockedqueue in PaswordHashing
// .java with length <= 0). So we do a Math.max
argon2_hashing_pool_size = Math.max(1, argon2_hashing_pool_size);

firebase_password_hashing_pool_size = Math.max(1, firebase_password_hashing_pool_size);

if (api_keys != null) {
String[] apiKeys = api_keys.trim().replaceAll("\\s", "").split(",");
Arrays.sort(apiKeys);
api_keys = String.join(",", apiKeys);
}
if (supertokens_saas_secret != null) {
supertokens_saas_secret = supertokens_saas_secret.trim();
}

Integer cliPort = CLIOptions.get(main).getPort();
if (cliPort != null) {
port = cliPort;
}

String cliHost = CLIOptions.get(main).getHost();
if (cliHost != null) {
host = cliHost;
}

access_token_validity = access_token_validity * 1000;
access_token_dynamic_signing_key_update_interval = access_token_dynamic_signing_key_update_interval * 3600 * 1000;
refresh_token_validity = refresh_token_validity * 60 * 1000;

isNormalizedAndValid = true;
}

Expand Down
52 changes: 46 additions & 6 deletions src/test/java/io/supertokens/test/CLIOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,17 @@ public void testMultipleInstancesAtTheSameTime() throws Exception {
assertEquals(Config.getConfig(process1.getProcess()).getErrorLogPath(process1.getProcess()),
Config.getConfig(process2.getProcess()).getErrorLogPath(process2.getProcess()));

Logging.debug(process.getProcess(), TenantIdentifier.BASE_TENANT, "test");
Logging.debug(process1.getProcess(), TenantIdentifier.BASE_TENANT, "test1");
Logging.debug(process2.getProcess(), TenantIdentifier.BASE_TENANT, "test2");
Logging.debug(process.getProcess(), TenantIdentifier.BASE_TENANT, "debugunique1");
Logging.debug(process1.getProcess(), TenantIdentifier.BASE_TENANT, "debugunique2");
Logging.debug(process2.getProcess(), TenantIdentifier.BASE_TENANT, "debugunique3");

Logging.error(process.getProcess(), TenantIdentifier.BASE_TENANT, "test", false);
Logging.error(process1.getProcess(), TenantIdentifier.BASE_TENANT, "test1", false);
Logging.error(process2.getProcess(), TenantIdentifier.BASE_TENANT, "test2", false);
Logging.info(process.getProcess(), TenantIdentifier.BASE_TENANT, "infounique1", false);
Logging.info(process1.getProcess(), TenantIdentifier.BASE_TENANT, "infounique2", false);
Logging.info(process2.getProcess(), TenantIdentifier.BASE_TENANT, "infounique3", false);

Logging.error(process.getProcess(), TenantIdentifier.BASE_TENANT, "errorunique1", false);
Logging.error(process1.getProcess(), TenantIdentifier.BASE_TENANT, "errorunique2", false);
Logging.error(process2.getProcess(), TenantIdentifier.BASE_TENANT, "errorunique3", false);

boolean processInfoLog = false;
boolean process1InfoLog = false;
Expand All @@ -167,6 +171,14 @@ public void testMultipleInstancesAtTheSameTime() throws Exception {
boolean process1ErrorLog = false;
boolean process2ErrorLog = false;

int infoTest1Count = 0;
int infoTest2Count = 0;
int infoTest3Count = 0;

int errrorTest1Count = 0;
int errrorTest2Count = 0;
int errrorTest3Count = 0;

try (BufferedReader reader = new BufferedReader(
new FileReader(Config.getConfig(process.getProcess()).getInfoLogPath(process.getProcess())))) {
String currentReadingLine = reader.readLine();
Expand All @@ -182,6 +194,16 @@ public void testMultipleInstancesAtTheSameTime() throws Exception {
processInfoLog = true;
}

if (currentReadingLine.contains("infounique1")) {
infoTest1Count++;
}
if (currentReadingLine.contains("infounique2")) {
infoTest2Count++;
}
if (currentReadingLine.contains("infounique3")) {
infoTest3Count++;
}

currentReadingLine = reader.readLine();
}
}
Expand All @@ -199,6 +221,17 @@ public void testMultipleInstancesAtTheSameTime() throws Exception {
if (currentReadingLine.contains(process.getProcess().getProcessId())) {
processErrorLog = true;
}

if (currentReadingLine.contains("errorunique1")) {
errrorTest1Count++;
}
if (currentReadingLine.contains("errorunique2")) {
errrorTest2Count++;
}
if (currentReadingLine.contains("errorunique3")) {
errrorTest3Count++;
}

currentReadingLine = reader.readLine();
}
}
Expand All @@ -208,6 +241,13 @@ public void testMultipleInstancesAtTheSameTime() throws Exception {
assertTrue("processes do not log info to the same location",
processInfoLog && process2InfoLog && process1InfoLog);

assertEquals(3, infoTest1Count);
assertEquals(3, infoTest2Count);
assertEquals(3, infoTest3Count);
assertEquals(3, errrorTest1Count);
assertEquals(3, errrorTest2Count);
assertEquals(3, errrorTest3Count);

process.kill();
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED));

Expand Down
1 change: 0 additions & 1 deletion src/test/java/io/supertokens/test/CronjobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ public void testThatCronjobThrowsQuitProgramExceptionAndQuits() throws Exception
Cronjobs.addCronjob(process.getProcess(), QuitProgramExceptionCronjob.getInstance(process.getProcess()));

assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));

process.kill();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/supertokens/test/TelemetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected URLConnection openConnection(URL u) {

telemetryId = telemetryData.get("telemetryId").getAsString();

process.kill();
process.kill(false);
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception {
process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

TenantIdentifier app = new TenantIdentifier(null, "a1", null);
TenantIdentifier tenant = new TenantIdentifier(null, "a1", "t1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO

@Test
public void testDifferentValuesForAppIdThatShouldNotWork() throws Exception {
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

String[] valueForCreate = new String[]{"a_b", "1", "1a", "appid-hello"};
for (int i = 0; i < valueForCreate.length; i++) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ public void testCUDsThatAreSame() throws Exception {

@Test
public void testDifferentValuesForCUDThatShouldNotWork() throws Exception {
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

String[] valueForCreate = new String[]{"http://localhost_com", "localhost:", "abc.example.1com", "domain.com:abcd"};
for (int i = 0; i < valueForCreate.length; i++) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import io.supertokens.featureflag.EE_FEATURES;
import io.supertokens.featureflag.FeatureFlagTestContent;
import io.supertokens.multitenancy.Multitenancy;
import io.supertokens.pluginInterface.STORAGE_TYPE;
import io.supertokens.pluginInterface.multitenancy.*;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.test.TestingProcessManager;
import io.supertokens.test.Utils;
import io.supertokens.test.httpRequest.HttpResponseException;
Expand Down Expand Up @@ -57,6 +59,10 @@ public void testSkipValidation() throws Exception {
process.startProcess();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));

if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(
new TenantIdentifier(null, "a1", null),
new EmailPasswordConfig(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO

@Test
public void testDifferentValuesForTenantIdThatShouldNotWork() throws Exception {
if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) {
return;
}

String[] valueForCreate = new String[]{"a_b", "1", "1a", "appid-hello", "AppId-Hello", "recipe", "reCipe", "CONFIG", "users", "Users"};
for (int i = 0; i < valueForCreate.length; i++) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void createRefreshTokenAndLoadAfterProcessRestart()
TokenInfo tokenInfo = RefreshToken.createNewRefreshToken(process.getProcess(), "sessionHandle", "userId",
"parentRefreshTokenHash1", "antiCsrfToken");

process.kill();
process.kill(false);
assertNotNull(process.checkOrWaitForEvent(PROCESS_STATE.STOPPED));

if (Version.getVersion(process.getProcess()).getPluginName().equals("sqlite")) {
Expand Down
Loading