diff --git a/src/main/java/io/supertokens/storage/postgresql/annotations/EditableInDashboard.java b/src/main/java/io/supertokens/storage/postgresql/annotations/EditableInDashboard.java new file mode 100644 index 00000000..ca31e17a --- /dev/null +++ b/src/main/java/io/supertokens/storage/postgresql/annotations/EditableInDashboard.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, VRAI Labs and/or its affiliates. All rights reserved. + * + * This software is licensed under the Apache License, Version 2.0 (the + * "License") as published by the Apache Software Foundation. + * + * You may not use this file except in compliance with the License. You may + * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +package io.supertokens.storage.postgresql.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface EditableInDashboard { +} diff --git a/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java b/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java index 9f39d995..8963e3e3 100644 --- a/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java +++ b/src/main/java/io/supertokens/storage/postgresql/config/PostgreSQLConfig.java @@ -27,11 +27,7 @@ import io.supertokens.pluginInterface.ConfigFieldInfo; import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.storage.postgresql.Start; -import io.supertokens.storage.postgresql.annotations.ConnectionPoolProperty; -import io.supertokens.storage.postgresql.annotations.IgnoreForAnnotationCheck; -import io.supertokens.storage.postgresql.annotations.NotConflictingWithinUserPool; -import io.supertokens.storage.postgresql.annotations.ConfigDescription; -import io.supertokens.storage.postgresql.annotations.UserPoolProperty; +import io.supertokens.storage.postgresql.annotations.*; import java.lang.reflect.Field; import java.net.URI; @@ -52,6 +48,7 @@ public class PostgreSQLConfig { @JsonProperty @ConnectionPoolProperty @ConfigDescription("Defines the connection pool size to PostgreSQL. (Default: 10)") + @EditableInDashboard private int postgresql_connection_pool_size = 10; @JsonProperty @@ -62,6 +59,7 @@ public class PostgreSQLConfig { @JsonProperty @UserPoolProperty @ConfigDescription("Specify the port to use when connecting to PostgreSQL instance. (Default: 5432)") + @EditableInDashboard private int postgresql_port = -1; @JsonProperty @@ -140,11 +138,13 @@ public class PostgreSQLConfig { @JsonProperty @ConnectionPoolProperty @ConfigDescription("Timeout in milliseconds for the idle connections to be closed. (Default: 60000)") + @EditableInDashboard private long postgresql_idle_connection_timeout = 60000; @JsonProperty @ConnectionPoolProperty @ConfigDescription("Minimum number of idle connections to be kept active. If not set, minimum idle connections will be same as the connection pool size. (Default: null)") + @EditableInDashboard private Integer postgresql_minimum_idle_connections = null; @IgnoreForAnnotationCheck @@ -204,11 +204,11 @@ public static ArrayList getConfigFieldsInfo(Start start) { JsonElement defaultValue = defaultConfig.get(field.getName()); boolean isNullable = defaultValue == null; - boolean isEditable = field.isAnnotationPresent(ConnectionPoolProperty.class); + boolean isEditable = field.isAnnotationPresent(EditableInDashboard.class); result.add(new ConfigFieldInfo( - key, valueType, value, description, isSaasProtected, isDifferentAcrossTenants, - isConfigYamlOnly, possibleValues, isNullable, defaultValue, true, isEditable)); + key, valueType, value, description, isDifferentAcrossTenants, + possibleValues, isNullable, defaultValue, true, isEditable)); } catch (NoSuchFieldException e) { continue; diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/MultitenancyQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/MultitenancyQueries.java index 0d9bf826..a2c0f62d 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/MultitenancyQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/MultitenancyQueries.java @@ -51,6 +51,8 @@ static String getQueryToCreateTenantConfigsTable(Start start) { + "email_password_enabled BOOLEAN," + "passwordless_enabled BOOLEAN," + "third_party_enabled BOOLEAN," + + "use_first_factors_from_static_if_empty BOOLEAN," + + "use_third_party_providers_from_static_if_empty BOOLEAN," + "CONSTRAINT " + Utils.getConstraintName(schema, tenantConfigsTable, null, "pkey") + " PRIMARY KEY (connection_uri_domain, app_id, tenant_id)" + ");"; // @formatter:on diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/multitenancy/TenantConfigSQLHelper.java b/src/main/java/io/supertokens/storage/postgresql/queries/multitenancy/TenantConfigSQLHelper.java index 1a2e00b2..4a5891e9 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/multitenancy/TenantConfigSQLHelper.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/multitenancy/TenantConfigSQLHelper.java @@ -16,15 +16,11 @@ package io.supertokens.storage.postgresql.queries.multitenancy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; import io.supertokens.pluginInterface.RowMapper; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.storage.postgresql.Start; import io.supertokens.storage.postgresql.queries.utils.JsonUtils; -import io.supertokens.storage.postgresql.utils.Utils; import java.sql.Connection; import java.sql.ResultSet; @@ -59,9 +55,13 @@ public TenantConfig map(ResultSet result) throws StorageQueryException { return new TenantConfig( new TenantIdentifier(result.getString("connection_uri_domain"), result.getString("app_id"), result.getString("tenant_id")), new EmailPasswordConfig(result.getBoolean("email_password_enabled")), - new ThirdPartyConfig(result.getBoolean("third_party_enabled"), this.providers), + new ThirdPartyConfig( + result.getBoolean("third_party_enabled"), + result.getBoolean("use_third_party_providers_from_static_if_empty"), + this.providers), new PasswordlessConfig(result.getBoolean("passwordless_enabled")), firstFactors.length == 0 ? null : firstFactors, + result.getBoolean("use_first_factors_from_static_if_empty"), requiredSecondaryFactors.length == 0 ? null : requiredSecondaryFactors, JsonUtils.stringToJsonObject(result.getString("core_config")) ); @@ -74,7 +74,8 @@ public TenantConfig map(ResultSet result) throws StorageQueryException { public static TenantConfig[] selectAll(Start start, HashMap> providerMap, HashMap firstFactorsMap, HashMap requiredSecondaryFactorsMap) throws SQLException, StorageQueryException { String QUERY = "SELECT connection_uri_domain, app_id, tenant_id, core_config," - + " email_password_enabled, passwordless_enabled, third_party_enabled FROM " + + " email_password_enabled, passwordless_enabled, third_party_enabled, " + + " use_first_factors_from_static_if_empty, use_third_party_providers_from_static_if_empty FROM " + getConfig(start).getTenantConfigsTable() + ";"; TenantConfig[] tenantConfigs = execute(start, QUERY, pst -> {}, result -> { @@ -104,8 +105,9 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon throws SQLException, StorageQueryException { String QUERY = "INSERT INTO " + getConfig(start).getTenantConfigsTable() + "(connection_uri_domain, app_id, tenant_id, core_config," - + " email_password_enabled, passwordless_enabled, third_party_enabled)" - + " VALUES(?, ?, ?, ?, ?, ?, ?)"; + + " email_password_enabled, passwordless_enabled, third_party_enabled," + + " use_first_factors_from_static_if_empty, use_third_party_providers_from_static_if_empty)" + + " VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"; update(sqlCon, QUERY, pst -> { pst.setString(1, tenantConfig.tenantIdentifier.getConnectionUriDomain()); @@ -115,6 +117,8 @@ public static void create(Start start, Connection sqlCon, TenantConfig tenantCon pst.setBoolean(5, tenantConfig.emailPasswordConfig.enabled); pst.setBoolean(6, tenantConfig.passwordlessConfig.enabled); pst.setBoolean(7, tenantConfig.thirdPartyConfig.enabled); + pst.setBoolean(8, tenantConfig.useFirstFactorsFromStaticConfigIfEmpty); + pst.setBoolean(9, tenantConfig.thirdPartyConfig.useThirdPartyProvidersFromStaticConfigIfEmpty); }); } diff --git a/src/test/java/io/supertokens/storage/postgresql/test/AccountLinkingTests.java b/src/test/java/io/supertokens/storage/postgresql/test/AccountLinkingTests.java index 5ab09431..5a09066b 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/AccountLinkingTests.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/AccountLinkingTests.java @@ -86,9 +86,9 @@ public void canLinkFailsIfTryingToLinkUsersAcrossDifferentStorageLayers() throws new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ) ); @@ -129,9 +129,9 @@ public void canLinkFailsIfTryingToLinkUsersAcrossDifferentStorageLayers() throws new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ) ); diff --git a/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java b/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java index 470e6ce0..25c3a633 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/DbConnectionPoolTest.java @@ -79,9 +79,9 @@ public void testActiveConnectionsWithTenants() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config ), false); Thread.sleep(1000); // let the new tenant be ready @@ -94,9 +94,9 @@ public void testActiveConnectionsWithTenants() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config ), false); Thread.sleep(2000); // let the new tenant be ready @@ -137,9 +137,9 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config ), false); Thread.sleep(5000); // let the new tenant be ready @@ -197,9 +197,9 @@ public void testDownTimeWhenChangingConnectionPoolSize() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config ), false); Thread.sleep(3000); // let the new tenant be ready @@ -279,9 +279,9 @@ public void testMinimumIdleConnectionForTenants() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config ), false); Thread.sleep(1000); // let the new tenant be ready @@ -295,9 +295,9 @@ public void testMinimumIdleConnectionForTenants() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config ), false); Thread.sleep(2000); // let the new tenant be ready @@ -338,9 +338,9 @@ public void testIdleConnectionTimeout() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config ), false); Thread.sleep(3000); // let the new tenant be ready diff --git a/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java b/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java index 591a4ac0..c8c6626e 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/LoggingTest.java @@ -44,7 +44,6 @@ import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Iterator; -import java.util.List; import java.util.Scanner; import static org.junit.Assert.*; @@ -285,9 +284,9 @@ public void confirmHikariLoggerClosedOnlyWhenProcessEnds() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenant, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, config ), false); @@ -517,9 +516,9 @@ public void testDBPasswordIsNotLoggedWhenTenantIsCreated() throws Exception { new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, config + null, true, null, config )); process.kill(); @@ -562,9 +561,9 @@ public void testDBPasswordIsNotLoggedWhenTenantIsCreated() throws Exception { new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, new JsonObject())); } catch (Exception e) { diff --git a/src/test/java/io/supertokens/storage/postgresql/test/SuperTokensSaaSSecretTest.java b/src/test/java/io/supertokens/storage/postgresql/test/SuperTokensSaaSSecretTest.java index 51673061..cf0e1fdb 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/SuperTokensSaaSSecretTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/SuperTokensSaaSSecretTest.java @@ -87,9 +87,9 @@ public void testThatTenantCannotSetDatabaseRelatedConfigIfSuperTokensSaaSSecretI JsonObject j = new JsonObject(); j.addProperty(PROTECTED_DB_CONFIG[i], ""); Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, j), true); fail(); } catch (BadPermissionException e) { @@ -164,9 +164,9 @@ public void testThatTenantCanSetDatabaseRelatedConfigIfSuperTokensSaaSSecretIsNo } Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, j), false); } @@ -217,9 +217,9 @@ public void testThatTenantCannotGetDatabaseRelatedConfigIfSuperTokensSaaSSecretI } Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null), new TenantConfig(new TenantIdentifier(null, null, "t" + i), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, j)); { diff --git a/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/StorageLayerTest.java b/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/StorageLayerTest.java index 97a3fb6b..ac1ec72a 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/StorageLayerTest.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/StorageLayerTest.java @@ -49,7 +49,6 @@ import java.io.IOException; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -111,9 +110,9 @@ public void mergingTenantWithBaseConfigWorks() TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -162,9 +161,9 @@ public void storageInstanceIsReusedAcrossTenants() TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier(null, "abc", null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -210,19 +209,19 @@ public void storageInstanceIsReusedAcrossTenantsComplex() TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier(null, "abc", null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig), new TenantConfig(new TenantIdentifier(null, "abc", "t1"), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig1), new TenantConfig(new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig1)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -285,9 +284,9 @@ public void mergingTenantWithBaseConfigWithInvalidConfigThrowsErrorWorks() try { TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -319,9 +318,9 @@ public void mergingTenantWithBaseConfigWithConflictingConfigsThrowsError() try { TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier(null, "abc", null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -354,9 +353,9 @@ public void mergingDifferentConnectionPoolIdTenantWithBaseConfigWithConflictingC try { TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier(null, "abc", null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -390,9 +389,9 @@ public void mergingDifferentUserPoolIdTenantWithBaseConfigWithConflictingConfigs TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -441,9 +440,9 @@ public void newStorageIsNotCreatedWhenSameTenantIsAdded() TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier(null, "abc", null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -489,9 +488,9 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() .modifyConfigToAddANewUserPoolForTesting(tenantConfig, 2); tenantConfig.add("postgresql_connection_pool_size", new JsonPrimitive(12)); tenants[0] = new TenantConfig(new TenantIdentifier("c1", null, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig); } @@ -501,9 +500,9 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() .modifyConfigToAddANewUserPoolForTesting(tenantConfig, 2); tenantConfig.add("postgresql_connection_pool_size", new JsonPrimitive(13)); tenants[1] = new TenantConfig(new TenantIdentifier("c1", null, "t1"), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig); } @@ -511,9 +510,9 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() JsonObject tenantConfig = new JsonObject(); tenantConfig.add("postgresql_connection_pool_size", new JsonPrimitive(14)); tenants[2] = new TenantConfig(new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig); } @@ -521,9 +520,9 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() JsonObject tenantConfig = new JsonObject(); tenantConfig.add("postgresql_connection_pool_size", new JsonPrimitive(15)); tenants[3] = new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig); } @@ -585,9 +584,9 @@ public void differentUserPoolCreatedBasedOnSchemaInConnectionUri() TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -628,9 +627,9 @@ public void multipleTenantsSameUserPoolAndConnectionPoolShouldWork() TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier(null, "abc", null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -664,9 +663,9 @@ public void multipleTenantsSameUserPoolAndDifferentConnectionPoolShouldWork() TenantConfig[] tenants = new TenantConfig[]{ new TenantConfig(new TenantIdentifier(null, "abc", null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfig)}; Config.loadAllTenantConfig(process.getProcess(), tenants); @@ -704,9 +703,9 @@ public void testCreating50StorageLayersUsage() config.addProperty("postgresql_database_name", "st" + insideLoop); tenants[insideLoop] = new TenantConfig(new TenantIdentifier(null, "a" + insideLoop, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, config); try { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantIdentifier(null, null, null), @@ -758,9 +757,9 @@ public void testCantCreateTenantWithUnknownDb() TenantConfig tenantConfig = new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfigJson); try { @@ -800,9 +799,9 @@ public void testTenantCreationAndThenDbDownDbThrowsErrorInRecipesAndDoesntAffect TenantConfig tenantConfig = new TenantConfig(tid, new EmailPasswordConfig(true), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfigJson); StorageLayer.getMultitenancyStorage(process.getProcess()).createTenant(tenantConfig); @@ -881,9 +880,9 @@ public void testBadPortWithNewTenantShouldNotCauseItToWaitInput() throws Excepti TenantConfig tenantConfig = new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), - new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), + new ThirdPartyConfig(false, true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - null, null, + null, true, null, tenantConfigJson); try { diff --git a/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestForNoCrashDuringStartup.java b/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestForNoCrashDuringStartup.java index b8635224..b79f1c00 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestForNoCrashDuringStartup.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestForNoCrashDuringStartup.java @@ -92,9 +92,9 @@ public void testThatCUDRecoversWhenItFailsToAddEntryDuringCreation() throws Exce Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -139,9 +139,9 @@ public void testThatCUDRecoversWhenTheDbIsDownDuringCreationButDbComesUpLater() Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -178,9 +178,9 @@ public void testThatAppRecoversAfterAppCreationFailedToAddEntry() throws Excepti Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -206,9 +206,9 @@ public void testThatAppRecoversAfterAppCreationFailedToAddEntry() throws Excepti Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); @@ -230,9 +230,9 @@ public void testThatCoreDoesNotCrashDuringStartupWhenCUDCreationFailedToAddEntry Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -276,9 +276,9 @@ public void testThatCoreDoesNotCrashDuringStartupWhenTenantEntryIsInconsistentIn Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -322,9 +322,9 @@ public void testThatCoreDoesNotCrashDuringStartupWhenAppCreationFailedToAddEntry Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -376,9 +376,9 @@ public void testThatCoreDoesNotCrashDuringStartupWhenCUDCreationFailedToAddTenan Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -393,9 +393,9 @@ public void testThatCoreDoesNotCrashDuringStartupWhenCUDCreationFailedToAddTenan Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -410,9 +410,9 @@ public void testThatCoreDoesNotCrashDuringStartupWhenCUDCreationFailedToAddTenan Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier("cud2", null, null), new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); @@ -503,9 +503,9 @@ public void testThatTenantComesToLifeOnceTheTargetDbIsUpAfterCoreRestart() throw Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); fail(); diff --git a/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestUserPoolIdChangeBehaviour.java b/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestUserPoolIdChangeBehaviour.java index 758e749a..cc991404 100644 --- a/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestUserPoolIdChangeBehaviour.java +++ b/src/test/java/io/supertokens/storage/postgresql/test/multitenancy/TestUserPoolIdChangeBehaviour.java @@ -82,9 +82,9 @@ public void testUsersWorkAfterUserPoolIdChanges() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); @@ -100,9 +100,9 @@ public void testUsersWorkAfterUserPoolIdChanges() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); @@ -129,9 +129,9 @@ public void testUsersWorkAfterUserPoolIdChangesAndServerRestart() throws Excepti Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false); @@ -147,9 +147,9 @@ public void testUsersWorkAfterUserPoolIdChangesAndServerRestart() throws Excepti Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( tenantIdentifier, new EmailPasswordConfig(true), - new ThirdPartyConfig(true, null), + new ThirdPartyConfig(true, true, null), new PasswordlessConfig(true), - null, null, + null, true, null, coreConfig ), false);