From da5dfa20a2584e66faa76251675e91dfc33d0a18 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 27 Oct 2023 12:58:05 +0530 Subject: [PATCH] Mfa multitenancy (#841) * fix: multitenancy changes * fix: mfa cleanup * fix: mfa cleanup * fix: test * fix: api * fix: mfa multitenancy updates * fix: tests * fix: mfa * fix: tests * fix: tests * fix: pr comments * fix: pr comments * fix: pr comments * fix: tests * fix: tests * fix: pr comments --- coreDriverInterfaceSupported.json | 3 +- .../ee/test/TestMultitenancyStats.java | 3 + .../multitenancy/TenantConfigSQLHelper.java | 4 +- .../multitenancy/MultitenancyHelper.java | 6 +- .../java/io/supertokens/utils/SemVer.java | 1 + .../supertokens/webserver/WebserverAPI.java | 3 +- .../api/multitenancy/BaseCreateOrUpdate.java | 57 +++- .../multitenancy/CreateOrUpdateAppAPI.java | 43 ++- .../CreateOrUpdateConnectionUriDomainAPI.java | 41 ++- .../CreateOrUpdateTenantOrGetTenantAPI.java | 47 ++- .../CreateOrUpdateThirdPartyConfigAPI.java | 4 +- .../thirdparty/RemoveThirdPartyConfigAPI.java | 4 +- .../io/supertokens/test/CDIVersionTest.java | 8 +- .../java/io/supertokens/test/CronjobTest.java | 60 ++++ .../io/supertokens/test/FeatureFlagTest.java | 10 + .../io/supertokens/test/HelloAPITest.java | 9 + .../test/IpAllowDenyRegexTest.java | 4 + .../io/supertokens/test/PathRouterTest.java | 180 +++++++---- .../io/supertokens/test/StorageLayerTest.java | 2 +- .../test/SuperTokensSaaSSecretTest.java | 15 +- .../test/TestHelloAPIRateLimiting.java | 3 + .../accountlinking/CreatePrimaryUserTest.java | 6 +- .../test/accountlinking/LinkAccountsTest.java | 6 +- .../test/accountlinking/MultitenantTest.java | 12 +- .../test/accountlinking/SessionTests.java | 12 +- .../api/CreatePrimaryUserAPITest.java | 3 +- .../test/authRecipe/MultitenantAPITest.java | 3 + .../test/authRecipe/UserPaginationTest.java | 3 + .../dashboard/apis/MultitenantAPITest.java | 3 + .../test/emailpassword/EmailPasswordTest.java | 2 + .../MultitenantEmailPasswordTest.java | 3 + .../emailpassword/api/MultitenantAPITest.java | 3 + .../api/MultitenantAPITest.java | 3 + .../test/multitenant/AppTenantUserTest.java | 24 +- .../test/multitenant/ConfigTest.java | 239 +++++++++----- .../test/multitenant/LoadTest.java | 3 +- .../supertokens/test/multitenant/LogTest.java | 20 +- .../test/multitenant/RandomConfigTest.java | 2 +- .../RequestConnectionUriDomainTest.java | 20 +- .../test/multitenant/SigningKeysTest.java | 9 +- .../test/multitenant/StorageLayerTest.java | 89 +++-- .../test/multitenant/TestAppData.java | 6 +- .../test/multitenant/api/TestApp.java | 303 +++++++++++++++++ .../api/TestConnectionUriDomain.java | 303 +++++++++++++++++ .../api/TestMultitenancyAPIHelper.java | 73 ++++- .../TestSkipValidationInCreateThirdParty.java | 3 +- .../test/multitenant/api/TestTenant.java | 305 +++++++++++++++++- .../TestTenantIdIsNotPresentForOlderCDI.java | 9 +- .../generator/GenerateTenantConfig.java | 76 +++++ .../generator/GenerateTotpConfig.java | 28 ++ .../passwordless/api/MultitenantAPITest.java | 3 + .../test/session/api/MultitenantAPITest.java | 3 + .../thirdparty/api/MultitenantAPITest.java | 3 + .../test/totp/api/MultitenantAPITest.java | 3 + .../userIdMapping/api/MultitenantAPITest.java | 12 +- 55 files changed, 1842 insertions(+), 260 deletions(-) create mode 100644 src/test/java/io/supertokens/test/multitenant/generator/GenerateTotpConfig.java diff --git a/coreDriverInterfaceSupported.json b/coreDriverInterfaceSupported.json index 683d582a9..568ea43ec 100644 --- a/coreDriverInterfaceSupported.json +++ b/coreDriverInterfaceSupported.json @@ -17,6 +17,7 @@ "2.20", "2.21", "3.0", - "4.0" + "4.0", + "4.1" ] } diff --git a/ee/src/test/java/io/supertokens/ee/test/TestMultitenancyStats.java b/ee/src/test/java/io/supertokens/ee/test/TestMultitenancyStats.java index 189d2b1d1..ef0d54f58 100644 --- a/ee/src/test/java/io/supertokens/ee/test/TestMultitenancyStats.java +++ b/ee/src/test/java/io/supertokens/ee/test/TestMultitenancyStats.java @@ -78,6 +78,7 @@ public void testPaidStatsIsSentForAllAppsInMultitenancy() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ), false); @@ -86,6 +87,7 @@ public void testPaidStatsIsSentForAllAppsInMultitenancy() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ), false); @@ -94,6 +96,7 @@ public void testPaidStatsIsSentForAllAppsInMultitenancy() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ), false); } diff --git a/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java b/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java index 6b5ce3931..dce7bfffb 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java @@ -53,7 +53,9 @@ public TenantConfig map(ResultSet result) throws StorageQueryException { new EmailPasswordConfig(result.getBoolean("email_password_enabled")), new ThirdPartyConfig(result.getBoolean("third_party_enabled"), this.providers), new PasswordlessConfig(result.getBoolean("passwordless_enabled")), - JsonUtils.stringToJsonObject(result.getString("core_config")) + new TotpConfig(false), // TODO + null, null, JsonUtils.stringToJsonObject(result.getString("core_config")) + // TODO ); } catch (Exception e) { throw new StorageQueryException(e); diff --git a/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java b/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java index fe9397622..647ccedff 100644 --- a/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java +++ b/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java @@ -75,7 +75,8 @@ public static void init(Main main) throws StorageQueryException, IOException { new TenantConfig( new TenantIdentifier(null, null, null), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), - new PasswordlessConfig(true), new JsonObject()), false, false, false); + new PasswordlessConfig(true), new TotpConfig(true), + null, null, new JsonObject()), false, false, false); // Not force reloading all resources here (the last boolean in the function above) // because the ucl for the FeatureFlag is not yet loaded and results in an empty // instance of eeFeatureFlag. This is applicable only when the core is starting on @@ -95,7 +96,8 @@ private TenantConfig[] getAllTenantsFromDb() throws StorageQueryException { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(true), + null, null, new JsonObject() ) }; } diff --git a/src/main/java/io/supertokens/utils/SemVer.java b/src/main/java/io/supertokens/utils/SemVer.java index 64b63ace6..1da0e83e4 100644 --- a/src/main/java/io/supertokens/utils/SemVer.java +++ b/src/main/java/io/supertokens/utils/SemVer.java @@ -34,6 +34,7 @@ public class SemVer implements Comparable { public static final SemVer v2_21 = new SemVer("2.21"); public static final SemVer v3_0 = new SemVer("3.0"); public static final SemVer v4_0 = new SemVer("4.0"); + public static final SemVer v4_1 = new SemVer("4.1"); final private String version; diff --git a/src/main/java/io/supertokens/webserver/WebserverAPI.java b/src/main/java/io/supertokens/webserver/WebserverAPI.java index fb20f98fe..ea3ac89f4 100644 --- a/src/main/java/io/supertokens/webserver/WebserverAPI.java +++ b/src/main/java/io/supertokens/webserver/WebserverAPI.java @@ -76,10 +76,11 @@ public abstract class WebserverAPI extends HttpServlet { supportedVersions.add(SemVer.v2_21); supportedVersions.add(SemVer.v3_0); supportedVersions.add(SemVer.v4_0); + supportedVersions.add(SemVer.v4_1); } public static SemVer getLatestCDIVersion() { - return SemVer.v4_0; + return SemVer.v4_1; } public SemVer getLatestCDIVersionForRequest(HttpServletRequest req) diff --git a/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java b/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java index ac930fb7b..edc284730 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java @@ -45,8 +45,10 @@ public BaseCreateOrUpdate(Main main) { protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdentifier, TenantIdentifier targetTenantIdentifier, Boolean emailPasswordEnabled, - Boolean thirdPartyEnabled, Boolean passwordlessEnabled, JsonObject coreConfig, - HttpServletResponse resp) + Boolean thirdPartyEnabled, Boolean passwordlessEnabled, Boolean totpEnabled, + boolean hasFirstFactors, String[] firstFactors, + boolean hasDefaultRequiredFactorIds, String[] defaultRequiredFactorIds, + JsonObject coreConfig, HttpServletResponse resp) throws ServletException, IOException { TenantConfig tenantConfig = Multitenancy.getTenantInfo(main, @@ -63,7 +65,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(true), + null, null, new JsonObject() ); } else { // We disable all recipes by default while creating tenant @@ -72,7 +75,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ); } createdNew = true; @@ -84,7 +88,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new EmailPasswordConfig(emailPasswordEnabled), tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, - tenantConfig.coreConfig + tenantConfig.totpConfig, + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -94,7 +99,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.emailPasswordConfig, new ThirdPartyConfig(thirdPartyEnabled, tenantConfig.thirdPartyConfig.providers), tenantConfig.passwordlessConfig, - tenantConfig.coreConfig + tenantConfig.totpConfig, + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -104,7 +110,41 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.emailPasswordConfig, tenantConfig.thirdPartyConfig, new PasswordlessConfig(passwordlessEnabled), - tenantConfig.coreConfig + tenantConfig.totpConfig, + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig + ); + } + + if (totpEnabled != null) { + tenantConfig = new TenantConfig( + tenantConfig.tenantIdentifier, + tenantConfig.emailPasswordConfig, + tenantConfig.thirdPartyConfig, + tenantConfig.passwordlessConfig, + new TotpConfig(totpEnabled), + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig + ); + } + + if (hasFirstFactors) { + tenantConfig = new TenantConfig( + tenantConfig.tenantIdentifier, + tenantConfig.emailPasswordConfig, + tenantConfig.thirdPartyConfig, + tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig + ); + } + + if (hasDefaultRequiredFactorIds) { + tenantConfig = new TenantConfig( + tenantConfig.tenantIdentifier, + tenantConfig.emailPasswordConfig, + tenantConfig.thirdPartyConfig, + tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + tenantConfig.firstFactors, defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -115,7 +155,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.emailPasswordConfig, tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, - coreConfig + tenantConfig.totpConfig, + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, coreConfig ); } diff --git a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java index d84cfcf7b..7df23ccf1 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -16,19 +16,22 @@ package io.supertokens.webserver.api.multitenancy; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.supertokens.Main; -import io.supertokens.multitenancy.exception.BadPermissionException; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; +import io.supertokens.utils.SemVer; import io.supertokens.webserver.InputParser; import io.supertokens.webserver.Utils; -import io.supertokens.webserver.api.multitenancy.BaseCreateOrUpdate; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class CreateOrUpdateAppAPI extends BaseCreateOrUpdate { @@ -56,6 +59,38 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); + Boolean totpEnabled = null; + String[] firstFactors = null; + boolean hasFirstFactors = false; + String[] defaultRequiredFactorIds = null; + boolean hasDefaultRequiredFactorIds = false; + + if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { + totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + hasFirstFactors = input.has("firstFactors"); + if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { + JsonArray firstFactorsArr = InputParser.parseArrayOrThrowError(input, "firstFactors", true); + firstFactors = new String[firstFactorsArr.size()]; + for (int i = 0; i < firstFactors.length; i++) { + firstFactors[i] = InputParser.parseStringFromElementOrThrowError(firstFactorsArr.get(i), "firstFactors", false); + } + if (firstFactors.length != new HashSet<>(Arrays.asList(firstFactors)).size()) { + throw new ServletException(new BadRequestException("firstFactors input should not contain duplicate values")); + } + } + hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); + if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { + JsonArray defaultRequiredFactorIdsArr = InputParser.parseArrayOrThrowError(input, "defaultRequiredFactorIds", true); + defaultRequiredFactorIds = new String[defaultRequiredFactorIdsArr.size()]; + for (int i = 0; i < defaultRequiredFactorIds.length; i++) { + defaultRequiredFactorIds[i] = InputParser.parseStringFromElementOrThrowError(defaultRequiredFactorIdsArr.get(i), "defaultRequiredFactorIds", false); + } + if (defaultRequiredFactorIds.length != new HashSet<>(Arrays.asList(defaultRequiredFactorIds)).size()) { + throw new ServletException(new BadRequestException("defaultRequiredFactorIds input should not contain duplicate values")); + } + } + } + TenantIdentifier sourceTenantIdentifier; try { sourceTenantIdentifier = this.getTenantIdentifierWithStorageFromRequest(req); @@ -66,7 +101,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO super.handle( req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), appId, null), - emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, coreConfig, resp); + emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, + totpEnabled, hasFirstFactors, firstFactors, hasDefaultRequiredFactorIds, defaultRequiredFactorIds, + coreConfig, resp); } } diff --git a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java index 8d88cb8d6..dd3298b89 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -16,10 +16,12 @@ package io.supertokens.webserver.api.multitenancy; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.supertokens.Main; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; +import io.supertokens.utils.SemVer; import io.supertokens.webserver.InputParser; import io.supertokens.webserver.Utils; import jakarta.servlet.ServletException; @@ -27,6 +29,9 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class CreateOrUpdateConnectionUriDomainAPI extends BaseCreateOrUpdate { @@ -54,6 +59,38 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); + Boolean totpEnabled = null; + String[] firstFactors = null; + boolean hasFirstFactors = false; + String[] defaultRequiredFactorIds = null; + boolean hasDefaultRequiredFactorIds = false; + + if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { + totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + hasFirstFactors = input.has("firstFactors"); + if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { + JsonArray firstFactorsArr = InputParser.parseArrayOrThrowError(input, "firstFactors", true); + firstFactors = new String[firstFactorsArr.size()]; + for (int i = 0; i < firstFactors.length; i++) { + firstFactors[i] = InputParser.parseStringFromElementOrThrowError(firstFactorsArr.get(i), "firstFactors", false); + } + if (firstFactors.length != new HashSet<>(Arrays.asList(firstFactors)).size()) { + throw new ServletException(new BadRequestException("firstFactors input should not contain duplicate values")); + } + } + hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); + if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { + JsonArray defaultRequiredFactorIdsArr = InputParser.parseArrayOrThrowError(input, "defaultRequiredFactorIds", true); + defaultRequiredFactorIds = new String[defaultRequiredFactorIdsArr.size()]; + for (int i = 0; i < defaultRequiredFactorIds.length; i++) { + defaultRequiredFactorIds[i] = InputParser.parseStringFromElementOrThrowError(defaultRequiredFactorIdsArr.get(i), "defaultRequiredFactorIds", false); + } + if (defaultRequiredFactorIds.length != new HashSet<>(Arrays.asList(defaultRequiredFactorIds)).size()) { + throw new ServletException(new BadRequestException("defaultRequiredFactorIds input should not contain duplicate values")); + } + } + } + TenantIdentifier sourceTenantIdentifier; try { sourceTenantIdentifier = this.getTenantIdentifierWithStorageFromRequest(req); @@ -64,7 +101,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO super.handle( req, sourceTenantIdentifier, new TenantIdentifier(connectionUriDomain, null, null), - emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, coreConfig, resp); + emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, + totpEnabled, hasFirstFactors, firstFactors, hasDefaultRequiredFactorIds, defaultRequiredFactorIds, + coreConfig, resp); } } diff --git a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java index 27d08cc40..c42b1a10d 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -16,12 +16,14 @@ package io.supertokens.webserver.api.multitenancy; +import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.supertokens.Main; import io.supertokens.config.CoreConfig; import io.supertokens.multitenancy.Multitenancy; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; +import io.supertokens.utils.SemVer; import io.supertokens.webserver.InputParser; import io.supertokens.webserver.Utils; import jakarta.servlet.ServletException; @@ -29,6 +31,9 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; public class CreateOrUpdateTenantOrGetTenantAPI extends BaseCreateOrUpdate { @@ -57,6 +62,38 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); + Boolean totpEnabled = null; + String[] firstFactors = null; + boolean hasFirstFactors = false; + String[] defaultRequiredFactorIds = null; + boolean hasDefaultRequiredFactorIds = false; + + if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { + totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + hasFirstFactors = input.has("firstFactors"); + if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { + JsonArray firstFactorsArr = InputParser.parseArrayOrThrowError(input, "firstFactors", true); + firstFactors = new String[firstFactorsArr.size()]; + for (int i = 0; i < firstFactors.length; i++) { + firstFactors[i] = InputParser.parseStringFromElementOrThrowError(firstFactorsArr.get(i), "firstFactors", false); + } + if (firstFactors.length != new HashSet<>(Arrays.asList(firstFactors)).size()) { + throw new ServletException(new BadRequestException("firstFactors input should not contain duplicate values")); + } + } + hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); + if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { + JsonArray defaultRequiredFactorIdsArr = InputParser.parseArrayOrThrowError(input, "defaultRequiredFactorIds", true); + defaultRequiredFactorIds = new String[defaultRequiredFactorIdsArr.size()]; + for (int i = 0; i < defaultRequiredFactorIds.length; i++) { + defaultRequiredFactorIds[i] = InputParser.parseStringFromElementOrThrowError(defaultRequiredFactorIdsArr.get(i), "defaultRequiredFactorIds", false); + } + if (defaultRequiredFactorIds.length != new HashSet<>(Arrays.asList(defaultRequiredFactorIds)).size()) { + throw new ServletException(new BadRequestException("defaultRequiredFactorIds input should not contain duplicate values")); + } + } + } + TenantIdentifier sourceTenantIdentifier; try { sourceTenantIdentifier = this.getTenantIdentifierWithStorageFromRequest(req); @@ -67,8 +104,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO super.handle( req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), sourceTenantIdentifier.getAppId(), tenantId), - emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, coreConfig, resp); - + emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, + totpEnabled, hasFirstFactors, firstFactors, hasDefaultRequiredFactorIds, defaultRequiredFactorIds, + coreConfig, resp); } @Override @@ -83,6 +121,11 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject result = config.toJson(shouldProtect, tenantIdentifier.getStorage(), CoreConfig.PROTECTED_CONFIGS); result.addProperty("status", "OK"); + if (getVersionFromRequest(req).lesserThan(SemVer.v4_1)) { + result.remove("totp"); + result.remove("mfa"); + } + super.sendJsonResponse(200, result, resp); } catch (TenantOrAppNotFoundException e) { JsonObject result = new JsonObject(); diff --git a/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/CreateOrUpdateThirdPartyConfigAPI.java b/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/CreateOrUpdateThirdPartyConfigAPI.java index eff3a93d9..667c6fb27 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/CreateOrUpdateThirdPartyConfigAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/CreateOrUpdateThirdPartyConfigAPI.java @@ -114,7 +114,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO tenantConfig.thirdPartyConfig.enabled, newProviders.toArray(new ThirdPartyConfig.Provider[0])), tenantConfig.passwordlessConfig, - tenantConfig.coreConfig); + tenantConfig.totpConfig, + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig + ); Multitenancy.addNewOrUpdateAppOrTenant(main, updatedConfig, shouldProtectProtectedConfig(req), skipValidation, true); diff --git a/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/RemoveThirdPartyConfigAPI.java b/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/RemoveThirdPartyConfigAPI.java index 8f5b5570c..e846647a2 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/RemoveThirdPartyConfigAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/thirdparty/RemoveThirdPartyConfigAPI.java @@ -82,7 +82,9 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I new ThirdPartyConfig( config.thirdPartyConfig.enabled, newProviders.toArray(new ThirdPartyConfig.Provider[0])), config.passwordlessConfig, - config.coreConfig); + config.totpConfig, + config.firstFactors, config.defaultRequiredFactorIds, config.coreConfig + ); Multitenancy.addNewOrUpdateAppOrTenant(main, updatedConfig, shouldProtectProtectedConfig(req), false, true); diff --git a/src/test/java/io/supertokens/test/CDIVersionTest.java b/src/test/java/io/supertokens/test/CDIVersionTest.java index 5c2b31e17..a65bf9853 100644 --- a/src/test/java/io/supertokens/test/CDIVersionTest.java +++ b/src/test/java/io/supertokens/test/CDIVersionTest.java @@ -26,7 +26,6 @@ import io.supertokens.multitenancy.Multitenancy; import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.multitenancy.*; -import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.storageLayer.StorageLayer; import io.supertokens.test.httpRequest.HttpRequestForTesting; import io.supertokens.test.httpRequest.HttpResponseException; @@ -43,7 +42,6 @@ import org.junit.rules.TestRule; import java.io.IOException; -import java.rmi.ServerException; import java.util.HashMap; import static junit.framework.TestCase.assertEquals; @@ -274,14 +272,16 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, "a1", "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); String response = HttpRequestForTesting.sendGETRequest(process.getProcess(), "", diff --git a/src/test/java/io/supertokens/test/CronjobTest.java b/src/test/java/io/supertokens/test/CronjobTest.java index 8baebba6f..de47144d0 100644 --- a/src/test/java/io/supertokens/test/CronjobTest.java +++ b/src/test/java/io/supertokens/test/CronjobTest.java @@ -462,6 +462,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -469,6 +471,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -476,6 +480,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -483,6 +489,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); @@ -496,6 +504,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, config ), false); @@ -504,6 +514,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -511,6 +523,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -518,6 +532,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, config ), false); @@ -546,6 +562,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -553,6 +571,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -560,6 +580,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -567,6 +589,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); @@ -598,6 +622,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -605,6 +631,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -612,6 +640,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -619,6 +649,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); @@ -651,6 +683,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -658,6 +692,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -665,6 +701,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -672,6 +710,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); @@ -708,6 +748,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -715,6 +757,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, new JsonObject() ), false); JsonObject config = new JsonObject(); @@ -725,6 +769,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -732,6 +778,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, config ), false); @@ -771,6 +819,8 @@ public void testThatCoreAutomaticallySyncsToConfigChangesInDb() throws Exception new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), + null, null, new JsonObject() ), false); @@ -791,6 +841,8 @@ public void testThatCoreAutomaticallySyncsToConfigChangesInDb() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), + null, null, new JsonObject() )); @@ -891,6 +943,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -898,6 +952,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -905,6 +961,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -912,6 +970,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + null, null, coreConfig ), false, false, true); diff --git a/src/test/java/io/supertokens/test/FeatureFlagTest.java b/src/test/java/io/supertokens/test/FeatureFlagTest.java index 2c52f5d53..5da1a28cc 100644 --- a/src/test/java/io/supertokens/test/FeatureFlagTest.java +++ b/src/test/java/io/supertokens/test/FeatureFlagTest.java @@ -291,6 +291,7 @@ public void testFeatureFlagWithMultitenancyFor500Tenants() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, new JsonObject() ) ); @@ -352,6 +353,7 @@ public void testThatMultitenantStatsAreAccurate() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ) ); @@ -379,6 +381,7 @@ public void testThatMultitenantStatsAreAccurate() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ) ); @@ -451,6 +454,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, new JsonObject() ) ); @@ -469,6 +473,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ) ); @@ -496,6 +501,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ) ); @@ -577,6 +583,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ) ); @@ -596,6 +603,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ) ); @@ -623,6 +631,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ) ); @@ -695,6 +704,7 @@ public void testPaidFeaturesAreEnabledIfUsingInMemoryDatabase() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, new JsonObject() ) ); diff --git a/src/test/java/io/supertokens/test/HelloAPITest.java b/src/test/java/io/supertokens/test/HelloAPITest.java index 61049ff3e..fb2e9836a 100644 --- a/src/test/java/io/supertokens/test/HelloAPITest.java +++ b/src/test/java/io/supertokens/test/HelloAPITest.java @@ -118,6 +118,7 @@ public void testHelloAPIWithBasePath3() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -126,6 +127,7 @@ public void testHelloAPIWithBasePath3() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -134,6 +136,7 @@ public void testHelloAPIWithBasePath3() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -201,6 +204,7 @@ public void testWithBasePathThatHelloAPIDoesNotRequireAPIKeys() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -209,6 +213,7 @@ public void testWithBasePathThatHelloAPIDoesNotRequireAPIKeys() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -217,6 +222,7 @@ public void testWithBasePathThatHelloAPIDoesNotRequireAPIKeys() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -285,6 +291,7 @@ public void testThatHelloAPIDoesNotRequireAPIKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -293,6 +300,7 @@ public void testThatHelloAPIDoesNotRequireAPIKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -301,6 +309,7 @@ public void testThatHelloAPIDoesNotRequireAPIKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject() ), false); diff --git a/src/test/java/io/supertokens/test/IpAllowDenyRegexTest.java b/src/test/java/io/supertokens/test/IpAllowDenyRegexTest.java index 962997eea..61c2004b9 100644 --- a/src/test/java/io/supertokens/test/IpAllowDenyRegexTest.java +++ b/src/test/java/io/supertokens/test/IpAllowDenyRegexTest.java @@ -385,11 +385,13 @@ public void CheckThatIPFiltersAreTenantSpecific() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, new JsonObject() ), false); @@ -425,11 +427,13 @@ public void CheckThatIPFiltersAreTenantSpecific() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, coreConfig ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, new JsonObject() ), false); diff --git a/src/test/java/io/supertokens/test/PathRouterTest.java b/src/test/java/io/supertokens/test/PathRouterTest.java index 555007e24..4132bf6f3 100644 --- a/src/test/java/io/supertokens/test/PathRouterTest.java +++ b/src/test/java/io/supertokens/test/PathRouterTest.java @@ -91,7 +91,8 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -102,7 +103,8 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -113,7 +115,8 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -263,7 +266,8 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -274,7 +278,8 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -285,7 +290,8 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -435,7 +441,8 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -446,7 +453,8 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -457,7 +465,8 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -617,7 +626,8 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -628,7 +638,8 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -639,7 +650,8 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -800,7 +812,8 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -811,7 +824,8 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -822,7 +836,8 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -980,7 +995,8 @@ public void withRecipeRouterTest() throws Exception { new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant( @@ -990,7 +1006,8 @@ public void withRecipeRouterTest() throws Exception { new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); @@ -1322,7 +1339,8 @@ public void tenantNotFoundTest() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1330,7 +1348,8 @@ public void tenantNotFoundTest() new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1338,7 +1357,8 @@ public void tenantNotFoundTest() new TenantConfig(new TenantIdentifier("127.0.0.1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1346,7 +1366,8 @@ public void tenantNotFoundTest() new TenantConfig(new TenantIdentifier("127.0.0.1", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); @@ -1443,7 +1464,8 @@ public void tenantNotFoundTest2() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1451,7 +1473,8 @@ public void tenantNotFoundTest2() new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1459,7 +1482,8 @@ public void tenantNotFoundTest2() new TenantConfig(new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - new JsonObject()), + new TotpConfig(false), + null, null, new JsonObject()), false ); @@ -1560,11 +1584,13 @@ public void tenantNotFoundTest3() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -1623,7 +1649,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1634,7 +1661,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1645,7 +1673,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1656,7 +1685,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1667,7 +1697,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1678,7 +1709,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1689,7 +1721,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1924,7 +1957,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1935,7 +1969,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1946,7 +1981,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1957,7 +1993,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1968,7 +2005,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1979,7 +2017,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1990,7 +2029,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2209,7 +2249,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2220,7 +2261,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2231,7 +2273,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2242,7 +2285,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2253,7 +2297,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2264,7 +2309,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2275,7 +2321,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2511,7 +2558,8 @@ public void tenantNotFoundWithAppIdTest() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2519,7 +2567,8 @@ public void tenantNotFoundWithAppIdTest() new TenantConfig(new TenantIdentifier("localhost", "app1", null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2527,7 +2576,8 @@ public void tenantNotFoundWithAppIdTest() new TenantConfig(new TenantIdentifier("localhost", "app1", "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2535,7 +2585,8 @@ public void tenantNotFoundWithAppIdTest() new TenantConfig(new TenantIdentifier("127.0.0.1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -2585,7 +2636,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I new TenantConfig(new TenantIdentifier("127.0.0.1", "app1", null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2593,7 +2645,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I new TenantConfig(new TenantIdentifier("127.0.0.1", "app1", "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); @@ -2651,7 +2704,8 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2659,7 +2713,8 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier("localhost", "app1", null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2667,7 +2722,8 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier("localhost", "app1", "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2675,7 +2731,8 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier(null, "app2", null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - new JsonObject()), + new TotpConfig(false), + null, null, new JsonObject()), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2683,7 +2740,8 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier(null, "app2", "t2"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - new JsonObject()), + new TotpConfig(false), + null, null, new JsonObject()), false ); @@ -2815,11 +2873,13 @@ public void tenantNotFoundWithAppIdTest3() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), new TenantConfig(new TenantIdentifier("localhost", "app1", "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { diff --git a/src/test/java/io/supertokens/test/StorageLayerTest.java b/src/test/java/io/supertokens/test/StorageLayerTest.java index 1b9c72922..a3b08c356 100644 --- a/src/test/java/io/supertokens/test/StorageLayerTest.java +++ b/src/test/java/io/supertokens/test/StorageLayerTest.java @@ -97,7 +97,7 @@ public void totpCodeLengthTest() throws Exception { // This error will be different in Postgres and MySQL // We added (CHECK (LENGTH(code) <= 8)) to the table definition in SQLite String totpUsedCodeTable = Config.getConfig(start).getTotpUsedCodesTable(); - assert e.getMessage().contains("CHECK constraint failed: " + totpUsedCodeTable); + assert e.getMessage().contains("CHECK constraint failed: " + totpUsedCodeTable) || e.getMessage().contains("LENGTH(code) <= 8"); } // Try code with length < 8 diff --git a/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java b/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java index 1e565cec5..c9f73e2e1 100644 --- a/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java +++ b/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java @@ -358,7 +358,8 @@ public void gettingTenantShouldNotExposeSuperTokensSaaSSecret() new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantConfig[] tenantConfigs = Multitenancy.getAllTenants(process.main); @@ -400,7 +401,8 @@ public void testThatTenantCannotSetSuperTokensSaasSecret() new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - j)); + new TotpConfig(false), + null, null, j)); fail(); } catch (InvalidConfigException e) { assertEquals(e.getMessage(), "supertokens_saas_secret can only be set via the core's base config setting"); @@ -463,7 +465,8 @@ public void testThatTenantCannotSetProtectedConfigIfSuperTokensSaaSSecretIsSet() Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - j), true); + new TotpConfig(false), + null, null, j), true); fail(); } catch (BadPermissionException e) { assertEquals(e.getMessage(), "Not allowed to modify protected configs."); @@ -549,7 +552,8 @@ public void testThatTenantCannotGetProtectedConfigIfSuperTokensSaaSSecretIsSet() new TenantConfig(new TenantIdentifier(null, null, "t" + i), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - j)); + new TotpConfig(false), + null, null, j)); { JsonObject response = HttpRequestForTesting.sendJsonRequest(process.getProcess(), "", @@ -628,7 +632,8 @@ public void testLogContainsCorrectCud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); { // clear the logs diff --git a/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java b/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java index 2a1e7f013..dd2ce6b8a 100644 --- a/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java +++ b/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java @@ -78,6 +78,7 @@ private void createApps(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -98,6 +99,7 @@ private void createApps(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -118,6 +120,7 @@ private void createApps(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java b/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java index 5614de91d..ebacc13df 100644 --- a/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java @@ -422,7 +422,8 @@ public void makePrimaryUserFailsCauseAnotherAccountWithSameEmailAlreadyAPrimaryU Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null), new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", StorageLayer.getStorage(process.main)); @@ -468,7 +469,8 @@ public void makePrimarySucceedsEvenIfAnotherAccountWithSameEmailButInADifferentT Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null), new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", StorageLayer.getStorage(process.main)); diff --git a/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java b/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java index aab79a23a..23bab1b97 100644 --- a/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java @@ -465,7 +465,8 @@ public void linkAccountFailureCauseAccountInfoAssociatedWithAPrimaryUserEvenIfIn Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null), new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", StorageLayer.getStorage(process.main)); @@ -518,7 +519,8 @@ public void linkAccountSuccessAcrossTenants() throws Exception { Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null), new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", StorageLayer.getStorage(process.main)); diff --git a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java index 438aea250..9c988bc4f 100644 --- a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java @@ -99,7 +99,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -119,7 +120,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -139,7 +141,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -159,7 +162,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } diff --git a/src/test/java/io/supertokens/test/accountlinking/SessionTests.java b/src/test/java/io/supertokens/test/accountlinking/SessionTests.java index 8938c2700..56497c44c 100644 --- a/src/test/java/io/supertokens/test/accountlinking/SessionTests.java +++ b/src/test/java/io/supertokens/test/accountlinking/SessionTests.java @@ -89,7 +89,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -109,7 +110,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -129,7 +131,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -149,7 +152,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } diff --git a/src/test/java/io/supertokens/test/accountlinking/api/CreatePrimaryUserAPITest.java b/src/test/java/io/supertokens/test/accountlinking/api/CreatePrimaryUserAPITest.java index ce4dd6010..e10802c4b 100644 --- a/src/test/java/io/supertokens/test/accountlinking/api/CreatePrimaryUserAPITest.java +++ b/src/test/java/io/supertokens/test/accountlinking/api/CreatePrimaryUserAPITest.java @@ -452,7 +452,8 @@ public void createPrimaryUserInTenantWithAnotherStorage() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); diff --git a/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java b/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java index c2e58abfd..a3f7fceb8 100644 --- a/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java @@ -122,6 +122,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); @@ -142,6 +143,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); @@ -162,6 +164,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java b/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java index 0e7f5e8d5..1654c3960 100644 --- a/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java +++ b/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java @@ -120,6 +120,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); @@ -140,6 +141,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); @@ -160,6 +162,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/dashboard/apis/MultitenantAPITest.java b/src/test/java/io/supertokens/test/dashboard/apis/MultitenantAPITest.java index a8dab3316..79b57306c 100644 --- a/src/test/java/io/supertokens/test/dashboard/apis/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/dashboard/apis/MultitenantAPITest.java @@ -109,6 +109,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); @@ -129,6 +130,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); @@ -149,6 +151,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false),null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java b/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java index b9f9387bc..a8ad869ca 100644 --- a/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java +++ b/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java @@ -936,6 +936,7 @@ public void updateEmailSucceedsIfEmailUsedByOtherPrimaryUserInDifferentTenantWhi Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null), new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", @@ -973,6 +974,7 @@ public void updateEmailFailsIfEmailUsedByOtherPrimaryUserInDifferentTenant() Multitenancy.addNewOrUpdateAppOrTenant(process.main, new TenantIdentifier(null, null, null), new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), + new TotpConfig(false), null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", diff --git a/src/test/java/io/supertokens/test/emailpassword/MultitenantEmailPasswordTest.java b/src/test/java/io/supertokens/test/emailpassword/MultitenantEmailPasswordTest.java index 80a6fbfe1..6ed9fdeaf 100644 --- a/src/test/java/io/supertokens/test/emailpassword/MultitenantEmailPasswordTest.java +++ b/src/test/java/io/supertokens/test/emailpassword/MultitenantEmailPasswordTest.java @@ -84,6 +84,7 @@ private void createTenants(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -104,6 +105,7 @@ private void createTenants(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -124,6 +126,7 @@ private void createTenants(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/emailpassword/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/emailpassword/api/MultitenantAPITest.java index cc4ff6fdf..2bd9df73d 100644 --- a/src/test/java/io/supertokens/test/emailpassword/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/emailpassword/api/MultitenantAPITest.java @@ -117,6 +117,7 @@ private void createTenants(Boolean includeHashingKey) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -141,6 +142,7 @@ private void createTenants(Boolean includeHashingKey) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -165,6 +167,7 @@ private void createTenants(Boolean includeHashingKey) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/emailverification/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/emailverification/api/MultitenantAPITest.java index 2fc093038..a07c7e7f6 100644 --- a/src/test/java/io/supertokens/test/emailverification/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/emailverification/api/MultitenantAPITest.java @@ -105,6 +105,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -125,6 +126,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -145,6 +147,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java index 4203b8778..e1aa2e9bf 100644 --- a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java +++ b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java @@ -105,7 +105,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -113,7 +114,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); TenantIdentifierWithStorage tWithStorage = t.withStorage( @@ -145,7 +147,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -153,7 +156,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); UserIdMapping.assertThatUserIdIsNotBeingUsedInNonAuthRecipes(tWithStorage.toAppIdentifierWithStorage(), @@ -202,7 +206,8 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -210,7 +215,8 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); TenantIdentifierWithStorage appWithStorage = app.withStorage( @@ -275,7 +281,8 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -283,7 +290,8 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); TenantIdentifierWithStorage appWithStorage = app.withStorage( diff --git a/src/test/java/io/supertokens/test/multitenant/ConfigTest.java b/src/test/java/io/supertokens/test/multitenant/ConfigTest.java index 2885d4318..fa9a5f7c2 100644 --- a/src/test/java/io/supertokens/test/multitenant/ConfigTest.java +++ b/src/test/java/io/supertokens/test/multitenant/ConfigTest.java @@ -157,7 +157,8 @@ public void mergingTenantWithBaseConfigWorks() new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); Assert.assertEquals(Config.getConfig(process.getProcess()).getRefreshTokenValidity(), (long) 144001 * 60 * 1000); @@ -209,7 +210,8 @@ public void mergingTenantWithBaseConfigWithInvalidConfigThrowsErrorWorks() new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); fail(); } catch (InvalidConfigException e) { assert (e.getMessage() @@ -245,7 +247,8 @@ public void mergingTenantWithBaseConfigWithConflictingConfigsThrowsError() new TenantConfig(new TenantIdentifier(null, null, "abc"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); fail(); } catch (InvalidConfigException e) { assert (e.getMessage() @@ -295,7 +298,8 @@ public void mergingDifferentUserPoolTenantWithBaseConfigWithConflictingConfigsSh new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); } @@ -344,7 +348,8 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() tenants[0] = new TenantConfig(new TenantIdentifier("c1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -355,7 +360,8 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() tenants[1] = new TenantConfig(new TenantIdentifier("c1", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -364,7 +370,8 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() tenants[2] = new TenantConfig(new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -373,7 +380,8 @@ public void testDifferentWaysToGetConfigBasedOnConnectionURIAndTenantId() tenants[3] = new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } Config.loadAllTenantConfig(process.getProcess(), tenants, new ArrayList<>()); @@ -439,7 +447,8 @@ public void testMappingSameUserPoolToDifferentConnectionURIThrowsError() tenants[0] = new TenantConfig(new TenantIdentifier("c1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -450,7 +459,8 @@ public void testMappingSameUserPoolToDifferentConnectionURIThrowsError() tenants[1] = new TenantConfig(new TenantIdentifier("c2", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } try { @@ -490,7 +500,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -502,7 +513,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -514,7 +526,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -526,7 +539,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -538,7 +552,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -550,7 +565,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -567,7 +583,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -579,7 +596,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -591,7 +609,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -603,7 +622,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -615,7 +635,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -627,7 +648,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -639,7 +661,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -685,7 +708,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -702,7 +726,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -714,7 +739,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -731,7 +757,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); @@ -743,7 +770,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -760,7 +788,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -777,7 +806,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -794,7 +824,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -811,7 +842,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -828,7 +860,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -845,7 +878,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -862,7 +896,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -879,7 +914,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -896,7 +932,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -936,7 +973,8 @@ public void testUpdationOfDefaultTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -974,7 +1012,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); } @@ -992,7 +1031,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); fail(); @@ -1010,7 +1050,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -1025,7 +1066,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); } @@ -1042,7 +1084,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); } @@ -1118,7 +1161,8 @@ public void testConfigNormalisation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1138,7 +1182,8 @@ public void testConfigNormalisation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig2 = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1176,7 +1221,8 @@ public void testTenantConfigIsNormalisedFromCUD1() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1194,7 +1240,8 @@ public void testTenantConfigIsNormalisedFromCUD1() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1236,7 +1283,8 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1254,7 +1302,8 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1272,7 +1321,8 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1305,7 +1355,8 @@ public void testInvalidConfigWhileCreatingNewTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); fail(); } catch (InvalidConfigException e) { @@ -1338,7 +1389,8 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1353,7 +1405,8 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1373,7 +1426,8 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Config configAfter = Config.getInstance(t1, process.getProcess()); @@ -1408,14 +1462,16 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( t1, new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1430,14 +1486,16 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false);Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( t1, new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig - ), false); + new TotpConfig(false), + null, null, coreConfig + ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1456,7 +1514,8 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Config configAfter = Config.getInstance(t1, process.getProcess()); @@ -1490,7 +1549,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1504,7 +1564,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1523,7 +1584,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Storage storageLayerAfter = StorageLayer.getStorage(t1, process.getProcess()); @@ -1543,7 +1605,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Storage storageLayerAfter = StorageLayer.getStorage(t1, process.getProcess()); @@ -1577,7 +1640,8 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1592,7 +1656,8 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1611,7 +1676,8 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); FeatureFlag featureFlagAfter = FeatureFlag.getInstance(process.getProcess(), t1); @@ -1645,7 +1711,8 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1663,7 +1730,8 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1692,7 +1760,8 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); AccessTokenSigningKey accessTokenSigningKeyAfter = AccessTokenSigningKey.getInstance(t1, process.getProcess()); @@ -1734,7 +1803,8 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); // Now load a new set of configs @@ -1753,28 +1823,32 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - config1 + new TotpConfig(false), + null, null, config1 ), new TenantConfig( new TenantIdentifier(null, "a2", null), new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - config2 + new TotpConfig(false), + null, null, config2 ), new TenantConfig( new TenantIdentifier(null, "a2", "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config3 + new TotpConfig(false), + null, null, config3 ), new TenantConfig( new TenantIdentifier(null, "a1", null), new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config4 + new TotpConfig(false), + null, null, config4 ), }; Config.loadAllTenantConfig(process.getProcess(), tenantConfigs); @@ -1820,7 +1894,8 @@ public void testThatMistypedConfigThrowsError() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - mistypedConfig + new TotpConfig(false), + null, null, mistypedConfig ), false); fail(); } catch (InvalidConfigException e) { @@ -1873,7 +1948,8 @@ public void testCoreSpecificConfigIsNotAllowedForNewTenants() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); fail(); } catch (InvalidConfigException e) { @@ -1962,7 +2038,8 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); fail(); } catch (InvalidConfigException e) { @@ -2025,7 +2102,8 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); JsonObject config2 = new JsonObject(); @@ -2046,7 +2124,8 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config2 + new TotpConfig(false), + null, null, config2 ), false); fail(); } catch (InvalidConfigException e) { diff --git a/src/test/java/io/supertokens/test/multitenant/LoadTest.java b/src/test/java/io/supertokens/test/multitenant/LoadTest.java index fd321e9f6..b691cde88 100644 --- a/src/test/java/io/supertokens/test/multitenant/LoadTest.java +++ b/src/test/java/io/supertokens/test/multitenant/LoadTest.java @@ -75,7 +75,8 @@ public void testCreating100TenantsAndCheckOnlyOneInstanceOfStorageLayerIsCreated new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - config); + new TotpConfig(false), + null, null, config); try { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantIdentifier(null, null, null), tenants[insideLoop]); diff --git a/src/test/java/io/supertokens/test/multitenant/LogTest.java b/src/test/java/io/supertokens/test/multitenant/LogTest.java index 80425ce51..3f0c538b3 100644 --- a/src/test/java/io/supertokens/test/multitenant/LogTest.java +++ b/src/test/java/io/supertokens/test/multitenant/LogTest.java @@ -19,8 +19,6 @@ import com.google.gson.JsonObject; import io.supertokens.Main; import io.supertokens.ProcessState; -import io.supertokens.cliOptions.CLIOptions; -import io.supertokens.config.Config; import io.supertokens.featureflag.EE_FEATURES; import io.supertokens.featureflag.FeatureFlagTestContent; import io.supertokens.multitenancy.Multitenancy; @@ -82,39 +80,45 @@ public void testLogThatEachLineIsUniqueOnStartup() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject()), false); + new TotpConfig(false), + null, null, new JsonObject()), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, "a1", "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject()), false); + new TotpConfig(false), + null, null, new JsonObject()), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, "a1", "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject()), false); + new TotpConfig(false), + null, null, new JsonObject()), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, "a2", null), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject()), false); + new TotpConfig(false), + null, null, new JsonObject()), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, "a2", "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject()), false); + new TotpConfig(false), + null, null, new JsonObject()), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, "a2", "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject()), false); + new TotpConfig(false), + null, null, new JsonObject()), false); assertEquals(7, Multitenancy.getAllTenants(process.getProcess()).length); diff --git a/src/test/java/io/supertokens/test/multitenant/RandomConfigTest.java b/src/test/java/io/supertokens/test/multitenant/RandomConfigTest.java index 678093185..4c8dbdeb6 100644 --- a/src/test/java/io/supertokens/test/multitenant/RandomConfigTest.java +++ b/src/test/java/io/supertokens/test/multitenant/RandomConfigTest.java @@ -72,7 +72,7 @@ public void randomlyTestLoadConfig() FeatureFlagTestContent.getInstance(process.getProcess()) .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY}); process.startProcess(); - assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); + assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED, 1000000)); if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { return; diff --git a/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java b/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java index c222b64c1..f2f8f1227 100644 --- a/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java +++ b/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java @@ -19,7 +19,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.supertokens.ProcessState; -import io.supertokens.config.Config; import io.supertokens.featureflag.EE_FEATURES; import io.supertokens.featureflag.FeatureFlagTestContent; import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; @@ -37,7 +36,6 @@ import io.supertokens.test.TestingProcessManager; import io.supertokens.test.Utils; import io.supertokens.test.httpRequest.HttpRequestForTesting; -import io.supertokens.test.multitenant.api.TestMultitenancyAPIHelper; import io.supertokens.thirdparty.InvalidProviderConfigException; import io.supertokens.webserver.Webserver; import io.supertokens.webserver.WebserverAPI; @@ -145,11 +143,13 @@ public void basicTestingWithDifferentAPIKey() Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), false); + new TotpConfig(false), + null, null, tenantConfig), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig(new TenantIdentifier("127.0.0.1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), false); + new TotpConfig(false), + null, null, tenant2Config), false); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -249,7 +249,8 @@ public void basicTestingWithDifferentAPIKeyAndTenantId() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -257,7 +258,8 @@ public void basicTestingWithDifferentAPIKeyAndTenantId() new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -265,7 +267,8 @@ public void basicTestingWithDifferentAPIKeyAndTenantId() new TenantConfig(new TenantIdentifier("127.0.0.1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -273,7 +276,8 @@ public void basicTestingWithDifferentAPIKeyAndTenantId() new TenantConfig(new TenantIdentifier("127.0.0.1", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); diff --git a/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java b/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java index 545748c6d..97ca78fc7 100644 --- a/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java +++ b/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java @@ -118,7 +118,8 @@ public void keysAreGeneratedForAllUserPoolIds() new TenantConfig(new TenantIdentifier("c1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig)}; + new TotpConfig(false), + null, null, tenantConfig)}; for (TenantConfig config : tenants) { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantIdentifier(null, null, null), @@ -189,11 +190,13 @@ public void signingKeyClassesAreThereForAllTenants() new TenantConfig(new TenantIdentifier("c1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), new TenantConfig(new TenantIdentifier("c2", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - tenantConfig2)}; + new TotpConfig(false), + null, null, tenantConfig2)}; for (TenantConfig config : tenants) { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantIdentifier(null, null, null), diff --git a/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java b/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java index b3e8cb46f..b78f69997 100644 --- a/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java +++ b/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java @@ -183,7 +183,8 @@ public void testUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -288,7 +289,8 @@ public void testUpdationOfDefaultTenantWithNullClientType() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -391,7 +393,8 @@ public void testForNullsInUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -485,7 +488,8 @@ public void testForNullClientsListInUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -552,7 +556,8 @@ public void testForNullProvidersListInUpdationOfDefaultTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -636,7 +641,8 @@ public void testCreateTenantPersistsDataCorrectly() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -752,7 +758,8 @@ public void testCreationOfDuplicationTenantThrowsDuplicateTenantException() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); try { @@ -790,7 +797,8 @@ public void testCreationOfDuplicationTenantThrowsDuplicateTenantException() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateTenantException e) { @@ -900,11 +908,12 @@ public void testOverwriteTenantOfNonExistantTenantThrowsTenantOrAppNotFoundExcep ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (TenantOrAppNotFoundException e) { - // pass + // pass0-89uuuuuui8j= } process.kill(); @@ -1003,7 +1012,8 @@ public void testCreateTenantWithDuplicateProviderIdThrowsException() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateThirdPartyIdException e) { @@ -1079,7 +1089,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderIdThrowsDuplicateTenan ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); } catch (DuplicateTenantException e) { fail(); @@ -1148,7 +1159,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderIdThrowsDuplicateTenan ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateTenantException e) { @@ -1224,7 +1236,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderClientTypeThrowsDuplic ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); } catch (DuplicateTenantException e) { fail(); @@ -1273,7 +1286,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderClientTypeThrowsDuplic ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateTenantException e) { @@ -1385,7 +1399,8 @@ public void testCreateTenantWithDuplicateClientTypeThrowsException() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateClientTypeException e) { @@ -1489,7 +1504,8 @@ public void testOverwriteTenantWithDuplicateProviderIdThrowsException() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateThirdPartyIdException e) { @@ -1601,7 +1617,8 @@ public void testOverwriteTenantWithDuplicateClientTypeThrowsException() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateClientTypeException e) { @@ -1690,7 +1707,8 @@ public void testOverwriteTenantForRaceConditions() ) }), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); break; } catch (Exception e) { @@ -1774,28 +1792,32 @@ public void testThatStoragePointingToSameDbSharesThInstance() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config1 + new TotpConfig(false), + null, null, config1 ), new TenantConfig( new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config1 + new TotpConfig(false), + null, null, config1 ), new TenantConfig( new TenantIdentifier(null, "a1", null), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config2 + new TotpConfig(false), + null, null, config2 ), new TenantConfig( new TenantIdentifier(null, "a1", "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config2 + new TotpConfig(false), + null, null, config2 ) }); @@ -1852,7 +1874,8 @@ public void testThatStorageIsClosedAfterTenantDeletion() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); Storage storage = StorageLayer.getStorage(new TenantIdentifier(null, null, "t1"), process.getProcess()); @@ -1898,14 +1921,16 @@ public void testThatStorageIsClosedOnlyWhenNoMoreTenantsArePointingToIt() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); Storage storage = StorageLayer.getStorage(new TenantIdentifier(null, null, "t1"), process.getProcess()); @@ -1956,14 +1981,16 @@ public void testStorageDoesNotLoadAgainAfterTenantDeletionWhenRefreshedFromDb() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); @@ -2036,7 +2063,8 @@ public void testThatOriginalStorageIsNotClosedIfTheStorageForATenantChangesAndTh new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Storage storage = StorageLayer.getBaseStorage(process.getProcess()); @@ -2051,7 +2079,8 @@ public void testThatOriginalStorageIsNotClosedIfTheStorageForATenantChangesAndTh new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ), false); storage = StorageLayer.getBaseStorage(process.getProcess()); diff --git a/src/test/java/io/supertokens/test/multitenant/TestAppData.java b/src/test/java/io/supertokens/test/multitenant/TestAppData.java index cf69c38f9..988b93185 100644 --- a/src/test/java/io/supertokens/test/multitenant/TestAppData.java +++ b/src/test/java/io/supertokens/test/multitenant/TestAppData.java @@ -26,7 +26,6 @@ import io.supertokens.emailverification.EmailVerification; import io.supertokens.featureflag.EE_FEATURES; import io.supertokens.featureflag.FeatureFlagTestContent; -import io.supertokens.mfa.Mfa; import io.supertokens.multitenancy.Multitenancy; import io.supertokens.passwordless.Passwordless; import io.supertokens.pluginInterface.STORAGE_TYPE; @@ -104,7 +103,7 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { return; } - String[] tablesToIgnore = new String[]{"tenant_thirdparty_provider_clients", "tenant_thirdparty_providers"}; + String[] tablesToIgnore = new String[]{"tenant_thirdparty_provider_clients", "tenant_thirdparty_providers", "tenant_first_factors", "tenant_default_required_factor_ids"}; TenantIdentifier app = new TenantIdentifier(null, "a1", null); @@ -113,7 +112,8 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); TenantIdentifierWithStorage appWithStorage = app.withStorage( diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestApp.java b/src/test/java/io/supertokens/test/multitenant/api/TestApp.java index fee7b1ad8..127a82143 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestApp.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestApp.java @@ -16,6 +16,7 @@ package io.supertokens.test.multitenant.api; +import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.supertokens.ProcessState; @@ -50,6 +51,7 @@ import java.io.IOException; import java.rmi.ServerException; +import java.util.Set; import static org.junit.Assert.*; @@ -507,4 +509,305 @@ public void testDefaultRecipesEnabledWhileCreatingApp() throws Exception { assertTrue(tenant.get("thirdParty").getAsJsonObject().get("enabled").getAsBoolean()); assertTrue(tenant.get("passwordless").getAsJsonObject().get("enabled").getAsBoolean()); } + + @Test + public void testTotpEnabledBoolean() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + true, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + false, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + } + + @Test + public void testFirstFactorsArray() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("firstFactors")); + + // builtin firstFactor + String[] firstFactors = new String[]{"otp-phone"}; + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, true, new String[]{"otp-phone"}, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + // custom factors + firstFactors = new String[]{"biometric"}; + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, true, firstFactors, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + // test both + firstFactors = new String[]{"otp-phone", "emailpassword", "biometric", "custom"}; + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, true, firstFactors, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(Set.of(firstFactors), Set.of(new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class))); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, true, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("firstFactors")); + } + + @Test + public void testDefaultRequiredFactorIdsArray() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("defaultRequiredFactorIds")); + + // builtin firstFactor + String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, true, new String[]{"otp-phone"}, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + // custom factors + defaultRequiredFactorIds = new String[]{"biometric"}; + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, true, defaultRequiredFactorIds, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + // test both + defaultRequiredFactorIds = new String[]{"otp-phone", "emailpassword", "biometric", "custom"}; + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, true, defaultRequiredFactorIds, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(Set.of(defaultRequiredFactorIds), Set.of(new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class))); + + response = TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, true, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("defaultRequiredFactorIds")); + } + + @Test + public void testDuplicateValuesInFirstFactorsAndDefaultRequiredFactorIds() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + String[] factors = new String[]{"duplicate", "emailpassword", "duplicate", "custom"}; + try { + TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, true, factors, false, null, + config, SemVer.v4_1); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertEquals("Http error. Status Code: 400. Message: firstFactors input should not contain duplicate values", e.getMessage()); + } + + try { + TestMultitenancyAPIHelper.createApp( + process.getProcess(), + new TenantIdentifier(null, null, null), + "a1", null, null, null, + null, false, null, true, factors, + config, SemVer.v4_1); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertEquals("Http error. Status Code: 400. Message: defaultRequiredFactorIds input should not contain duplicate values", e.getMessage()); + } + + } + } diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java b/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java index 8ca0855f1..debbb2948 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java @@ -16,6 +16,7 @@ package io.supertokens.test.multitenant.api; +import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.supertokens.ProcessState; @@ -35,6 +36,7 @@ import io.supertokens.test.httpRequest.HttpRequestForTesting; import io.supertokens.test.httpRequest.HttpResponseException; import io.supertokens.thirdparty.InvalidProviderConfigException; +import io.supertokens.utils.SemVer; import io.supertokens.webserver.Webserver; import io.supertokens.webserver.WebserverAPI; import jakarta.servlet.ServletException; @@ -46,6 +48,7 @@ import org.junit.Test; import java.io.IOException; +import java.util.Set; import static org.junit.Assert.*; @@ -487,4 +490,304 @@ public void testDefaultRecipesEnabledWhileCreatingCUD() throws Exception { assertTrue(tenant.get("thirdParty").getAsJsonObject().get("enabled").getAsBoolean()); assertTrue(tenant.get("passwordless").getAsJsonObject().get("enabled").getAsBoolean()); } + + @Test + public void testTotpEnabledBoolean() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + true, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + false, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + } + + @Test + public void testFirstFactorsArray() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("firstFactors")); + + // builtin firstFactor + String[] firstFactors = new String[]{"otp-phone"}; + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, true, new String[]{"otp-phone"}, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + // custom factors + firstFactors = new String[]{"biometric"}; + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, true, firstFactors, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + // test both + firstFactors = new String[]{"otp-phone", "emailpassword", "biometric", "custom"}; + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, true, firstFactors, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(Set.of(firstFactors), Set.of(new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class))); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, true, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("firstFactors")); + } + + @Test + public void testDefaultRequiredFactorIdsArray() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("defaultRequiredFactorIds")); + + // builtin firstFactor + String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, true, new String[]{"otp-phone"}, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + // custom factors + defaultRequiredFactorIds = new String[]{"biometric"}; + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, true, defaultRequiredFactorIds, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + // test both + defaultRequiredFactorIds = new String[]{"otp-phone", "emailpassword", "biometric", "custom"}; + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, true, defaultRequiredFactorIds, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(Set.of(defaultRequiredFactorIds), Set.of(new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class))); + + response = TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, true, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("defaultRequiredFactorIds")); + } + + @Test + public void testDuplicateValuesInFirstFactorsAndDefaultRequiredFactorIds() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + String[] factors = new String[]{"duplicate", "emailpassword", "duplicate", "custom"}; + try { + TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, true, factors, false, null, + config, SemVer.v4_1); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertEquals("Http error. Status Code: 400. Message: firstFactors input should not contain duplicate values", e.getMessage()); + } + + try { + TestMultitenancyAPIHelper.createConnectionUriDomain( + process.getProcess(), + new TenantIdentifier(null, null, null), + "127.0.0.1", null, null, null, + null, false, null, true, factors, + config, SemVer.v4_1); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertEquals("Http error. Status Code: 400. Message: defaultRequiredFactorIds input should not contain duplicate values", e.getMessage()); + } + + } } diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java b/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java index 119672092..47cd8dd56 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java @@ -38,6 +38,17 @@ public class TestMultitenancyAPIHelper { public static JsonObject createConnectionUriDomain(Main main, TenantIdentifier sourceTenant, String connectionUriDomain, Boolean emailPasswordEnabled, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, JsonObject coreConfig) throws HttpResponseException, IOException { + return createConnectionUriDomain(main, sourceTenant, connectionUriDomain, emailPasswordEnabled, thirdPartyEnabled, + passwordlessEnabled, false, false, null, false, null, coreConfig, SemVer.v3_0); + + } + + public static JsonObject createConnectionUriDomain(Main main, TenantIdentifier sourceTenant, String connectionUriDomain, Boolean emailPasswordEnabled, + Boolean thirdPartyEnabled, Boolean passwordlessEnabled, + Boolean totpEnabled, + boolean setFirstFactors, String[] firstFactors, + boolean setDefaultRequiredFactorIds, String[] defaultRequiredFactorIds, + JsonObject coreConfig, SemVer version) throws HttpResponseException, IOException { JsonObject requestBody = new JsonObject(); if (connectionUriDomain != null) { requestBody.addProperty("connectionUriDomain", connectionUriDomain); @@ -51,12 +62,22 @@ public static JsonObject createConnectionUriDomain(Main main, TenantIdentifier s if (passwordlessEnabled != null) { requestBody.addProperty("passwordlessEnabled", passwordlessEnabled); } + if (totpEnabled != null) { + requestBody.addProperty("totpEnabled", totpEnabled); + } + if (setFirstFactors || firstFactors != null) { + requestBody.add("firstFactors", new Gson().toJsonTree(firstFactors)); + } + if (setDefaultRequiredFactorIds || defaultRequiredFactorIds != null) { + requestBody.add("defaultRequiredFactorIds", new Gson().toJsonTree(defaultRequiredFactorIds)); + } + requestBody.add("coreConfig", coreConfig); JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(main, "", HttpRequestForTesting.getMultitenantUrl(sourceTenant, "/recipe/multitenancy/connectionuridomain"), requestBody, 1000, 2500, null, - SemVer.v3_0.get(), "multitenancy"); + version.get(), "multitenancy"); assertEquals("OK", response.getAsJsonPrimitive("status").getAsString()); @@ -92,6 +113,16 @@ public static JsonObject deleteConnectionUriDomain(TenantIdentifier sourceTenant public static JsonObject createApp(Main main, TenantIdentifier sourceTenant, String appId, Boolean emailPasswordEnabled, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, JsonObject coreConfig) throws HttpResponseException, IOException { + return createApp(main, sourceTenant, appId, emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, + false, false, null, false, null, coreConfig, SemVer.v3_0); + } + + public static JsonObject createApp(Main main, TenantIdentifier sourceTenant, String appId, Boolean emailPasswordEnabled, + Boolean thirdPartyEnabled, Boolean passwordlessEnabled, + Boolean totpEnabled, + boolean setFirstFactors, String[] firstFactors, + boolean setDefaultRequiredFactorIds, String[] defaultRequiredFactorIds, + JsonObject coreConfig, SemVer version) throws HttpResponseException, IOException { JsonObject requestBody = new JsonObject(); requestBody.addProperty("appId", appId); if (emailPasswordEnabled != null) { @@ -103,12 +134,21 @@ public static JsonObject createApp(Main main, TenantIdentifier sourceTenant, Str if (passwordlessEnabled != null) { requestBody.addProperty("passwordlessEnabled", passwordlessEnabled); } + if (totpEnabled != null) { + requestBody.addProperty("totpEnabled", totpEnabled); + } + if (setFirstFactors || firstFactors != null) { + requestBody.add("firstFactors", new Gson().toJsonTree(firstFactors)); + } + if (setDefaultRequiredFactorIds || defaultRequiredFactorIds != null) { + requestBody.add("defaultRequiredFactorIds", new Gson().toJsonTree(defaultRequiredFactorIds)); + } requestBody.add("coreConfig", coreConfig); JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(main, "", HttpRequestForTesting.getMultitenantUrl(sourceTenant, "/recipe/multitenancy/app"), requestBody, 1000, 2500, null, - SemVer.v3_0.get(), "multitenancy"); + version.get(), "multitenancy"); assertEquals("OK", response.getAsJsonPrimitive("status").getAsString()); return response; @@ -142,6 +182,16 @@ public static JsonObject deleteApp(TenantIdentifier sourceTenant, String appId, public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, String tenantId, Boolean emailPasswordEnabled, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, JsonObject coreConfig) throws HttpResponseException, IOException { + return createTenant(main, sourceTenant, tenantId, emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, + null, false, null, false, null, coreConfig, SemVer.v3_0); + } + + public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, String tenantId, Boolean emailPasswordEnabled, + Boolean thirdPartyEnabled, Boolean passwordlessEnabled, + Boolean totpEnabled, + boolean setFirstFactors, String[] firstFactors, + boolean setDefaultRequiredFactorIds, String[] defaultRequiredFactorIds, + JsonObject coreConfig, SemVer version) throws HttpResponseException, IOException { JsonObject requestBody = new JsonObject(); requestBody.addProperty("tenantId", tenantId); if (emailPasswordEnabled != null) { @@ -153,12 +203,22 @@ public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, if (passwordlessEnabled != null) { requestBody.addProperty("passwordlessEnabled", passwordlessEnabled); } + if (totpEnabled != null) { + requestBody.addProperty("totpEnabled", totpEnabled); + } + if (setFirstFactors || firstFactors != null) { + requestBody.add("firstFactors", new Gson().toJsonTree(firstFactors)); + } + if (setDefaultRequiredFactorIds || defaultRequiredFactorIds != null) { + requestBody.add("defaultRequiredFactorIds", new Gson().toJsonTree(defaultRequiredFactorIds)); + } + requestBody.add("coreConfig", coreConfig); JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(main, "", HttpRequestForTesting.getMultitenantUrl(sourceTenant, "/recipe/multitenancy/tenant"), requestBody, 1000, 2500, null, - SemVer.v3_0.get(), "multitenancy"); + version.get(), "multitenancy"); assertEquals("OK", response.getAsJsonPrimitive("status").getAsString()); return response; @@ -191,11 +251,16 @@ public static JsonObject deleteTenant(TenantIdentifier sourceTenant, String tena public static JsonObject getTenant(TenantIdentifier tenantIdentifier, Main main) throws HttpResponseException, IOException { + return getTenant(tenantIdentifier, main, SemVer.v3_0); + } + + public static JsonObject getTenant(TenantIdentifier tenantIdentifier, Main main, SemVer version) + throws HttpResponseException, IOException { JsonObject response = HttpRequestForTesting.sendGETRequest(main, "", HttpRequestForTesting.getMultitenantUrl(tenantIdentifier, "/recipe/multitenancy/tenant"), null, 1000, 1000, null, - SemVer.v3_0.get(), "multitenancy"); + version.get(), "multitenancy"); assertEquals("OK", response.getAsJsonPrimitive("status").getAsString()); return response; diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestSkipValidationInCreateThirdParty.java b/src/test/java/io/supertokens/test/multitenant/api/TestSkipValidationInCreateThirdParty.java index d99ae5658..8aab40577 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestSkipValidationInCreateThirdParty.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestSkipValidationInCreateThirdParty.java @@ -68,7 +68,8 @@ public void testSkipValidation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); try { diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java index b03ebd71c..967300276 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java @@ -16,8 +16,7 @@ package io.supertokens.test.multitenant.api; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; +import com.google.gson.*; import io.supertokens.ProcessState; import io.supertokens.featureflag.EE_FEATURES; import io.supertokens.featureflag.FeatureFlagTestContent; @@ -35,6 +34,7 @@ import io.supertokens.test.httpRequest.HttpRequestForTesting; import io.supertokens.test.httpRequest.HttpResponseException; import io.supertokens.thirdparty.InvalidProviderConfigException; +import io.supertokens.utils.SemVer; import io.supertokens.webserver.Webserver; import io.supertokens.webserver.WebserverAPI; import jakarta.servlet.ServletException; @@ -46,6 +46,7 @@ import org.junit.Test; import java.io.IOException; +import java.util.Set; import static org.junit.Assert.*; @@ -346,4 +347,304 @@ public void testDefaultRecipesEnabledWhileCreatingTenant() throws Exception { assertFalse(tenant.get("thirdParty").getAsJsonObject().get("enabled").getAsBoolean()); assertFalse(tenant.get("passwordless").getAsJsonObject().get("enabled").getAsBoolean()); } + + @Test + public void testTotpEnabledBoolean() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + true, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + false, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + } + + @Test + public void testFirstFactorsArray() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("firstFactors")); + + // builtin firstFactor + String[] firstFactors = new String[]{"otp-phone"}; + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, true, new String[]{"otp-phone"}, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + // custom factors + firstFactors = new String[]{"biometric"}; + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, true, firstFactors, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + + // test both + firstFactors = new String[]{"otp-phone", "emailpassword", "biometric", "custom"}; + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, true, firstFactors, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(Set.of(firstFactors), Set.of(new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class))); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, true, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("firstFactors")); + } + + @Test + public void testDefaultRequiredFactorIdsArray() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + JsonObject response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + config); + + assertTrue(response.get("createdNew").getAsBoolean()); + + JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("defaultRequiredFactorIds")); + + // builtin firstFactor + String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, true, new String[]{"otp-phone"}, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, false, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + // custom factors + defaultRequiredFactorIds = new String[]{"biometric"}; + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, true, defaultRequiredFactorIds, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + + // test both + defaultRequiredFactorIds = new String[]{"otp-phone", "emailpassword", "biometric", "custom"}; + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, true, defaultRequiredFactorIds, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(Set.of(defaultRequiredFactorIds), Set.of(new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class))); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, true, null, + config, SemVer.v4_1); + assertFalse(response.get("createdNew").getAsBoolean()); + + tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), + process.getProcess(), SemVer.v4_1); + assertNull(tenant.get("defaultRequiredFactorIds")); + } + + @Test + public void testDuplicateValuesInFirstFactorsAndDefaultRequiredFactorIds() throws Exception { + if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + JsonObject config = new JsonObject(); + StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); + + String[] factors = new String[]{"duplicate", "emailpassword", "duplicate", "custom"}; + try { + TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, true, factors, false, null, + config, SemVer.v4_1); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertEquals("Http error. Status Code: 400. Message: firstFactors input should not contain duplicate values", e.getMessage()); + } + + try { + TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, false, null, true, factors, + config, SemVer.v4_1); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertEquals("Http error. Status Code: 400. Message: defaultRequiredFactorIds input should not contain duplicate values", e.getMessage()); + } + + } } diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java b/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java index 1b12646d4..d0857f13c 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java @@ -121,7 +121,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -141,7 +142,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } @@ -161,7 +163,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - config + new TotpConfig(false), + null, null, config ) ); } diff --git a/src/test/java/io/supertokens/test/multitenant/generator/GenerateTenantConfig.java b/src/test/java/io/supertokens/test/multitenant/generator/GenerateTenantConfig.java index a03cf0eaa..ed3b5e1cf 100644 --- a/src/test/java/io/supertokens/test/multitenant/generator/GenerateTenantConfig.java +++ b/src/test/java/io/supertokens/test/multitenant/generator/GenerateTenantConfig.java @@ -20,8 +20,51 @@ import io.supertokens.pluginInterface.multitenancy.*; import java.lang.reflect.InvocationTargetException; +import java.util.HashSet; +import java.util.Random; +import java.util.Set; public class GenerateTenantConfig { + private static final String[] FACTORS = new String[]{ + "emailpassword", + "thirdparty", + "otp-email", + "otp-phone", + "link-email", + "link-phone", + "totp", + "biometric", + "custom" + }; + + private static String[] selectRandomElements(String[] inputArray) { + Random random = new Random(); + int numElementsToSelect = random.nextInt(4); // Randomly select 0 to 3 elements + + // Ensure numElementsToSelect is within the bounds of the array + numElementsToSelect = Math.min(numElementsToSelect, inputArray.length); + + // Create a set to store unique indices + Set selectedIndices = new HashSet<>(); + + // Generate random indices and select the corresponding elements + while (selectedIndices.size() < numElementsToSelect) { + int randomIndex = random.nextInt(inputArray.length); + selectedIndices.add(randomIndex); + } + + // Create an array to hold the randomly selected elements + String[] selectedElements = new String[numElementsToSelect]; + + // Fill the array with the selected elements + int i = 0; + for (int index : selectedIndices) { + selectedElements[i++] = inputArray[index]; + } + + return selectedElements; + } + public static ConfigGenerator.GeneratedValueAndExpectation generate_tenantIdentifier() { // TODO: generate different appid and tenantid return new ConfigGenerator.GeneratedValueAndExpectation( @@ -48,6 +91,39 @@ public static ConfigGenerator.GeneratedValueAndExpectation generate_thirdPartyCo return ConfigGenerator.generate(ThirdPartyConfig.class); } + public static ConfigGenerator.GeneratedValueAndExpectation generate_totpConfig() + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException, + InstantiationException { + return ConfigGenerator.generate(TotpConfig.class); + } + + + public static ConfigGenerator.GeneratedValueAndExpectation generate_firstFactors() { + if (new Random().nextFloat() < 0.15) { + return new ConfigGenerator.GeneratedValueAndExpectation( + null, + new ConfigGenerator.Expectation("ok", null)); + } + + String[] factors = selectRandomElements(FACTORS); + return new ConfigGenerator.GeneratedValueAndExpectation( + factors, + new ConfigGenerator.Expectation("ok", factors)); + } + + public static ConfigGenerator.GeneratedValueAndExpectation generate_defaultRequiredFactorIds() { + if (new Random().nextFloat() < 0.15) { + return new ConfigGenerator.GeneratedValueAndExpectation( + null, + new ConfigGenerator.Expectation("ok", null)); + } + + String[] factors = selectRandomElements(FACTORS); + return new ConfigGenerator.GeneratedValueAndExpectation( + factors, + new ConfigGenerator.Expectation("ok", factors)); + } + public static ConfigGenerator.GeneratedValueAndExpectation generate_coreConfig() { // TODO: return new ConfigGenerator.GeneratedValueAndExpectation(new JsonObject(), new ConfigGenerator.Expectation("ok", new JsonObject())); diff --git a/src/test/java/io/supertokens/test/multitenant/generator/GenerateTotpConfig.java b/src/test/java/io/supertokens/test/multitenant/generator/GenerateTotpConfig.java new file mode 100644 index 000000000..2b11e3b29 --- /dev/null +++ b/src/test/java/io/supertokens/test/multitenant/generator/GenerateTotpConfig.java @@ -0,0 +1,28 @@ +/* + * 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.test.multitenant.generator; + +import java.util.Random; + +public class GenerateTotpConfig { + public static ConfigGenerator.GeneratedValueAndExpectation generate_enabled() { + boolean enabled = new Random().nextBoolean(); + return new ConfigGenerator.GeneratedValueAndExpectation( + enabled, + new ConfigGenerator.Expectation("ok", enabled)); + } +} diff --git a/src/test/java/io/supertokens/test/passwordless/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/passwordless/api/MultitenantAPITest.java index 632736e69..2c441d4b4 100644 --- a/src/test/java/io/supertokens/test/passwordless/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/passwordless/api/MultitenantAPITest.java @@ -108,6 +108,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -128,6 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -148,6 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/session/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/session/api/MultitenantAPITest.java index 51c860957..9cf848d16 100644 --- a/src/test/java/io/supertokens/test/session/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/session/api/MultitenantAPITest.java @@ -109,6 +109,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -129,6 +130,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -149,6 +151,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/thirdparty/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/thirdparty/api/MultitenantAPITest.java index 068ffb27a..2e2c5516a 100644 --- a/src/test/java/io/supertokens/test/thirdparty/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/thirdparty/api/MultitenantAPITest.java @@ -108,6 +108,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -128,6 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); @@ -148,6 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/totp/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/totp/api/MultitenantAPITest.java index 51c3549c2..42473700e 100644 --- a/src/test/java/io/supertokens/test/totp/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/MultitenantAPITest.java @@ -108,6 +108,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -128,6 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); @@ -148,6 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), null, null, config ) ); diff --git a/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java b/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java index 942653763..f6a78416b 100644 --- a/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java @@ -106,7 +106,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - config + new TotpConfig(false), + null, null, config ) ); } @@ -126,7 +127,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - config + new TotpConfig(false), + null, null, config ) ); } @@ -146,7 +148,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - config + new TotpConfig(false), + null, null, config ) ); } @@ -166,7 +169,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - config + new TotpConfig(false), + null, null, config ) ); }