From d66f0f6f1fcf64189e3e545afb5831480ddb1cd6 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 12 Oct 2023 14:03:10 +0530 Subject: [PATCH 01/16] fix: multitenancy changes --- .../ee/test/TestMultitenancyStats.java | 3 + .../multitenancy/TenantConfigSQLHelper.java | 2 + .../multitenancy/MultitenancyHelper.java | 5 +- .../io/supertokens/webserver/InputParser.java | 19 +++++ .../api/multitenancy/BaseCreateOrUpdate.java | 53 ++++++++++++- .../multitenancy/CreateOrUpdateAppAPI.java | 8 +- .../CreateOrUpdateConnectionUriDomainAPI.java | 8 +- .../CreateOrUpdateTenantOrGetTenantAPI.java | 10 ++- .../CreateOrUpdateThirdPartyConfigAPI.java | 2 + .../thirdparty/RemoveThirdPartyConfigAPI.java | 2 + .../io/supertokens/test/CDIVersionTest.java | 2 + .../java/io/supertokens/test/CronjobTest.java | 52 ++++++++++++ .../io/supertokens/test/FeatureFlagTest.java | 10 +++ .../io/supertokens/test/HelloAPITest.java | 9 +++ .../test/IpAllowDenyRegexTest.java | 4 + .../io/supertokens/test/PathRouterTest.java | 60 ++++++++++++++ .../test/SuperTokensSaaSSecretTest.java | 5 ++ .../test/TestHelloAPIRateLimiting.java | 3 + .../accountlinking/CreatePrimaryUserTest.java | 2 + .../test/accountlinking/LinkAccountsTest.java | 2 + .../test/accountlinking/MultitenantTest.java | 4 + .../test/accountlinking/SessionTests.java | 4 + .../api/CreatePrimaryUserAPITest.java | 1 + .../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 + .../supertokens/test/mfa/MfaStorageTest.java | 2 +- .../test/multitenant/AppTenantUserTest.java | 8 ++ .../test/multitenant/ConfigTest.java | 79 +++++++++++++++++++ .../test/multitenant/LoadTest.java | 1 + .../supertokens/test/multitenant/LogTest.java | 6 ++ .../test/multitenant/RandomConfigTest.java | 4 +- .../RequestConnectionUriDomainTest.java | 6 ++ .../test/multitenant/SigningKeysTest.java | 3 + .../test/multitenant/StorageLayerTest.java | 31 +++++++- .../test/multitenant/TestAppData.java | 1 + .../TestSkipValidationInCreateThirdParty.java | 1 + .../TestTenantIdIsNotPresentForOlderCDI.java | 3 + .../generator/GenerateMfaConfig.java | 71 +++++++++++++++++ .../generator/GenerateTenantConfig.java | 12 +++ .../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 | 4 + 50 files changed, 551 insertions(+), 11 deletions(-) create mode 100644 src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java create mode 100644 src/test/java/io/supertokens/test/multitenant/generator/GenerateTotpConfig.java 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..60aaeb496 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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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..9dd93bab6 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java @@ -53,6 +53,8 @@ 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")), + new TotpConfig(false), // TODO + new MfaConfig(new String[0], new String[0]), // TODO JsonUtils.stringToJsonObject(result.getString("core_config")) ); } catch (Exception e) { diff --git a/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java b/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java index a555cf05c..5bbfb4126 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(false), new MfaConfig(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,6 +96,8 @@ private TenantConfig[] getAllTenantsFromDb() throws StorageQueryException { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ) }; diff --git a/src/main/java/io/supertokens/webserver/InputParser.java b/src/main/java/io/supertokens/webserver/InputParser.java index ebf1e86ee..759031435 100644 --- a/src/main/java/io/supertokens/webserver/InputParser.java +++ b/src/main/java/io/supertokens/webserver/InputParser.java @@ -144,6 +144,25 @@ public static String parseStringOrThrowError(JsonObject element, String fieldNam } } + public static String[] parseStringArrayOrThrowError(JsonObject element, String fieldName, boolean nullable) + throws ServletException { + try { + if (nullable && element.get(fieldName) == null) { + return null; + } + JsonArray strings = element.get(fieldName).getAsJsonArray(); + String[] result = new String[strings.size()]; + for (int i = 0; i < strings.size(); i++) { + result[i] = strings.get(i).getAsString(); + } + + return result; + } catch (Exception e) { + throw new ServletException( + new WebserverAPI.BadRequestException("Field name '" + fieldName + "' is invalid in JSON input")); + } + } + public static String parseStringFromElementOrThrowError(JsonElement element, String parentFieldName, boolean nullable) throws ServletException { try { 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..a97eda87d 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,9 @@ 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, + String[] firstFactors, String[] defaultMFARequirements, + JsonObject coreConfig, HttpServletResponse resp) throws ServletException, IOException { TenantConfig tenantConfig = Multitenancy.getTenantInfo(main, @@ -63,6 +64,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ); } else { @@ -72,6 +75,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ); } @@ -84,6 +89,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new EmailPasswordConfig(emailPasswordEnabled), tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + tenantConfig.mfaConfig, tenantConfig.coreConfig ); } @@ -94,6 +101,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.emailPasswordConfig, new ThirdPartyConfig(thirdPartyEnabled, tenantConfig.thirdPartyConfig.providers), tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + tenantConfig.mfaConfig, tenantConfig.coreConfig ); } @@ -104,6 +113,44 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.emailPasswordConfig, tenantConfig.thirdPartyConfig, new PasswordlessConfig(passwordlessEnabled), + tenantConfig.totpConfig, + tenantConfig.mfaConfig, + tenantConfig.coreConfig + ); + } + + if (totpEnabled != null) { + tenantConfig = new TenantConfig( + tenantConfig.tenantIdentifier, + tenantConfig.emailPasswordConfig, + tenantConfig.thirdPartyConfig, + tenantConfig.passwordlessConfig, + new TotpConfig(totpEnabled), + tenantConfig.mfaConfig, + tenantConfig.coreConfig + ); + } + + if (firstFactors != null) { + tenantConfig = new TenantConfig( + tenantConfig.tenantIdentifier, + tenantConfig.emailPasswordConfig, + tenantConfig.thirdPartyConfig, + tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + new MfaConfig(firstFactors, tenantConfig.mfaConfig.defaultMFARequirements), + tenantConfig.coreConfig + ); + } + + if (defaultMFARequirements != null) { + tenantConfig = new TenantConfig( + tenantConfig.tenantIdentifier, + tenantConfig.emailPasswordConfig, + tenantConfig.thirdPartyConfig, + tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + new MfaConfig(tenantConfig.mfaConfig.firstFactors, defaultMFARequirements), tenantConfig.coreConfig ); } @@ -115,6 +162,8 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.emailPasswordConfig, tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + tenantConfig.mfaConfig, 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..425a0a161 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -54,6 +54,10 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean emailPasswordEnabled = InputParser.parseBooleanOrThrowError(input, "emailPasswordEnabled", true); Boolean thirdPartyEnabled = InputParser.parseBooleanOrThrowError(input, "thirdPartyEnabled", true); Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); + Boolean totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + String[] firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + String[] defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, + "defaultMFARequirements", true); JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); TenantIdentifier sourceTenantIdentifier; @@ -66,7 +70,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, firstFactors, defaultMFARequirements, + 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..566184b1d 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -52,6 +52,10 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean emailPasswordEnabled = InputParser.parseBooleanOrThrowError(input, "emailPasswordEnabled", true); Boolean thirdPartyEnabled = InputParser.parseBooleanOrThrowError(input, "thirdPartyEnabled", true); Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); + Boolean totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + String[] firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + String[] defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, + "defaultMFARequirements", true); JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); TenantIdentifier sourceTenantIdentifier; @@ -64,7 +68,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, firstFactors, defaultMFARequirements, + 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..42aeccccc 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -55,6 +55,11 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean emailPasswordEnabled = InputParser.parseBooleanOrThrowError(input, "emailPasswordEnabled", true); Boolean thirdPartyEnabled = InputParser.parseBooleanOrThrowError(input, "thirdPartyEnabled", true); Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); + Boolean totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + String[] firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + String[] defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, + "defaultMFARequirements", true); + JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); TenantIdentifier sourceTenantIdentifier; @@ -67,8 +72,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, firstFactors, defaultMFARequirements, + coreConfig, resp); } @Override 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..81ea90d3e 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,6 +114,8 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO tenantConfig.thirdPartyConfig.enabled, newProviders.toArray(new ThirdPartyConfig.Provider[0])), tenantConfig.passwordlessConfig, + tenantConfig.totpConfig, + tenantConfig.mfaConfig, tenantConfig.coreConfig); Multitenancy.addNewOrUpdateAppOrTenant(main, updatedConfig, shouldProtectProtectedConfig(req), 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..044d29331 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,6 +82,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I new ThirdPartyConfig( config.thirdPartyConfig.enabled, newProviders.toArray(new ThirdPartyConfig.Provider[0])), config.passwordlessConfig, + config.totpConfig, + config.mfaConfig, 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..bc985e60e 100644 --- a/src/test/java/io/supertokens/test/CDIVersionTest.java +++ b/src/test/java/io/supertokens/test/CDIVersionTest.java @@ -274,6 +274,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -281,6 +282,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); diff --git a/src/test/java/io/supertokens/test/CronjobTest.java b/src/test/java/io/supertokens/test/CronjobTest.java index 606ea745b..bac94ab0b 100644 --- a/src/test/java/io/supertokens/test/CronjobTest.java +++ b/src/test/java/io/supertokens/test/CronjobTest.java @@ -419,6 +419,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -426,6 +428,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -433,6 +437,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -440,6 +446,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); @@ -453,6 +461,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), config ), false); @@ -461,6 +471,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -468,6 +480,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -475,6 +489,8 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), config ), false); @@ -503,6 +519,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -510,6 +528,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -517,6 +537,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -524,6 +546,8 @@ public void testTargetTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); @@ -555,6 +579,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -562,6 +588,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -569,6 +597,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -576,6 +606,8 @@ public void testPerTenantCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); @@ -608,6 +640,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -615,6 +649,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -622,6 +658,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -629,6 +667,8 @@ public void testPerAppCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); @@ -665,6 +705,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -672,6 +714,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); JsonObject config = new JsonObject(); @@ -682,6 +726,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -689,6 +735,8 @@ public void testPerUserPoolCronTask() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), config ), false); @@ -728,6 +776,8 @@ public void testThatCoreAutomaticallySyncsToConfigChangesInDb() throws Exception new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() ), false); @@ -748,6 +798,8 @@ public void testThatCoreAutomaticallySyncsToConfigChangesInDb() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), + new MfaConfig(null, null), new JsonObject() )); diff --git a/src/test/java/io/supertokens/test/FeatureFlagTest.java b/src/test/java/io/supertokens/test/FeatureFlagTest.java index 8c249464b..82cfd05a5 100644 --- a/src/test/java/io/supertokens/test/FeatureFlagTest.java +++ b/src/test/java/io/supertokens/test/FeatureFlagTest.java @@ -401,6 +401,7 @@ public void testFeatureFlagWithMultitenancyFor500Tenants() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -462,6 +463,7 @@ public void testThatMultitenantStatsAreAccurate() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -489,6 +491,7 @@ public void testThatMultitenantStatsAreAccurate() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -561,6 +564,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -579,6 +583,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -606,6 +611,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -687,6 +693,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -706,6 +713,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -733,6 +741,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -805,6 +814,7 @@ public void testPaidFeaturesAreEnabledIfUsingInMemoryDatabase() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..cae41b3e5 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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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..c6066a7c3 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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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..db548e481 100644 --- a/src/test/java/io/supertokens/test/PathRouterTest.java +++ b/src/test/java/io/supertokens/test/PathRouterTest.java @@ -91,6 +91,7 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -102,6 +103,7 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -113,6 +115,7 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -263,6 +266,7 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -274,6 +278,7 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -285,6 +290,7 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -435,6 +441,7 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -446,6 +453,7 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -457,6 +465,7 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -617,6 +626,7 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -628,6 +638,7 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -639,6 +650,7 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -800,6 +812,7 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -811,6 +824,7 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -822,6 +836,7 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -980,6 +995,7 @@ public void withRecipeRouterTest() throws Exception { new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -990,6 +1006,7 @@ public void withRecipeRouterTest() throws Exception { new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -1322,6 +1339,7 @@ public void tenantNotFoundTest() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -1330,6 +1348,7 @@ public void tenantNotFoundTest() new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -1338,6 +1357,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenant2Config), false ); @@ -1346,6 +1366,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenant2Config), false ); @@ -1443,6 +1464,7 @@ public void tenantNotFoundTest2() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -1451,6 +1473,7 @@ public void tenantNotFoundTest2() new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -1459,6 +1482,7 @@ public void tenantNotFoundTest2() new TenantConfig(new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject()), false ); @@ -1560,10 +1584,12 @@ public void tenantNotFoundTest3() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig)}, new ArrayList<>()); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -1623,6 +1649,7 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1634,6 +1661,7 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1645,6 +1673,7 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1656,6 +1685,7 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1667,6 +1697,7 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1678,6 +1709,7 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1689,6 +1721,7 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1924,6 +1957,7 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1935,6 +1969,7 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1946,6 +1981,7 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1957,6 +1993,7 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1968,6 +2005,7 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1979,6 +2017,7 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -1990,6 +2029,7 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2209,6 +2249,7 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2220,6 +2261,7 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2231,6 +2273,7 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2242,6 +2285,7 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2253,6 +2297,7 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2264,6 +2309,7 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2275,6 +2321,7 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false @@ -2511,6 +2558,7 @@ public void tenantNotFoundWithAppIdTest() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -2519,6 +2567,7 @@ public void tenantNotFoundWithAppIdTest() new TenantConfig(new TenantIdentifier("localhost", "app1", null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -2527,6 +2576,7 @@ public void tenantNotFoundWithAppIdTest() new TenantConfig(new TenantIdentifier("localhost", "app1", "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -2535,6 +2585,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenant2Config), false ); @@ -2585,6 +2636,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenant2Config), false ); @@ -2593,6 +2645,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenant2Config), false ); @@ -2651,6 +2704,7 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -2659,6 +2713,7 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier("localhost", "app1", null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -2667,6 +2722,7 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier("localhost", "app1", "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -2675,6 +2731,7 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier(null, "app2", null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject()), false ); @@ -2683,6 +2740,7 @@ public void tenantNotFoundWithAppIdTest2() new TenantConfig(new TenantIdentifier(null, "app2", "t2"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject()), false ); @@ -2815,10 +2873,12 @@ public void tenantNotFoundWithAppIdTest3() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), new TenantConfig(new TenantIdentifier("localhost", "app1", "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig)}, new ArrayList<>()); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { diff --git a/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java b/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java index 1e565cec5..bed7173e3 100644 --- a/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java +++ b/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java @@ -358,6 +358,7 @@ public void gettingTenantShouldNotExposeSuperTokensSaaSSecret() new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject())); TenantConfig[] tenantConfigs = Multitenancy.getAllTenants(process.main); @@ -400,6 +401,7 @@ public void testThatTenantCannotSetSuperTokensSaasSecret() new TenantConfig(new TenantIdentifier(null, null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), j)); fail(); } catch (InvalidConfigException e) { @@ -463,6 +465,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), j), true); fail(); } catch (BadPermissionException e) { @@ -549,6 +552,7 @@ public void testThatTenantCannotGetProtectedConfigIfSuperTokensSaaSSecretIsSet() new TenantConfig(new TenantIdentifier(null, null, "t" + i), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), j)); { @@ -628,6 +632,7 @@ public void testLogContainsCorrectCud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); diff --git a/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java b/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java index 2a1e7f013..56daf54d4 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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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..36d564351 100644 --- a/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java @@ -422,6 +422,7 @@ 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 TotpConfig(false), new MfaConfig(null, null), new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", @@ -468,6 +469,7 @@ 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 TotpConfig(false), new MfaConfig(null, null), new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", diff --git a/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java b/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java index aab79a23a..1ef94dc17 100644 --- a/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java @@ -465,6 +465,7 @@ 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 TotpConfig(false), new MfaConfig(null, null), new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", @@ -518,6 +519,7 @@ 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 TotpConfig(false), new MfaConfig(null, null), new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", diff --git a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java index 438aea250..306907984 100644 --- a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java @@ -99,6 +99,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -119,6 +120,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -139,6 +141,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -159,6 +162,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..fdbf537da 100644 --- a/src/test/java/io/supertokens/test/accountlinking/SessionTests.java +++ b/src/test/java/io/supertokens/test/accountlinking/SessionTests.java @@ -89,6 +89,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -109,6 +110,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -129,6 +131,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -149,6 +152,7 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..6803c6613 100644 --- a/src/test/java/io/supertokens/test/accountlinking/api/CreatePrimaryUserAPITest.java +++ b/src/test/java/io/supertokens/test/accountlinking/api/CreatePrimaryUserAPITest.java @@ -452,6 +452,7 @@ public void createPrimaryUserInTenantWithAnotherStorage() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..0112eb45d 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), new MfaConfig(null, null), config ) ); @@ -142,6 +143,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -162,6 +164,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..12efc86db 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), new MfaConfig(null, null), config ) ); @@ -140,6 +141,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -160,6 +162,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..8e3f86612 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), new MfaConfig(null, null), config ) ); @@ -129,6 +130,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -149,6 +151,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..cb4dfd8a6 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), new MfaConfig(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), new MfaConfig(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..518cab796 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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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..db935ca1c 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), new MfaConfig(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), new MfaConfig(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), new MfaConfig(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..b10386548 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), new MfaConfig(null, null), config ) ); @@ -125,6 +126,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -145,6 +147,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); diff --git a/src/test/java/io/supertokens/test/mfa/MfaStorageTest.java b/src/test/java/io/supertokens/test/mfa/MfaStorageTest.java index 6af701819..d65d2d326 100644 --- a/src/test/java/io/supertokens/test/mfa/MfaStorageTest.java +++ b/src/test/java/io/supertokens/test/mfa/MfaStorageTest.java @@ -153,7 +153,7 @@ public void deleteUserFromTenantTest() throws Exception { TenantIdentifierWithStorage publicTenant = new TenantIdentifierWithStorage(null, null, null, result.storage); TenantIdentifierWithStorage privateTenant = new TenantIdentifierWithStorage(null, null, "t1", result.storage); - TenantConfig privateTenantConfig = new TenantConfig(privateTenant, new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new JsonObject()); + TenantConfig privateTenantConfig = new TenantConfig(privateTenant, new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), new MfaConfig(null, null), new JsonObject()); Multitenancy.addNewOrUpdateAppOrTenant( result.process.main, diff --git a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java index e1c7f9e0c..53d8458f7 100644 --- a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java +++ b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java @@ -105,6 +105,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -113,6 +114,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -145,6 +147,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -153,6 +156,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -202,6 +206,7 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -210,6 +215,7 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -275,6 +281,7 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -283,6 +290,7 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); diff --git a/src/test/java/io/supertokens/test/multitenant/ConfigTest.java b/src/test/java/io/supertokens/test/multitenant/ConfigTest.java index 2885d4318..64dd865ae 100644 --- a/src/test/java/io/supertokens/test/multitenant/ConfigTest.java +++ b/src/test/java/io/supertokens/test/multitenant/ConfigTest.java @@ -157,6 +157,7 @@ public void mergingTenantWithBaseConfigWorks() new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig)}, new ArrayList<>()); Assert.assertEquals(Config.getConfig(process.getProcess()).getRefreshTokenValidity(), @@ -209,6 +210,7 @@ public void mergingTenantWithBaseConfigWithInvalidConfigThrowsErrorWorks() new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig)}, new ArrayList<>()); fail(); } catch (InvalidConfigException e) { @@ -245,6 +247,7 @@ public void mergingTenantWithBaseConfigWithConflictingConfigsThrowsError() new TenantConfig(new TenantIdentifier(null, null, "abc"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig)}, new ArrayList<>()); fail(); } catch (InvalidConfigException e) { @@ -295,6 +298,7 @@ public void mergingDifferentUserPoolTenantWithBaseConfigWithConflictingConfigsSh new TenantConfig(new TenantIdentifier("abc", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig)}, new ArrayList<>()); } @@ -344,6 +348,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig); } @@ -355,6 +360,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig); } @@ -364,6 +370,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig); } @@ -373,6 +380,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig); } @@ -439,6 +447,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig); } @@ -450,6 +459,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig); } @@ -490,6 +500,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -502,6 +513,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -514,6 +526,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -526,6 +539,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -538,6 +552,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -550,6 +565,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -567,6 +583,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -579,6 +596,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -591,6 +609,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -603,6 +622,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -615,6 +635,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -627,6 +648,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -639,6 +661,7 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -685,6 +708,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -702,6 +726,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -714,6 +739,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -731,6 +757,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -743,6 +770,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -760,6 +788,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -777,6 +806,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -794,6 +824,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -811,6 +842,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -828,6 +860,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -845,6 +878,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -862,6 +896,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -879,6 +914,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -896,6 +932,7 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -936,6 +973,7 @@ public void testUpdationOfDefaultTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -974,6 +1012,7 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -992,6 +1031,7 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -1010,6 +1050,7 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ) ); @@ -1025,6 +1066,7 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -1042,6 +1084,7 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ) ); @@ -1118,6 +1161,7 @@ public void testConfigNormalisation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfigJson ), false); @@ -1138,6 +1182,7 @@ public void testConfigNormalisation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfigJson ), false); @@ -1176,6 +1221,7 @@ public void testTenantConfigIsNormalisedFromCUD1() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfigJson ), false); @@ -1194,6 +1240,7 @@ public void testTenantConfigIsNormalisedFromCUD1() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfigJson ), false); @@ -1236,6 +1283,7 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfigJson ), false); @@ -1254,6 +1302,7 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfigJson ), false); @@ -1272,6 +1321,7 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfigJson ), false); @@ -1305,6 +1355,7 @@ public void testInvalidConfigWhileCreatingNewTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); fail(); @@ -1338,6 +1389,7 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); } @@ -1353,6 +1405,7 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1373,6 +1426,7 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1408,6 +1462,7 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -1415,6 +1470,7 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); } @@ -1430,12 +1486,14 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false);Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( t1, new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1456,6 +1514,7 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1490,6 +1549,7 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); } @@ -1504,6 +1564,7 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1523,6 +1584,7 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1543,6 +1605,7 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1577,6 +1640,7 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); } @@ -1592,6 +1656,7 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1611,6 +1676,7 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1645,6 +1711,7 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); } @@ -1663,6 +1730,7 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1692,6 +1760,7 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), coreConfig ), false); @@ -1734,6 +1803,7 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); @@ -1753,6 +1823,7 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config1 ), new TenantConfig( @@ -1760,6 +1831,7 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config2 ), new TenantConfig( @@ -1767,6 +1839,7 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config3 ), new TenantConfig( @@ -1774,6 +1847,7 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config4 ), }; @@ -1820,6 +1894,7 @@ public void testThatMistypedConfigThrowsError() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), mistypedConfig ), false); fail(); @@ -1873,6 +1948,7 @@ public void testCoreSpecificConfigIsNotAllowedForNewTenants() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); fail(); @@ -1962,6 +2038,7 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); fail(); @@ -2025,6 +2102,7 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); @@ -2046,6 +2124,7 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config2 ), false); fail(); diff --git a/src/test/java/io/supertokens/test/multitenant/LoadTest.java b/src/test/java/io/supertokens/test/multitenant/LoadTest.java index fd321e9f6..0afb4d88b 100644 --- a/src/test/java/io/supertokens/test/multitenant/LoadTest.java +++ b/src/test/java/io/supertokens/test/multitenant/LoadTest.java @@ -75,6 +75,7 @@ public void testCreating100TenantsAndCheckOnlyOneInstanceOfStorageLayerIsCreated new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), config); try { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantIdentifier(null, null, null), diff --git a/src/test/java/io/supertokens/test/multitenant/LogTest.java b/src/test/java/io/supertokens/test/multitenant/LogTest.java index 80425ce51..9be6b3cca 100644 --- a/src/test/java/io/supertokens/test/multitenant/LogTest.java +++ b/src/test/java/io/supertokens/test/multitenant/LogTest.java @@ -82,6 +82,7 @@ public void testLogThatEachLineIsUniqueOnStartup() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject()), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -89,18 +90,21 @@ public void testLogThatEachLineIsUniqueOnStartup() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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 TotpConfig(false), new MfaConfig(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 TotpConfig(false), new MfaConfig(null, null), new JsonObject()), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -108,12 +112,14 @@ public void testLogThatEachLineIsUniqueOnStartup() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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 TotpConfig(false), new MfaConfig(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 c1d2fbf07..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; @@ -101,7 +101,7 @@ public void randomlyTestLoadConfig() TenantConfig persistedTenantConfig = Multitenancy.getTenantInfo(process.getProcess(), tenantConfig.tenantIdentifier); - assertEquals(tenantConfig, persistedTenantConfig); + assertTrue(tenantConfig.deepEquals(persistedTenantConfig)); } catch (InvalidProviderConfigException | InvalidConfigException e) { assertFalse(isOk); diff --git a/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java b/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java index c222b64c1..7f1e4330c 100644 --- a/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java +++ b/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java @@ -145,10 +145,12 @@ 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), + new TotpConfig(false), new MfaConfig(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), + new TotpConfig(false), new MfaConfig(null, null), tenant2Config), false); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -249,6 +251,7 @@ public void basicTestingWithDifferentAPIKeyAndTenantId() new TenantConfig(new TenantIdentifier("localhost", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -257,6 +260,7 @@ public void basicTestingWithDifferentAPIKeyAndTenantId() new TenantConfig(new TenantIdentifier("localhost", null, "t1"), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), false ); @@ -265,6 +269,7 @@ 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), + new TotpConfig(false), new MfaConfig(null, null), tenant2Config), false ); @@ -273,6 +278,7 @@ 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), + new TotpConfig(false), new MfaConfig(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..c37ae35f5 100644 --- a/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java +++ b/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java @@ -118,6 +118,7 @@ public void keysAreGeneratedForAllUserPoolIds() new TenantConfig(new TenantIdentifier("c1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig)}; for (TenantConfig config : tenants) { @@ -189,10 +190,12 @@ public void signingKeyClassesAreThereForAllTenants() new TenantConfig(new TenantIdentifier("c1", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig), new TenantConfig(new TenantIdentifier("c2", null, null), new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), tenantConfig2)}; for (TenantConfig config : tenants) { diff --git a/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java b/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java index b3e8cb46f..93d8364e8 100644 --- a/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java +++ b/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java @@ -183,6 +183,7 @@ public void testUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); @@ -288,6 +289,7 @@ public void testUpdationOfDefaultTenantWithNullClientType() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); @@ -391,6 +393,7 @@ public void testForNullsInUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); @@ -485,6 +488,7 @@ public void testForNullClientsListInUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); @@ -552,6 +556,7 @@ public void testForNullProvidersListInUpdationOfDefaultTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); @@ -636,6 +641,7 @@ public void testCreateTenantPersistsDataCorrectly() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); @@ -752,6 +758,7 @@ public void testCreationOfDuplicationTenantThrowsDuplicateTenantException() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); @@ -790,6 +797,7 @@ public void testCreationOfDuplicationTenantThrowsDuplicateTenantException() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); @@ -900,11 +908,12 @@ public void testOverwriteTenantOfNonExistantTenantThrowsTenantOrAppNotFoundExcep ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); } catch (TenantOrAppNotFoundException e) { - // pass + // pass0-89uuuuuui8j= } process.kill(); @@ -1003,6 +1012,7 @@ public void testCreateTenantWithDuplicateProviderIdThrowsException() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); @@ -1079,6 +1089,7 @@ public void testCreateDuplicateTenantWithDuplicateProviderIdThrowsDuplicateTenan ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); } catch (DuplicateTenantException e) { @@ -1148,6 +1159,7 @@ public void testCreateDuplicateTenantWithDuplicateProviderIdThrowsDuplicateTenan ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); @@ -1224,6 +1236,7 @@ public void testCreateDuplicateTenantWithDuplicateProviderClientTypeThrowsDuplic ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); } catch (DuplicateTenantException e) { @@ -1273,6 +1286,7 @@ public void testCreateDuplicateTenantWithDuplicateProviderClientTypeThrowsDuplic ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); @@ -1385,6 +1399,7 @@ public void testCreateTenantWithDuplicateClientTypeThrowsException() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); @@ -1489,6 +1504,7 @@ public void testOverwriteTenantWithDuplicateProviderIdThrowsException() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); @@ -1601,6 +1617,7 @@ public void testOverwriteTenantWithDuplicateClientTypeThrowsException() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); fail(); @@ -1690,6 +1707,7 @@ public void testOverwriteTenantForRaceConditions() ) }), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() )); break; @@ -1774,6 +1792,7 @@ public void testThatStoragePointingToSameDbSharesThInstance() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config1 ), new TenantConfig( @@ -1781,6 +1800,7 @@ public void testThatStoragePointingToSameDbSharesThInstance() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config1 ), new TenantConfig( @@ -1788,6 +1808,7 @@ public void testThatStoragePointingToSameDbSharesThInstance() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config2 ), new TenantConfig( @@ -1795,6 +1816,7 @@ public void testThatStoragePointingToSameDbSharesThInstance() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config2 ) }); @@ -1852,6 +1874,7 @@ public void testThatStorageIsClosedAfterTenantDeletion() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); @@ -1898,6 +1921,7 @@ public void testThatStorageIsClosedOnlyWhenNoMoreTenantsArePointingToIt() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -1905,6 +1929,7 @@ public void testThatStorageIsClosedOnlyWhenNoMoreTenantsArePointingToIt() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); @@ -1956,6 +1981,7 @@ public void testStorageDoesNotLoadAgainAfterTenantDeletionWhenRefreshedFromDb() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -1963,6 +1989,7 @@ public void testStorageDoesNotLoadAgainAfterTenantDeletionWhenRefreshedFromDb() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); @@ -2036,6 +2063,7 @@ public void testThatOriginalStorageIsNotClosedIfTheStorageForATenantChangesAndTh new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); @@ -2051,6 +2079,7 @@ public void testThatOriginalStorageIsNotClosedIfTheStorageForATenantChangesAndTh new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ), false); diff --git a/src/test/java/io/supertokens/test/multitenant/TestAppData.java b/src/test/java/io/supertokens/test/multitenant/TestAppData.java index 225df2491..0df6ee761 100644 --- a/src/test/java/io/supertokens/test/multitenant/TestAppData.java +++ b/src/test/java/io/supertokens/test/multitenant/TestAppData.java @@ -113,6 +113,7 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); 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..84f5f3490 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestSkipValidationInCreateThirdParty.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestSkipValidationInCreateThirdParty.java @@ -68,6 +68,7 @@ public void testSkipValidation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), new JsonObject() ), false); 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..212cc8698 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java @@ -121,6 +121,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -141,6 +142,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -161,6 +163,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); diff --git a/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java b/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java new file mode 100644 index 000000000..fea260357 --- /dev/null +++ b/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java @@ -0,0 +1,71 @@ +/* + * 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.HashSet; +import java.util.Random; +import java.util.Set; + +public class GenerateMfaConfig { + private static final String[] FACTORS = new String[]{ + "password", "otp-email", "otp-phone", "link-email", "link-phone", "totp", "thirdparty" + }; + + 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_firstFactors() { + String[] factors = selectRandomElements(FACTORS); + + return new ConfigGenerator.GeneratedValueAndExpectation( + factors, + new ConfigGenerator.Expectation("ok", factors)); + } + + public static ConfigGenerator.GeneratedValueAndExpectation generate_defaultMFARequirements() { + String[] factors = selectRandomElements(FACTORS); + + return new ConfigGenerator.GeneratedValueAndExpectation( + factors, + new ConfigGenerator.Expectation("ok", factors)); + } +} 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..77833877e 100644 --- a/src/test/java/io/supertokens/test/multitenant/generator/GenerateTenantConfig.java +++ b/src/test/java/io/supertokens/test/multitenant/generator/GenerateTenantConfig.java @@ -48,6 +48,18 @@ 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_mfaConfig() + throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException, + InstantiationException { + return ConfigGenerator.generate(MfaConfig.class); + } + 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..50d0b45e3 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), new MfaConfig(null, null), config ) ); @@ -128,6 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -148,6 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..c31966044 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), new MfaConfig(null, null), config ) ); @@ -129,6 +130,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -149,6 +151,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..f85b9a0d8 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), new MfaConfig(null, null), config ) ); @@ -128,6 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -148,6 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(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 df8cac9fb..b282ce006 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), new MfaConfig(null, null), config ) ); @@ -128,6 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -148,6 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), + new TotpConfig(false), new MfaConfig(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..3c54fbc6c 100644 --- a/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/userIdMapping/api/MultitenantAPITest.java @@ -106,6 +106,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -126,6 +127,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -146,6 +148,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), config ) ); @@ -166,6 +169,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), + new TotpConfig(false), new MfaConfig(null, null), config ) ); From 70e3fbc659b5344c85c7d11d7e7583b80dd3306e Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 12 Oct 2023 15:49:21 +0530 Subject: [PATCH 02/16] fix: mfa cleanup --- .../java/io/supertokens/ee/EEFeatureFlag.java | 5 +- .../io/supertokens/authRecipe/AuthRecipe.java | 4 - .../supertokens/featureflag/EE_FEATURES.java | 2 +- .../java/io/supertokens/inmemorydb/Start.java | 67 ------ src/main/java/io/supertokens/mfa/Mfa.java | 52 +---- src/main/java/io/supertokens/totp/Totp.java | 27 +-- .../io/supertokens/webserver/Webserver.java | 7 - .../webserver/api/mfa/DisableFactorAPI.java | 81 -------- .../webserver/api/mfa/EnableFactorAPI.java | 81 -------- .../webserver/api/mfa/ListFactorsAPI.java | 83 -------- .../supertokens/test/mfa/MfaLicenseTest.java | 152 -------------- .../supertokens/test/mfa/MfaRecipeTest.java | 109 ---------- .../supertokens/test/mfa/MfaStorageTest.java | 192 ------------------ .../io/supertokens/test/mfa/MfaTestBase.java | 148 -------------- .../test/mfa/api/DisableFactorAPITest.java | 93 --------- .../test/mfa/api/EnableFactorAPITest.java | 84 -------- .../test/mfa/api/ListFactorsAPITest.java | 89 -------- .../test/mfa/api/MfaUserIdMappingTest.java | 81 -------- .../test/multitenant/AppTenantUserTest.java | 12 +- .../test/multitenant/TestAppData.java | 5 +- .../api/TestTenantUserAssociation.java | 7 +- .../supertokens/test/totp/TOTPRecipeTest.java | 4 +- .../test/totp/TOTPStorageTest.java | 2 +- .../test/totp/TotpLicenseTest.java | 9 +- .../totp/api/CreateTotpDeviceAPITest.java | 4 +- .../test/totp/api/GetTotpDevicesAPITest.java | 2 +- .../test/totp/api/MultitenantAPITest.java | 2 +- .../totp/api/RemoveTotpDeviceAPITest.java | 2 +- .../test/totp/api/TotpUserIdMappingTest.java | 2 +- .../totp/api/UpdateTotpDeviceAPITest.java | 2 +- .../test/totp/api/VerifyTotpAPITest.java | 2 +- .../totp/api/VerifyTotpDeviceAPITest.java | 2 +- .../test/userIdMapping/UserIdMappingTest.java | 6 +- 33 files changed, 44 insertions(+), 1376 deletions(-) delete mode 100644 src/main/java/io/supertokens/webserver/api/mfa/DisableFactorAPI.java delete mode 100644 src/main/java/io/supertokens/webserver/api/mfa/EnableFactorAPI.java delete mode 100644 src/main/java/io/supertokens/webserver/api/mfa/ListFactorsAPI.java delete mode 100644 src/test/java/io/supertokens/test/mfa/MfaLicenseTest.java delete mode 100644 src/test/java/io/supertokens/test/mfa/MfaRecipeTest.java delete mode 100644 src/test/java/io/supertokens/test/mfa/MfaStorageTest.java delete mode 100644 src/test/java/io/supertokens/test/mfa/MfaTestBase.java delete mode 100644 src/test/java/io/supertokens/test/mfa/api/DisableFactorAPITest.java delete mode 100644 src/test/java/io/supertokens/test/mfa/api/EnableFactorAPITest.java delete mode 100644 src/test/java/io/supertokens/test/mfa/api/ListFactorsAPITest.java delete mode 100644 src/test/java/io/supertokens/test/mfa/api/MfaUserIdMappingTest.java diff --git a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java index 18f72ce7d..81c80b4ea 100644 --- a/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java +++ b/ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java @@ -248,6 +248,7 @@ private JsonObject getMFAStats() throws StorageQueryException, TenantOrAppNotFou } mfaStats.add("maus", mfaMauArr); + mfaStats.add("totp", getTOTPStats()); int mfaTotalUsers = 0; for (Storage storage : storages) { @@ -387,10 +388,6 @@ public JsonObject getPaidFeatureStats() throws StorageQueryException, TenantOrAp usageStats.add(EE_FEATURES.DASHBOARD_LOGIN.toString(), getDashboardLoginStats()); } - if (feature == EE_FEATURES.TOTP) { - usageStats.add(EE_FEATURES.TOTP.toString(), getTOTPStats()); - } - if (feature == EE_FEATURES.MFA) { usageStats.add(EE_FEATURES.MFA.toString(), getMFAStats()); } diff --git a/src/main/java/io/supertokens/authRecipe/AuthRecipe.java b/src/main/java/io/supertokens/authRecipe/AuthRecipe.java index 0c4f7b918..508bffaf6 100644 --- a/src/main/java/io/supertokens/authRecipe/AuthRecipe.java +++ b/src/main/java/io/supertokens/authRecipe/AuthRecipe.java @@ -934,8 +934,6 @@ private static void deleteNonAuthRecipeUser(TransactionConnection con, AppIdenti .deleteAllRolesForUser_Transaction(con, appIdentifierWithStorage, userId); appIdentifierWithStorage.getActiveUsersStorage() .deleteUserActive_Transaction(con, appIdentifierWithStorage, userId); - appIdentifierWithStorage.getMfaStorage() - .deleteMfaInfoForUser_Transaction(con, appIdentifierWithStorage, userId); } private static void deleteAuthRecipeUser(TransactionConnection con, @@ -976,8 +974,6 @@ public static boolean deleteNonAuthRecipeUser(TenantIdentifierWithStorage .removeUser(tenantIdentifierWithStorage, userId); finalDidExist = finalDidExist || didExist; - didExist = tenantIdentifierWithStorage.getMfaStorage() - .deleteMfaInfoForUser(tenantIdentifierWithStorage, userId); finalDidExist = finalDidExist || didExist; return finalDidExist; diff --git a/src/main/java/io/supertokens/featureflag/EE_FEATURES.java b/src/main/java/io/supertokens/featureflag/EE_FEATURES.java index de35653b6..e120fbf2f 100644 --- a/src/main/java/io/supertokens/featureflag/EE_FEATURES.java +++ b/src/main/java/io/supertokens/featureflag/EE_FEATURES.java @@ -18,7 +18,7 @@ public enum EE_FEATURES { ACCOUNT_LINKING("account_linking"), MULTI_TENANCY("multi_tenancy"), TEST("test"), - DASHBOARD_LOGIN("dashboard_login"), TOTP("totp"), MFA("mfa"); + DASHBOARD_LOGIN("dashboard_login"), MFA("mfa"); private final String name; diff --git a/src/main/java/io/supertokens/inmemorydb/Start.java b/src/main/java/io/supertokens/inmemorydb/Start.java index cf6e858ae..d3dbcf90f 100644 --- a/src/main/java/io/supertokens/inmemorydb/Start.java +++ b/src/main/java/io/supertokens/inmemorydb/Start.java @@ -2813,73 +2813,6 @@ public int removeExpiredCodes(TenantIdentifier tenantIdentifier, long expiredBef } } - - // MFA recipe: - @Override - public boolean enableFactor(TenantIdentifier tenantIdentifier, String userId, String factor) - throws StorageQueryException { - try { - int insertedCount = MfaQueries.enableFactor(this, tenantIdentifier, userId, factor); - if (insertedCount == 0) { - return false; - } - return true; - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public String[] listFactors(TenantIdentifier tenantIdentifier, String userId) - throws StorageQueryException { - try { - return MfaQueries.listFactors(this, tenantIdentifier, userId); - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public boolean disableFactor(TenantIdentifier tenantIdentifier, String userId, String factor) - throws StorageQueryException { - try { - int deletedCount = MfaQueries.disableFactor(this, tenantIdentifier, userId, factor); - if (deletedCount == 0) { - return false; - } - return true; - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public boolean deleteMfaInfoForUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId) - throws StorageQueryException { - try { - int deletedCount = MfaQueries.deleteUser_Transaction(this, (Connection) con.getConnection(), appIdentifier, userId); - if (deletedCount == 0) { - return false; - } - return true; - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - - @Override - public boolean deleteMfaInfoForUser(TenantIdentifier tenantIdentifier, String userId) throws StorageQueryException { - try { - int deletedCount = MfaQueries.deleteUserFromTenant(this, tenantIdentifier, userId); - if (deletedCount == 0) { - return false; - } - return true; - } catch (SQLException e) { - throw new StorageQueryException(e); - } - } - @Override public Set getValidFieldsInConfig() { return SQLiteConfig.getValidFields(); diff --git a/src/main/java/io/supertokens/mfa/Mfa.java b/src/main/java/io/supertokens/mfa/Mfa.java index 968d49f5e..a93f7b7c2 100644 --- a/src/main/java/io/supertokens/mfa/Mfa.java +++ b/src/main/java/io/supertokens/mfa/Mfa.java @@ -5,60 +5,20 @@ import io.supertokens.featureflag.FeatureFlag; import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; -import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; public class Mfa { - private static boolean isMfaEnabled(AppIdentifier appIdentifier, Main main) - throws StorageQueryException, TenantOrAppNotFoundException { + public static void checkForMFAFeature(AppIdentifier appIdentifier, Main main) + throws StorageQueryException, TenantOrAppNotFoundException, FeatureNotEnabledException { EE_FEATURES[] features = FeatureFlag.getInstance(main, appIdentifier).getEnabledFeatures(); for (EE_FEATURES f : features) { if (f == EE_FEATURES.MFA) { - return true; + return; } } - return false; - } - - public static boolean enableFactor(TenantIdentifierWithStorage tenantIdentifierWithStorage, Main main, String userId, String factorId) - throws - StorageQueryException, FeatureNotEnabledException, TenantOrAppNotFoundException { - if (!isMfaEnabled(tenantIdentifierWithStorage.toAppIdentifier(), main)) { - throw new FeatureNotEnabledException( - "MFA feature is not enabled. Please subscribe to a SuperTokens core license key to enable this " + - "feature."); - } - - MfaStorage mfaStorage = tenantIdentifierWithStorage.getMfaStorage(); - return mfaStorage.enableFactor(tenantIdentifierWithStorage, userId, factorId); - } - - public static String[] listFactors(TenantIdentifierWithStorage tenantIdentifierWithStorage, Main main, String userId) - throws - StorageQueryException, TenantOrAppNotFoundException, FeatureNotEnabledException { - if (!isMfaEnabled(tenantIdentifierWithStorage.toAppIdentifier(), main)) { - throw new FeatureNotEnabledException( - "MFA feature is not enabled. Please subscribe to a SuperTokens core license key to enable this " + - "feature."); - } - - MfaStorage mfaStorage = tenantIdentifierWithStorage.getMfaStorage(); - return mfaStorage.listFactors(tenantIdentifierWithStorage, userId); - } - - public static boolean disableFactor(TenantIdentifierWithStorage tenantIdentifierWithStorage, Main main, String userId, String factorId) - throws - StorageQueryException, TenantOrAppNotFoundException, FeatureNotEnabledException { - - if (!isMfaEnabled(tenantIdentifierWithStorage.toAppIdentifier(), main)) { - throw new FeatureNotEnabledException( - "MFA feature is not enabled. Please subscribe to a SuperTokens core license key to enable this " + - "feature."); - } - - MfaStorage mfaStorage = tenantIdentifierWithStorage.getMfaStorage(); - return mfaStorage.disableFactor(tenantIdentifierWithStorage, userId, factorId); + throw new FeatureNotEnabledException( + "MFA feature is not enabled. Please subscribe to a SuperTokens core license key to enable this " + + "feature."); } } diff --git a/src/main/java/io/supertokens/totp/Totp.java b/src/main/java/io/supertokens/totp/Totp.java index e5f715c3b..0c2ae63a9 100644 --- a/src/main/java/io/supertokens/totp/Totp.java +++ b/src/main/java/io/supertokens/totp/Totp.java @@ -3,12 +3,10 @@ import com.eatthepath.otp.TimeBasedOneTimePasswordGenerator; import io.supertokens.Main; import io.supertokens.config.Config; -import io.supertokens.featureflag.EE_FEATURES; -import io.supertokens.featureflag.FeatureFlag; import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; +import io.supertokens.mfa.Mfa; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; -import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; @@ -70,17 +68,6 @@ private static boolean checkCode(TOTPDevice device, String code) { return false; } - private static boolean isTotpEnabled(AppIdentifier appIdentifier, Main main) - throws StorageQueryException, TenantOrAppNotFoundException { - EE_FEATURES[] features = FeatureFlag.getInstance(main, appIdentifier).getEnabledFeatures(); - for (EE_FEATURES f : features) { - if (f == EE_FEATURES.TOTP) { - return true; - } - } - return false; - } - @TestOnly public static TOTPDevice registerDevice(Main main, String userId, String deviceName, int skew, int period) @@ -126,11 +113,7 @@ public static TOTPDevice registerDevice(AppIdentifierWithStorage appIdentifierWi throws StorageQueryException, DeviceAlreadyExistsException, NoSuchAlgorithmException, FeatureNotEnabledException, TenantOrAppNotFoundException, StorageTransactionLogicException { - if (!isTotpEnabled(appIdentifierWithStorage, main)) { - throw new FeatureNotEnabledException( - "TOTP feature is not enabled. Please subscribe to a SuperTokens core license key to enable this " + - "feature."); - } + Mfa.checkForMFAFeature(appIdentifierWithStorage, main); String secret = generateSecret(); TOTPDevice device = new TOTPDevice(userId, deviceName, secret, period, skew, false); @@ -403,11 +386,7 @@ public static void verifyCode(TenantIdentifierWithStorage tenantIdentifierWithSt StorageQueryException, StorageTransactionLogicException, FeatureNotEnabledException, TenantOrAppNotFoundException { - if (!isTotpEnabled(tenantIdentifierWithStorage.toAppIdentifierWithStorage(), main)) { - throw new FeatureNotEnabledException( - "TOTP feature is not enabled. Please subscribe to a SuperTokens core license key to enable this " + - "feature."); - } + Mfa.checkForMFAFeature(tenantIdentifierWithStorage.toAppIdentifierWithStorage(), main); TOTPSQLStorage totpStorage = tenantIdentifierWithStorage.getTOTPStorage(); diff --git a/src/main/java/io/supertokens/webserver/Webserver.java b/src/main/java/io/supertokens/webserver/Webserver.java index b418d5e4a..5e4a4ff8c 100644 --- a/src/main/java/io/supertokens/webserver/Webserver.java +++ b/src/main/java/io/supertokens/webserver/Webserver.java @@ -37,9 +37,6 @@ import io.supertokens.webserver.api.emailverification.VerifyEmailAPI; import io.supertokens.webserver.api.jwt.JWKSAPI; import io.supertokens.webserver.api.jwt.JWTSigningAPI; -import io.supertokens.webserver.api.mfa.DisableFactorAPI; -import io.supertokens.webserver.api.mfa.EnableFactorAPI; -import io.supertokens.webserver.api.mfa.ListFactorsAPI; import io.supertokens.webserver.api.multitenancy.*; import io.supertokens.webserver.api.multitenancy.thirdparty.CreateOrUpdateThirdPartyConfigAPI; import io.supertokens.webserver.api.multitenancy.thirdparty.RemoveThirdPartyConfigAPI; @@ -232,10 +229,6 @@ private void setupRoutes() { addAPI(new GetDashboardSessionsForUserAPI(main)); addAPI(new SearchTagsAPI(main)); - addAPI(new ListFactorsAPI(main)); - addAPI(new EnableFactorAPI(main)); - addAPI(new DisableFactorAPI(main)); - addAPI(new CreateOrUpdateConnectionUriDomainAPI(main)); addAPI(new RemoveConnectionUriDomainAPI(main)); addAPI(new ListConnectionUriDomainsAPI(main)); diff --git a/src/main/java/io/supertokens/webserver/api/mfa/DisableFactorAPI.java b/src/main/java/io/supertokens/webserver/api/mfa/DisableFactorAPI.java deleted file mode 100644 index 92acecacb..000000000 --- a/src/main/java/io/supertokens/webserver/api/mfa/DisableFactorAPI.java +++ /dev/null @@ -1,81 +0,0 @@ -package io.supertokens.webserver.api.mfa; - -import com.google.gson.JsonObject; -import io.supertokens.Main; -import io.supertokens.TenantIdentifierWithStorageAndUserIdMapping; -import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; -import io.supertokens.mfa.Mfa; -import io.supertokens.pluginInterface.RECIPE_ID; -import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; -import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; -import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; -import io.supertokens.useridmapping.UserIdType; -import io.supertokens.webserver.InputParser; -import io.supertokens.webserver.WebserverAPI; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import java.io.IOException; - -public class DisableFactorAPI extends WebserverAPI { - private static final long serialVersionUID = -4641988458637882374L; - - public DisableFactorAPI(Main main) { - super(main, RECIPE_ID.MFA.toString()); - } - - @Override - public String getPath() { - return "/recipe/mfa/factors/disable"; - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific - JsonObject input = InputParser.parseJsonObjectOrThrowError(req); - - String userId = InputParser.parseStringOrThrowError(input, "userId", false); - String factor = InputParser.parseStringOrThrowError(input, "factor", false).trim().toLowerCase(); - - if (userId.isEmpty()) { - throw new ServletException(new BadRequestException("userId cannot be empty")); - } - if (factor.isEmpty()) { - throw new ServletException(new BadRequestException("factor cannot be empty")); - } - - JsonObject result = new JsonObject(); - - try { - TenantIdentifierWithStorage tenantIdentifierWithStorage; - try { - // This step is required only because user_last_active table stores supertokens internal user id. - // While sending the usage stats we do a join, so mfa tables must also use internal user id. - - // Try to find the tenantIdentifier with right storage based on the userId - TenantIdentifierWithStorageAndUserIdMapping mappingAndStorage = - getTenantIdentifierWithStorageAndUserIdMappingFromRequest( - req, userId, UserIdType.ANY); - - if (mappingAndStorage.userIdMapping != null) { - userId = mappingAndStorage.userIdMapping.superTokensUserId; - } - tenantIdentifierWithStorage = mappingAndStorage.tenantIdentifierWithStorage; - } catch (UnknownUserIdException e) { - // if the user is not found, just use the storage of the tenant of interest - tenantIdentifierWithStorage = getTenantIdentifierWithStorageFromRequest(req); - } - - boolean actuallyDeleted = Mfa.disableFactor(tenantIdentifierWithStorage, main, userId, factor); - - result.addProperty("status", "OK"); - result.addProperty("didExist", actuallyDeleted); - super.sendJsonResponse(200, result, resp); - } catch (StorageQueryException | FeatureNotEnabledException | TenantOrAppNotFoundException e) { - throw new ServletException(e); - } - } - -} diff --git a/src/main/java/io/supertokens/webserver/api/mfa/EnableFactorAPI.java b/src/main/java/io/supertokens/webserver/api/mfa/EnableFactorAPI.java deleted file mode 100644 index 34d35509e..000000000 --- a/src/main/java/io/supertokens/webserver/api/mfa/EnableFactorAPI.java +++ /dev/null @@ -1,81 +0,0 @@ -package io.supertokens.webserver.api.mfa; - -import com.google.gson.JsonObject; -import io.supertokens.Main; -import io.supertokens.TenantIdentifierWithStorageAndUserIdMapping; -import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; -import io.supertokens.mfa.Mfa; -import io.supertokens.pluginInterface.RECIPE_ID; -import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; -import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; -import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; -import io.supertokens.useridmapping.UserIdType; -import io.supertokens.webserver.InputParser; -import io.supertokens.webserver.WebserverAPI; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import java.io.IOException; - -public class EnableFactorAPI extends WebserverAPI { - private static final long serialVersionUID = -4641988458637882374L; - - public EnableFactorAPI(Main main) { - super(main, RECIPE_ID.MFA.toString()); - } - - @Override - public String getPath() { - return "/recipe/mfa/factors/enable"; - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific - JsonObject input = InputParser.parseJsonObjectOrThrowError(req); - - String userId = InputParser.parseStringOrThrowError(input, "userId", false); - String factor = InputParser.parseStringOrThrowError(input, "factor", false).trim().toLowerCase(); - - if (userId.isEmpty()) { - throw new ServletException(new BadRequestException("userId cannot be empty")); - } - if (factor.isEmpty()) { - throw new ServletException(new BadRequestException("factor cannot be empty")); - } - - JsonObject result = new JsonObject(); - - try { - TenantIdentifierWithStorage tenantIdentifierWithStorage; - try { - // This step is required only because user_last_active table stores supertokens internal user id. - // While sending the usage stats we do a join, so mfa tables must also use internal user id. - - // Try to find the tenantIdentifier with right storage based on the userId - TenantIdentifierWithStorageAndUserIdMapping mappingAndStorage = - getTenantIdentifierWithStorageAndUserIdMappingFromRequest( - req, userId, UserIdType.ANY); - - if (mappingAndStorage.userIdMapping != null) { - userId = mappingAndStorage.userIdMapping.superTokensUserId; - } - tenantIdentifierWithStorage = mappingAndStorage.tenantIdentifierWithStorage; - } catch (UnknownUserIdException e) { - // if the user is not found, just use the storage of the tenant of interest - tenantIdentifierWithStorage = getTenantIdentifierWithStorageFromRequest(req); - } - - boolean actuallyInserted = Mfa.enableFactor(tenantIdentifierWithStorage, main, userId, factor); - - result.addProperty("status", "OK"); - result.addProperty("didExist", !actuallyInserted); - super.sendJsonResponse(200, result, resp); - } catch (StorageQueryException | FeatureNotEnabledException | TenantOrAppNotFoundException e) { - throw new ServletException(e); - } - } - -} diff --git a/src/main/java/io/supertokens/webserver/api/mfa/ListFactorsAPI.java b/src/main/java/io/supertokens/webserver/api/mfa/ListFactorsAPI.java deleted file mode 100644 index 06ed4729b..000000000 --- a/src/main/java/io/supertokens/webserver/api/mfa/ListFactorsAPI.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.supertokens.webserver.api.mfa; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import io.supertokens.Main; -import io.supertokens.TenantIdentifierWithStorageAndUserIdMapping; -import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; -import io.supertokens.mfa.Mfa; -import io.supertokens.pluginInterface.RECIPE_ID; -import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; -import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; -import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; -import io.supertokens.useridmapping.UserIdType; -import io.supertokens.webserver.InputParser; -import io.supertokens.webserver.WebserverAPI; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import java.io.IOException; - -public class ListFactorsAPI extends WebserverAPI { - private static final long serialVersionUID = -4641988458637882374L; - - public ListFactorsAPI(Main main) { - super(main, RECIPE_ID.MFA.toString()); - } - - @Override - public String getPath() { - return "/recipe/mfa/factors/list"; - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific - String userId = InputParser.getQueryParamOrThrowError(req, "userId", false); - - if (userId.isEmpty()) { - throw new ServletException(new BadRequestException("userId cannot be empty")); - } - - JsonObject result = new JsonObject(); - - try { - TenantIdentifierWithStorage tenantIdentifierWithStorage; - try { - // This step is required only because user_last_active table stores supertokens internal user id. - // While sending the usage stats we do a join, so mfa tables must also use internal user id. - - // Try to find the tenantIdentifier with right storage based on the userId - TenantIdentifierWithStorageAndUserIdMapping mappingAndStorage = - getTenantIdentifierWithStorageAndUserIdMappingFromRequest( - req, userId, UserIdType.ANY); - - if (mappingAndStorage.userIdMapping != null) { - userId = mappingAndStorage.userIdMapping.superTokensUserId; - } - tenantIdentifierWithStorage = mappingAndStorage.tenantIdentifierWithStorage; - } catch (UnknownUserIdException e) { - // if the user is not found, just use the storage of the tenant of interest - tenantIdentifierWithStorage = getTenantIdentifierWithStorageFromRequest(req); - } - - String[] factors = Mfa.listFactors(tenantIdentifierWithStorage, main, userId); - - JsonArray factorsJson = new JsonArray(); - - for (String factor : factors) { - factorsJson.add(new JsonPrimitive(factor)); - } - - result.addProperty("status", "OK"); - result.add("factors", factorsJson); - super.sendJsonResponse(200, result, resp); - } catch (StorageQueryException | FeatureNotEnabledException | TenantOrAppNotFoundException e) { - throw new ServletException(e); - } - } - -} diff --git a/src/test/java/io/supertokens/test/mfa/MfaLicenseTest.java b/src/test/java/io/supertokens/test/mfa/MfaLicenseTest.java deleted file mode 100644 index 96d32a3f6..000000000 --- a/src/test/java/io/supertokens/test/mfa/MfaLicenseTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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.mfa; - -import com.google.gson.JsonObject; -import io.supertokens.Main; -import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; -import io.supertokens.mfa.Mfa; -import io.supertokens.pluginInterface.mfa.MfaStorage; -import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; -import io.supertokens.storageLayer.StorageLayer; -import io.supertokens.test.httpRequest.HttpResponseException; -import org.junit.Test; - -import java.util.HashMap; - -import static org.junit.Assert.assertThrows; - -public class MfaLicenseTest extends MfaTestBase { - @Test - public void testTotpWithoutLicense() throws Exception { - TestSetupResult result = initSteps(false); - if (result == null) { - return; - } - - if (StorageLayer.isInMemDb(result.process.getProcess())) { - return; - } - - Main main = result.process.getProcess(); - MfaStorage storage = result.storage; - TenantIdentifierWithStorage tid = new TenantIdentifierWithStorage(null, null, null, storage); - - // Enable factor - assertThrows(FeatureNotEnabledException.class, () -> { - Mfa.enableFactor(tid, main, "userId", "f1"); - }); - // List factors - assertThrows(FeatureNotEnabledException.class, () -> { - Mfa.listFactors(tid, main, "user"); - }); - // Disable factor - assertThrows(FeatureNotEnabledException.class, () -> { - Mfa.disableFactor(tid, main, "userId", "f1"); - }); - - // Try to create device via API: - JsonObject body = new JsonObject(); - body.addProperty("userId", "user-id"); - body.addProperty("factor", "f1"); - - HttpResponseException e = assertThrows( - HttpResponseException.class, - () -> { - enableFactorRequest(result.process, body); - } - ); - assert e.statusCode == 402; - assert e.getMessage().contains("MFA feature is not enabled"); - - - // Try to list devices via API: - HashMap params = new HashMap<>(); - params.put("userId", "user-id"); - - HttpResponseException e2 = assertThrows( - HttpResponseException.class, - () -> { - listFactorsRequest(result.process, params); - } - ); - assert e2.statusCode == 402; - assert e2.getMessage().contains("MFA feature is not enabled"); - - // Try to disable factor via API: - body.addProperty("userId", "user-id"); - body.addProperty("factor", "f1"); - - HttpResponseException e3 = assertThrows( - HttpResponseException.class, - () -> { - disableFactorRequest(result.process, body); - } - ); - assert e3.statusCode == 402; - assert e3.getMessage().contains("MFA feature is not enabled"); - } - - - @Test - public void testTotpWithLicense() throws Exception { - TestSetupResult result = initSteps(true); - if (result == null) { - return; - } - Main main = result.process.getProcess(); - MfaStorage storage = result.storage; - TenantIdentifierWithStorage tid = new TenantIdentifierWithStorage(null, null, null, storage); - - // Enable factor - boolean insertedFactor = Mfa.enableFactor(tid, main, "userId", "f1"); - assert insertedFactor; - // List factors - String[] factors = Mfa.listFactors(tid, main, "userId"); - assert factors.length == 1; - assert factors[0].equals("f1"); - // Disable factor - boolean removedFactor = Mfa.disableFactor(tid, main, "userId", "f1"); - assert removedFactor; - - // Try to enable factor via API: - JsonObject body = new JsonObject(); - body.addProperty("userId", "user-id"); - body.addProperty("factor", "f1"); - - JsonObject res = enableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == false; - - // Try to list factors via API: - HashMap params = new HashMap<>(); - params.put("userId", "user-id"); - - JsonObject res2 = listFactorsRequest(result.process, params); - assert res2.get("status").getAsString().equals("OK"); - assert res2.get("factors").getAsJsonArray().size() == 1; - assert res2.get("factors").getAsJsonArray().get(0).getAsString().equals("f1"); - - // Try to disable factor via API: - body.addProperty("userId", "user-id"); - body.addProperty("factor", "f1"); - - JsonObject res3 = disableFactorRequest(result.process, body); - assert res3.get("status").getAsString().equals("OK"); - assert res3.get("didExist").getAsBoolean() == true; - } -} diff --git a/src/test/java/io/supertokens/test/mfa/MfaRecipeTest.java b/src/test/java/io/supertokens/test/mfa/MfaRecipeTest.java deleted file mode 100644 index 1182e71a5..000000000 --- a/src/test/java/io/supertokens/test/mfa/MfaRecipeTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.mfa; - -import com.google.gson.JsonObject; -import io.supertokens.Main; -import io.supertokens.emailpassword.EmailPassword; -import io.supertokens.featureflag.EE_FEATURES; -import io.supertokens.featureflag.FeatureFlagTestContent; -import io.supertokens.mfa.Mfa; -import io.supertokens.multitenancy.Multitenancy; -import io.supertokens.pluginInterface.mfa.MfaStorage; -import io.supertokens.pluginInterface.multitenancy.*; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; - -public class MfaRecipeTest extends MfaTestBase { - @Test - public void enableFactorTests() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - MfaStorage storage = result.storage; - Main main = result.process.main; - TenantIdentifierWithStorage tid = new TenantIdentifierWithStorage(null, null, null, storage); - - boolean insertedF1 = Mfa.enableFactor(tid, main, "userId", "f1"); - assert insertedF1; - - String[] factors = Mfa.listFactors(tid, main, "userId"); - - assert factors != null; - assert factors.length == 1; - assert factors[0].equals("f1"); - - boolean insertedF1Again = Mfa.enableFactor(tid, main, "userId", "f1"); - boolean insertedF2 = Mfa.enableFactor(tid, main, "userId", "f2"); - - assert !insertedF1Again; - assert insertedF2; - } - - @Test - public void listFactorsTest() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - MfaStorage storage = result.storage; - Main main = result.process.main; - TenantIdentifierWithStorage tid = new TenantIdentifierWithStorage(null, null, null, storage); - - assert Mfa.enableFactor(tid, main, "userId", "f3") == true; - assert Mfa.enableFactor(tid, main, "userId", "f1") == true; - assert Mfa.enableFactor(tid, main, "userId", "f2") == true; - - assert Mfa.disableFactor(tid, main, "userId", "f2") == true; - - String[] factors = Mfa.listFactors(tid, main, "userId"); - - assert factors != null; - assert factors.length == 2; - assert factors[0].equals("f1"); - assert factors[1].equals("f3"); - } - - @Test - public void disableFactorsTest() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - MfaStorage storage = result.storage; - Main main = result.process.main; - TenantIdentifierWithStorage tid = new TenantIdentifierWithStorage(null, null, null, storage); - - assert Mfa.enableFactor(tid, main, "userId", "f1") == true; - assert Mfa.enableFactor(tid, main, "userId", "f2") == true; - - assert Mfa.disableFactor(tid, main, "non-existent-userId", "f1") == false; // userId does not exist - assert Mfa.disableFactor(tid, main, "userId", "f2") == true; // f2 was enabled - assert Mfa.disableFactor(tid, main, "userId", "f3") == false; // f3 was never enabled - - String[] factors = storage.listFactors(tid, "userId"); - - assert factors != null; - assert factors.length == 1; - assert factors[0].equals("f1"); - - factors = Mfa.listFactors(tid, main, "non-existent-user"); - assert factors.length == 0; - } -} diff --git a/src/test/java/io/supertokens/test/mfa/MfaStorageTest.java b/src/test/java/io/supertokens/test/mfa/MfaStorageTest.java deleted file mode 100644 index 6af701819..000000000 --- a/src/test/java/io/supertokens/test/mfa/MfaStorageTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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.mfa; - -import com.google.gson.JsonObject; -import io.supertokens.emailpassword.EmailPassword; -import io.supertokens.featureflag.EE_FEATURES; -import io.supertokens.featureflag.FeatureFlagTestContent; -import io.supertokens.multitenancy.Multitenancy; -import io.supertokens.pluginInterface.mfa.MfaStorage; -import io.supertokens.pluginInterface.mfa.sqlStorage.MfaSQLStorage; -import io.supertokens.pluginInterface.multitenancy.*; -import io.supertokens.pluginInterface.sqlStorage.SQLStorage; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; - -public class MfaStorageTest extends MfaTestBase { - - @Test - public void enableFactorTests() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - MfaStorage storage = result.storage; - TenantIdentifier tid = new TenantIdentifier(null, null, null); - - boolean insertedF1 = storage.enableFactor(tid, "userId", "f1"); - assert insertedF1; - - String[] factors = storage.listFactors(tid, "userId"); - - assert factors != null; - assert factors.length == 1; - assert factors[0].equals("f1"); - - boolean insertedF1Again = storage.enableFactor(tid, "userId", "f1"); - boolean insertedF2 = storage.enableFactor(tid, "userId", "f2"); - - assert !insertedF1Again; - assert insertedF2; - } - - @Test - public void listFactorsTest() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - MfaStorage storage = result.storage; - TenantIdentifier tid = new TenantIdentifier(null, null, null); - - assert storage.enableFactor(tid, "userId", "f1") == true; - assert storage.enableFactor(tid, "userId", "f2") == true; - assert storage.enableFactor(tid, "userId", "f3") == true; - - assert storage.disableFactor(tid, "userId", "f2") == true; - - String[] factors = storage.listFactors(tid, "userId"); - - assert factors != null; - assert factors.length == 2; - assert factors[0].equals("f1"); - assert factors[1].equals("f3"); - } - - @Test - public void disableFactorsTest() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - MfaStorage storage = result.storage; - TenantIdentifier tid = new TenantIdentifier(null, null, null); - - assert storage.enableFactor(tid, "userId", "f1") == true; - assert storage.enableFactor(tid, "userId", "f2") == true; - - assert storage.disableFactor(tid, "non-existent-userId", "f1") == false; // userId does not exist - assert storage.disableFactor(tid, "userId", "f2") == true; // f2 was enabled - assert storage.disableFactor(tid, "userId", "f3") == false; // f3 was never enabled - - String[] factors = storage.listFactors(tid, "userId"); - - assert factors != null; - assert factors.length == 1; - assert factors[0].equals("f1"); - - factors = storage.listFactors(tid, "non-existent-user"); - assert factors.length == 0; - } - - - @Test - public void deleteUserTest() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - MfaSQLStorage storage = result.storage; - TenantIdentifier tid = new TenantIdentifier(null, null, null); - - assert storage.enableFactor(tid, "user1", "f1") == true; - assert storage.enableFactor(tid, "user1", "f2") == true; - - assert storage.enableFactor(tid, "user2", "f1") == true; - assert storage.enableFactor(tid, "user2", "f3") == true; - - ((SQLStorage) storage).startTransaction(con -> { - assert storage.deleteMfaInfoForUser_Transaction(con, tid.toAppIdentifier(), "non-existent-user") == false; - assert storage.deleteMfaInfoForUser_Transaction(con, tid.toAppIdentifier(), "user2") == true; - return null; - }); - - String[] factors = storage.listFactors(tid, "user2"); - assert factors.length == 0; - - factors = storage.listFactors(tid, "user1"); - - assert factors.length == 2; - assert factors[0].equals("f1"); - assert factors[1].equals("f2"); - } - - - @Test - public void deleteUserFromTenantTest() throws Exception { - TestSetupResult result = initSteps(); - if (result == null) { - return; - } - - FeatureFlagTestContent.getInstance(result.process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA, EE_FEATURES.MULTI_TENANCY}); - - MfaStorage mfaStorage = result.storage; - - TenantIdentifierWithStorage publicTenant = new TenantIdentifierWithStorage(null, null, null, result.storage); - TenantIdentifierWithStorage privateTenant = new TenantIdentifierWithStorage(null, null, "t1", result.storage); - - TenantConfig privateTenantConfig = new TenantConfig(privateTenant, new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new JsonObject()); - - Multitenancy.addNewOrUpdateAppOrTenant( - result.process.main, - privateTenantConfig, - false - ); - - // we will use the same userId for both tenants - String userId = EmailPassword.signUp( - privateTenant, - result.process.main, - "user@example.com", - "password" - ).getSupertokensUserId(); - - // Iterate over all both tenants and enable the same set of factors for the same user ID - for (TenantIdentifierWithStorage tid : new TenantIdentifierWithStorage[]{publicTenant, privateTenant}) { - assert mfaStorage.enableFactor(tid, userId, "f1") == true; - assert mfaStorage.enableFactor(tid, userId, "f2") == true; - } - - // Delete private tenant user - assert mfaStorage.deleteMfaInfoForUser(privateTenant, userId) == true; - - // Deleting user from one tenant shouldn't affect others: - assert mfaStorage.listFactors(privateTenant, userId).length == 0; - assert mfaStorage.listFactors(publicTenant, userId).length == 2; - - String userEmail = EmailPassword.signIn(privateTenant, result.process.main, "user@example.com", "password").loginMethods[0].email; - assert userEmail.equals("user@example.com"); // Use should still exist in the private tenant since we have only disabled MFA related info - - // Deleting from non existent user should return false: - assert mfaStorage.deleteMfaInfoForUser(privateTenant, "non-existent-user") == false; - } - -} diff --git a/src/test/java/io/supertokens/test/mfa/MfaTestBase.java b/src/test/java/io/supertokens/test/mfa/MfaTestBase.java deleted file mode 100644 index 1d9b236d5..000000000 --- a/src/test/java/io/supertokens/test/mfa/MfaTestBase.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.mfa; - -import com.google.gson.JsonObject; -import io.supertokens.ProcessState; -import io.supertokens.featureflag.EE_FEATURES; -import io.supertokens.featureflag.FeatureFlagTestContent; -import io.supertokens.pluginInterface.STORAGE_TYPE; -import io.supertokens.pluginInterface.mfa.sqlStorage.MfaSQLStorage; -import io.supertokens.storageLayer.StorageLayer; -import io.supertokens.test.TestingProcessManager; -import io.supertokens.test.Utils; -import io.supertokens.test.httpRequest.HttpRequestForTesting; -import io.supertokens.test.httpRequest.HttpResponseException; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestRule; - -import java.io.IOException; -import java.util.HashMap; - -import static org.junit.Assert.*; - -public class MfaTestBase { - @Rule - public TestRule watchman = Utils.getOnFailure(); - - @AfterClass - public static void afterTesting() { - Utils.afterTesting(); - } - - @Before - public void beforeEach() { - Utils.reset(); - } - - - public class TestSetupResult { - public MfaSQLStorage storage; - public TestingProcessManager.TestingProcess process; - - public TestSetupResult(MfaSQLStorage storage, TestingProcessManager.TestingProcess process) { - this.storage = storage; - this.process = process; - } - } - - public TestSetupResult initSteps(boolean enableMfaFeature) - throws InterruptedException { - String[] args = {"../"}; - - TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); - assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); - - if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { - return null; - } - - MfaSQLStorage storage = (MfaSQLStorage) StorageLayer.getStorage(process.getProcess()); - - if (enableMfaFeature) { - FeatureFlagTestContent.getInstance(process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); - } - - return new TestSetupResult(storage, process); - } - - public TestSetupResult initSteps() - throws InterruptedException { - return initSteps(true); - } - - public void checkFieldMissingErrorResponse(Exception ex, String fieldName) { - assert ex instanceof HttpResponseException; - HttpResponseException e = (HttpResponseException) ex; - assert e.statusCode == 400; - assertTrue(e.getMessage().contains( - "Http error. Status Code: 400. Message: Field name '" + fieldName + "' is invalid in JSON input")); - } - - public void checkResponseErrorContains(Exception ex, String msg) { - assert ex instanceof HttpResponseException; - HttpResponseException e = (HttpResponseException) ex; - assert e.statusCode == 400; - assertTrue(e.getMessage().contains(msg)); - } - - - public JsonObject enableFactorRequest(TestingProcessManager.TestingProcess process, JsonObject body) - throws HttpResponseException, IOException { - return HttpRequestForTesting.sendJsonPOSTRequest( - process.getProcess(), - "", - "http://localhost:3567/recipe/mfa/factors/enable", - body, - 1000, - 1000, - null, - Utils.getCdiVersionStringLatestForTests(), - "mfa"); - } - - public JsonObject listFactorsRequest(TestingProcessManager.TestingProcess process, HashMap params) - throws HttpResponseException, IOException { - return HttpRequestForTesting.sendGETRequest( - process.getProcess(), - "", - "http://localhost:3567/recipe/mfa/factors/list", - params, - 1000, - 1000, - null, - Utils.getCdiVersionStringLatestForTests(), - "mfa"); - } - - public JsonObject disableFactorRequest(TestingProcessManager.TestingProcess process, JsonObject body) - throws HttpResponseException, IOException { - return HttpRequestForTesting.sendJsonPOSTRequest( - process.getProcess(), - "", - "http://localhost:3567/recipe/mfa/factors/disable", - body, - 1000, - 1000, - null, - Utils.getCdiVersionStringLatestForTests(), - "mfa"); - } -} diff --git a/src/test/java/io/supertokens/test/mfa/api/DisableFactorAPITest.java b/src/test/java/io/supertokens/test/mfa/api/DisableFactorAPITest.java deleted file mode 100644 index 946bc73c2..000000000 --- a/src/test/java/io/supertokens/test/mfa/api/DisableFactorAPITest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.mfa.api; - -import com.google.gson.JsonObject; -import io.supertokens.test.TestingProcessManager; -import io.supertokens.test.httpRequest.HttpResponseException; -import io.supertokens.test.mfa.MfaTestBase; -import org.junit.Test; - -import java.util.HashMap; - -import static org.junit.Assert.assertThrows; - -public class DisableFactorAPITest extends MfaTestBase { - private HttpResponseException disableFactorRequestAndReturnException(TestingProcessManager.TestingProcess process, JsonObject body) { - return assertThrows( - HttpResponseException.class, - () -> disableFactorRequest(process, body)); - } - - @Test - public void testApi() throws Exception { - TestSetupResult result = initSteps(); - assert result != null; - - // Prepare by enabling 2 factors for a user - { - JsonObject body = new JsonObject(); - body.addProperty("userId", "userId"); - body.addProperty("factor", "f1"); - enableFactorRequest(result.process, body); - - body.addProperty("factor", "f2"); - enableFactorRequest(result.process, body); - } - - JsonObject body = new JsonObject(); - // Missing userId/factor - { - Exception e = disableFactorRequestAndReturnException(result.process, body); - checkFieldMissingErrorResponse(e, "userId"); - - body.addProperty("userId", ""); - e = disableFactorRequestAndReturnException(result.process, body); - checkFieldMissingErrorResponse(e, "factor"); - } - // Invalid userId/factor - { - body.addProperty("factor", ""); - Exception e = disableFactorRequestAndReturnException(result.process, body); - checkResponseErrorContains(e, "userId cannot be empty"); - - body.addProperty("userId", "userId"); - e = disableFactorRequestAndReturnException(result.process, body); - checkResponseErrorContains(e, "factor cannot be empty"); - } - - body.addProperty("factor", "f1"); - // Should pass now: - JsonObject res = disableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == true; - - // Repeat the same request, should pass but wasAlreadyEnabled should be true - res = disableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == false; - - HashMap params = new HashMap<>(); - params.put("userId", "userId"); - - // Check that the factor was actually disabled - res = listFactorsRequest(result.process, params); - assert res.get("status").getAsString().equals("OK"); - assert res.get("factors").getAsJsonArray().size() == 1; - assert res.get("factors").getAsJsonArray().get(0).getAsString().equals("f2"); - } -} diff --git a/src/test/java/io/supertokens/test/mfa/api/EnableFactorAPITest.java b/src/test/java/io/supertokens/test/mfa/api/EnableFactorAPITest.java deleted file mode 100644 index 3ee31052d..000000000 --- a/src/test/java/io/supertokens/test/mfa/api/EnableFactorAPITest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.mfa.api; - -import com.google.gson.JsonObject; -import io.supertokens.test.TestingProcessManager; -import io.supertokens.test.httpRequest.HttpResponseException; -import io.supertokens.test.mfa.MfaTestBase; -import org.junit.Test; - -import java.util.HashMap; - -import static org.junit.Assert.assertThrows; - -public class EnableFactorAPITest extends MfaTestBase { - private HttpResponseException enableFactorRequestAndReturnException(TestingProcessManager.TestingProcess process, JsonObject body) { - return assertThrows( - HttpResponseException.class, - () -> enableFactorRequest(process, body)); - } - - @Test - public void testApi() throws Exception { - TestSetupResult result = initSteps(); - assert result != null; - - JsonObject body = new JsonObject(); - // Missing userId/factor - { - Exception e = enableFactorRequestAndReturnException(result.process, body); - checkFieldMissingErrorResponse(e, "userId"); - - body.addProperty("userId", ""); - e = enableFactorRequestAndReturnException(result.process, body); - checkFieldMissingErrorResponse(e, "factor"); - } - // Invalid userId/factor - { - body.addProperty("factor", ""); - Exception e = enableFactorRequestAndReturnException(result.process, body); - checkResponseErrorContains(e, "userId cannot be empty"); - - body.addProperty("userId", "userId"); - e = enableFactorRequestAndReturnException(result.process, body); - checkResponseErrorContains(e, "factor cannot be empty"); - } - - body.addProperty("factor", "f1"); - // Should pass now: - JsonObject res = enableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == false; - - // Repeat the same request, should pass but didExist should be true - res = enableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == true; - - // Check that the factors were actually enabled - { - HashMap params = new HashMap<>(); - params.put("userId", "userId"); - res = listFactorsRequest(result.process, params); - assert res.get("status").getAsString().equals("OK"); - assert res.get("factors").getAsJsonArray().size() == 1; - assert res.get("factors").getAsJsonArray().get(0).getAsString().equals("f1"); - } - - } -} diff --git a/src/test/java/io/supertokens/test/mfa/api/ListFactorsAPITest.java b/src/test/java/io/supertokens/test/mfa/api/ListFactorsAPITest.java deleted file mode 100644 index 0a629627a..000000000 --- a/src/test/java/io/supertokens/test/mfa/api/ListFactorsAPITest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.mfa.api; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import io.supertokens.Main; -import io.supertokens.pluginInterface.mfa.MfaStorage; -import io.supertokens.test.TestingProcessManager; -import io.supertokens.test.httpRequest.HttpResponseException; -import io.supertokens.test.mfa.MfaTestBase; -import org.junit.Test; - -import java.util.HashMap; - -import static org.junit.Assert.assertThrows; - -public class ListFactorsAPITest extends MfaTestBase { - - private HttpResponseException listFactorsRequestAndReturnException(TestingProcessManager.TestingProcess process, HashMap params) { - return assertThrows( - HttpResponseException.class, - () -> listFactorsRequest(process, params)); - } - @Test - public void testApi() throws Exception { - TestSetupResult result = initSteps(); - assert result != null; - - MfaStorage storage = result.storage; - Main main = result.process.main; - - // Prepare by enabling a factor for a user: - { - JsonObject body = new JsonObject(); - body.addProperty("userId", "userId"); - body.addProperty("factor", "f1"); - enableFactorRequest(result.process, body); - } - - HashMap params = new HashMap<>(); - - // Missing userId - { - Exception e = listFactorsRequestAndReturnException(result.process, params); - checkResponseErrorContains(e, "Field name 'userId' is missing in GET request"); - } - // Invalid userId - { - params.put("userId", ""); - Exception e = listFactorsRequestAndReturnException(result.process, params); - checkResponseErrorContains(e, "userId cannot be empty"); - } - - params.put("userId", "userId"); - JsonObject res = listFactorsRequest(result.process, params); - assert res.get("status").getAsString().equals("OK"); - - JsonArray factors = res.get("factors").getAsJsonArray(); - String factor = factors.get(0).getAsString(); - - assert factors.size() == 1; - assert factor.equals("f1"); - - // Try for a non-existing user: - { - params.put("userId", "userId2"); - res = listFactorsRequest(result.process, params); - assert res.get("status").getAsString().equals("OK"); - - factors = res.get("factors").getAsJsonArray(); - assert factors.size() == 0; - } - } -} diff --git a/src/test/java/io/supertokens/test/mfa/api/MfaUserIdMappingTest.java b/src/test/java/io/supertokens/test/mfa/api/MfaUserIdMappingTest.java deleted file mode 100644 index ec60ff654..000000000 --- a/src/test/java/io/supertokens/test/mfa/api/MfaUserIdMappingTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.mfa.api; - -import com.google.gson.JsonObject; -import io.supertokens.Main; -import io.supertokens.emailpassword.EmailPassword; -import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; -import io.supertokens.test.mfa.MfaTestBase; -import io.supertokens.useridmapping.UserIdMapping; -import org.junit.Test; - -import java.util.HashMap; - -public class MfaUserIdMappingTest extends MfaTestBase { - @Test - public void testExternalUserIdTranslation() throws Exception { - TestSetupResult result = initSteps(true); - Main main = result.process.getProcess(); - - JsonObject body = new JsonObject(); - AuthRecipeUserInfo user = EmailPassword.signUp(main, "test@example.com", "testPass123"); - String superTokensUserId = user.getSupertokensUserId(); - String externalUserId = "external-user-id"; - - // Create user id mapping first: - UserIdMapping.createUserIdMapping(main, superTokensUserId, externalUserId, null, false); - - body.addProperty("userId", superTokensUserId); - body.addProperty("factor", "f1"); - - // Enable factor f1 for user (use superTokensUserId for this): - JsonObject res = enableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == false; - - // Now use external user for all requests instead of superTokensUserId: - body.addProperty("userId", externalUserId); - - // Enable factor f2 for user: - body.addProperty("factor", "f2"); - res = enableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == false; - - // List factors for user: - HashMap params = new HashMap<>(); - params.put("userId", externalUserId); - res = listFactorsRequest(result.process, params); - assert res.get("status").getAsString().equals("OK"); - assert res.get("factors").getAsJsonArray().size() == 2; - assert res.get("factors").getAsJsonArray().get(0).getAsString().equals("f1"); - assert res.get("factors").getAsJsonArray().get(1).getAsString().equals("f2"); - - // Disable factor f1 for user: - body.addProperty("factor", "f1"); - res = disableFactorRequest(result.process, body); - assert res.get("status").getAsString().equals("OK"); - assert res.get("didExist").getAsBoolean() == true; - - // List factors for user: - res = listFactorsRequest(result.process, params); - assert res.get("status").getAsString().equals("OK"); - assert res.get("factors").getAsJsonArray().size() == 1; - assert res.get("factors").getAsJsonArray().get(0).getAsString().equals("f2"); - } -} diff --git a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java index e1c7f9e0c..442eafaac 100644 --- a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java +++ b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java @@ -26,6 +26,7 @@ import io.supertokens.pluginInterface.ActiveUsersStorage; import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; +import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; import io.supertokens.storageLayer.StorageLayer; @@ -66,7 +67,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); FeatureFlagTestContent.getInstance(process.getProcess()) .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{ - EE_FEATURES.MULTI_TENANCY, EE_FEATURES.TOTP}); + EE_FEATURES.MULTI_TENANCY, EE_FEATURES.MFA}); process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); @@ -76,7 +77,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { // this list contains the package names for recipes which dont use UserIdMapping ArrayList classesToSkip = new ArrayList<>( - List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName())); + List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName(), + MfaStorage.class.getName())); Reflections reflections = new Reflections("io.supertokens.pluginInterface"); Set> classes = reflections.getSubTypesOf(NonAuthRecipeStorage.class); @@ -171,7 +173,7 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); FeatureFlagTestContent.getInstance(process.getProcess()) .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{ - EE_FEATURES.MULTI_TENANCY, EE_FEATURES.TOTP}); + EE_FEATURES.MULTI_TENANCY, EE_FEATURES.MFA}); process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); @@ -181,7 +183,7 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception // this list contains the package names for recipes which dont use UserIdMapping ArrayList classesToSkip = new ArrayList<>( - List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName())); + List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName(), MfaStorage.class.getName())); Reflections reflections = new Reflections("io.supertokens.pluginInterface"); Set> classes = reflections.getSubTypesOf(NonAuthRecipeStorage.class); @@ -258,7 +260,7 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); FeatureFlagTestContent.getInstance(process.getProcess()) .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{ - EE_FEATURES.MULTI_TENANCY, EE_FEATURES.TOTP}); + EE_FEATURES.MULTI_TENANCY, EE_FEATURES.MFA}); process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); diff --git a/src/test/java/io/supertokens/test/multitenant/TestAppData.java b/src/test/java/io/supertokens/test/multitenant/TestAppData.java index 225df2491..cf69c38f9 100644 --- a/src/test/java/io/supertokens/test/multitenant/TestAppData.java +++ b/src/test/java/io/supertokens/test/multitenant/TestAppData.java @@ -96,7 +96,7 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { TestingProcessManager.TestingProcess process = TestingProcessManager.start(args, false); FeatureFlagTestContent.getInstance(process.getProcess()) .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, - new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY, EE_FEATURES.TOTP, EE_FEATURES.MFA}); + new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY, EE_FEATURES.MFA}); process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); @@ -167,9 +167,6 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { UserIdMapping.createUserIdMapping(process.getProcess(), appWithStorage.toAppIdentifierWithStorage(), plUser.user.getSupertokensUserId(), "externalid", null, false); - Mfa.enableFactor(appWithStorage, process.getProcess(), - epUser.getSupertokensUserId(), "emailpassword"); - String[] tablesThatHaveData = appWithStorage.getStorage() .getAllTablesInTheDatabaseThatHasDataForAppId(app.getAppId()); tablesThatHaveData = removeStrings(tablesThatHaveData, tablesToIgnore); diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java b/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java index 9c86c127e..d5c4360ec 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java @@ -33,6 +33,7 @@ import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.jwt.JWTRecipeStorage; +import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; @@ -197,8 +198,10 @@ public void testUserDisassociationForNotAuthRecipes() throws Exception { } if (name.equals(UserMetadataStorage.class.getName()) - || name.equals(JWTRecipeStorage.class.getName()) || - name.equals(ActiveUsersStorage.class.getName())) { + || name.equals(JWTRecipeStorage.class.getName()) + || name.equals(ActiveUsersStorage.class.getName()) + || name.equals(MfaStorage.class.getName()) + ) { // user metadata is app specific and does not have any tenant specific data // JWT storage does not have any user specific data // Active users storage does not have tenant specific data diff --git a/src/test/java/io/supertokens/test/totp/TOTPRecipeTest.java b/src/test/java/io/supertokens/test/totp/TOTPRecipeTest.java index 0b589bec9..f926d2267 100644 --- a/src/test/java/io/supertokens/test/totp/TOTPRecipeTest.java +++ b/src/test/java/io/supertokens/test/totp/TOTPRecipeTest.java @@ -98,7 +98,7 @@ public TestSetupResult defaultInit() TOTPStorage storage = (TOTPStorage) StorageLayer.getStorage(process.getProcess()); FeatureFlagTestContent.getInstance(process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.TOTP}); + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); return new TestSetupResult(storage, process); } @@ -325,7 +325,7 @@ public void rateLimitCooldownTest() throws Exception { } FeatureFlagTestContent.getInstance(process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.TOTP}); + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); Main main = process.getProcess(); diff --git a/src/test/java/io/supertokens/test/totp/TOTPStorageTest.java b/src/test/java/io/supertokens/test/totp/TOTPStorageTest.java index e03169d2a..38297710a 100644 --- a/src/test/java/io/supertokens/test/totp/TOTPStorageTest.java +++ b/src/test/java/io/supertokens/test/totp/TOTPStorageTest.java @@ -68,7 +68,7 @@ public TestSetupResult initSteps() TOTPSQLStorage storage = (TOTPSQLStorage) StorageLayer.getStorage(process.getProcess()); FeatureFlagTestContent.getInstance(process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.TOTP}); + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); return new TestSetupResult(storage, process); } diff --git a/src/test/java/io/supertokens/test/totp/TotpLicenseTest.java b/src/test/java/io/supertokens/test/totp/TotpLicenseTest.java index d612bd40e..889eb02f6 100644 --- a/src/test/java/io/supertokens/test/totp/TotpLicenseTest.java +++ b/src/test/java/io/supertokens/test/totp/TotpLicenseTest.java @@ -42,8 +42,7 @@ import static org.junit.Assert.assertThrows; public class TotpLicenseTest { - public final static String OPAQUE_KEY_WITH_TOTP_FEATURE = "pXhNK=nYiEsb6gJEOYP2kIR6M0kn4XLvNqcwT1XbX8xHtm44K" + - "-lQfGCbaeN0Ieeza39fxkXr=tiiUU=DXxDH40Y=4FLT4CE-rG1ETjkXxO4yucLpJvw3uSegPayoISGL"; + public final static String OPAQUE_KEY_WITH_MFA_FEATURE = "Qk8olVa=v-9PU=snnUFMF4ihMCx4zVBOO6Jd7Nrg6Cg5YyFliEj252ADgpwEpDLfFowA0U5OyVo3XL=U4FMft2HDHCDGg9hWD4iwQQiyjMRi6Mu03CVbAxIkNGaXtJ53"; @Rule public TestRule watchman = Utils.getOnFailure(); @@ -126,7 +125,7 @@ public void testTotpWithoutLicense() throws Exception { } ); assert e.statusCode == 402; - assert e.getMessage().contains("TOTP feature is not enabled"); + assert e.getMessage().contains("MFA feature is not enabled"); // Try to verify code via API: @@ -151,7 +150,7 @@ public void testTotpWithoutLicense() throws Exception { } ); assert e2.statusCode == 402; - assert e2.getMessage().contains("TOTP feature is not enabled"); + assert e2.getMessage().contains("MFA feature is not enabled"); } @@ -162,7 +161,7 @@ public void testTotpWithLicense() throws Exception { return; } FeatureFlagTestContent.getInstance(result.process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.TOTP}); + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); Main main = result.process.getProcess(); diff --git a/src/test/java/io/supertokens/test/totp/api/CreateTotpDeviceAPITest.java b/src/test/java/io/supertokens/test/totp/api/CreateTotpDeviceAPITest.java index 4aa922e2d..17e6fe29e 100644 --- a/src/test/java/io/supertokens/test/totp/api/CreateTotpDeviceAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/CreateTotpDeviceAPITest.java @@ -81,9 +81,9 @@ public void testApi() throws Exception { } FeatureFlag.getInstance(process.main) - .setLicenseKeyAndSyncFeatures(TotpLicenseTest.OPAQUE_KEY_WITH_TOTP_FEATURE); + .setLicenseKeyAndSyncFeatures(TotpLicenseTest.OPAQUE_KEY_WITH_MFA_FEATURE); FeatureFlagTestContent.getInstance(process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.TOTP}); + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { return; diff --git a/src/test/java/io/supertokens/test/totp/api/GetTotpDevicesAPITest.java b/src/test/java/io/supertokens/test/totp/api/GetTotpDevicesAPITest.java index 0ea0f8387..e48ba2b29 100644 --- a/src/test/java/io/supertokens/test/totp/api/GetTotpDevicesAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/GetTotpDevicesAPITest.java @@ -77,7 +77,7 @@ public void testApi() throws Exception { TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); - FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.TOTP }); + FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.MFA }); if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { return; 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 df8cac9fb..51c3549c2 100644 --- a/src/test/java/io/supertokens/test/totp/api/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/MultitenantAPITest.java @@ -75,7 +75,7 @@ public void beforeEach() throws InterruptedException, InvalidProviderConfigExcep this.process = TestingProcessManager.start(args); FeatureFlagTestContent.getInstance(process.getProcess()) .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{ - EE_FEATURES.MULTI_TENANCY, EE_FEATURES.TOTP}); + EE_FEATURES.MULTI_TENANCY, EE_FEATURES.MFA}); process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); diff --git a/src/test/java/io/supertokens/test/totp/api/RemoveTotpDeviceAPITest.java b/src/test/java/io/supertokens/test/totp/api/RemoveTotpDeviceAPITest.java index bb4a13a53..aa92e4ad0 100644 --- a/src/test/java/io/supertokens/test/totp/api/RemoveTotpDeviceAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/RemoveTotpDeviceAPITest.java @@ -78,7 +78,7 @@ public void testApi() throws Exception { } FeatureFlagTestContent.getInstance(process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.TOTP}); + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); // Setup user and devices: JsonObject createDeviceReq = new JsonObject(); diff --git a/src/test/java/io/supertokens/test/totp/api/TotpUserIdMappingTest.java b/src/test/java/io/supertokens/test/totp/api/TotpUserIdMappingTest.java index 112cd0c14..f3b0d0ad6 100644 --- a/src/test/java/io/supertokens/test/totp/api/TotpUserIdMappingTest.java +++ b/src/test/java/io/supertokens/test/totp/api/TotpUserIdMappingTest.java @@ -48,7 +48,7 @@ public void testExternalUserIdTranslation() throws Exception { return; } - FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.TOTP }); + FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.MFA }); JsonObject body = new JsonObject(); diff --git a/src/test/java/io/supertokens/test/totp/api/UpdateTotpDeviceAPITest.java b/src/test/java/io/supertokens/test/totp/api/UpdateTotpDeviceAPITest.java index 29be8c12c..27c5f9fea 100644 --- a/src/test/java/io/supertokens/test/totp/api/UpdateTotpDeviceAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/UpdateTotpDeviceAPITest.java @@ -76,7 +76,7 @@ public void testApi() throws Exception { return; } - FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.TOTP }); + FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.MFA }); // Setup user and devices: JsonObject createDeviceReq = new JsonObject(); diff --git a/src/test/java/io/supertokens/test/totp/api/VerifyTotpAPITest.java b/src/test/java/io/supertokens/test/totp/api/VerifyTotpAPITest.java index 08c836586..a17eee38b 100644 --- a/src/test/java/io/supertokens/test/totp/api/VerifyTotpAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/VerifyTotpAPITest.java @@ -88,7 +88,7 @@ public void testApi() throws Exception { } FeatureFlagTestContent.getInstance(process.main) - .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.TOTP}); + .setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[]{EE_FEATURES.MFA}); // Setup user and devices: JsonObject createDeviceReq = new JsonObject(); diff --git a/src/test/java/io/supertokens/test/totp/api/VerifyTotpDeviceAPITest.java b/src/test/java/io/supertokens/test/totp/api/VerifyTotpDeviceAPITest.java index ca5e1c43b..b29f187fe 100644 --- a/src/test/java/io/supertokens/test/totp/api/VerifyTotpDeviceAPITest.java +++ b/src/test/java/io/supertokens/test/totp/api/VerifyTotpDeviceAPITest.java @@ -84,7 +84,7 @@ public void testApi() throws Exception { return; } - FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.TOTP }); + FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.MFA }); // Setup user and devices: JsonObject createDeviceReq = new JsonObject(); diff --git a/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java b/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java index 9a6cfb33a..96d9fa5db 100644 --- a/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java +++ b/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java @@ -25,6 +25,7 @@ import io.supertokens.pluginInterface.ActiveUsersStorage; import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; +import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; @@ -791,11 +792,12 @@ public void checkThatCreateUserIdMappingHasAllNonAuthRecipeChecks() throws Excep return; } - FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.TOTP }); + FeatureFlagTestContent.getInstance(process.main).setKeyValue(FeatureFlagTestContent.ENABLED_FEATURES, new EE_FEATURES[] { EE_FEATURES.MFA }); // this list contains the package names for recipes which dont use UserIdMapping ArrayList nonAuthRecipesWhichDontNeedUserIdMapping = new ArrayList<>( - List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName())); + List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName(), + MfaStorage.class.getName())); Reflections reflections = new Reflections("io.supertokens.pluginInterface"); Set> classes = reflections.getSubTypesOf(NonAuthRecipeStorage.class); From 69817f465dc81f3e24205703501998584123bcd7 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 12 Oct 2023 16:03:02 +0530 Subject: [PATCH 03/16] fix: mfa cleanup --- .../java/io/supertokens/inmemorydb/Start.java | 13 +-- .../inmemorydb/config/SQLiteConfig.java | 4 - .../queries/ActiveUsersQueries.java | 28 +----- .../inmemorydb/queries/GeneralQueries.java | 5 -- .../inmemorydb/queries/MfaQueries.java | 90 ------------------- 5 files changed, 4 insertions(+), 136 deletions(-) diff --git a/src/main/java/io/supertokens/inmemorydb/Start.java b/src/main/java/io/supertokens/inmemorydb/Start.java index d3dbcf90f..afed4d279 100644 --- a/src/main/java/io/supertokens/inmemorydb/Start.java +++ b/src/main/java/io/supertokens/inmemorydb/Start.java @@ -619,12 +619,7 @@ public boolean isUserIdBeingUsedInNonAuthRecipe(AppIdentifier appIdentifier, Str } else if (className.equals(JWTRecipeStorage.class.getName())) { return false; } else if (className.equals(MfaStorage.class.getName())) { - try { - MultitenancyQueries.getAllTenants(this); - return MfaQueries.listFactors(this, appIdentifier, userId).length > 0; - } catch (SQLException e) { - throw new StorageQueryException(e); - } + return false; /* nothing here */ } else { throw new IllegalStateException("ClassName: " + className + " is not part of NonAuthRecipeStorage"); } @@ -724,11 +719,7 @@ public void addInfoToNonAuthRecipesBasedOnUserId(TenantIdentifier tenantIdentifi throw new StorageQueryException(e); } } else if (className.equals(MfaStorage.class.getName())) { - try { - MfaQueries.enableFactor(this, tenantIdentifier, userId, "emailpassword"); - } catch (SQLException e) { - throw new StorageQueryException(e); - } + /* nothing here */ } else { throw new IllegalStateException("ClassName: " + className + " is not part of NonAuthRecipeStorage"); } diff --git a/src/main/java/io/supertokens/inmemorydb/config/SQLiteConfig.java b/src/main/java/io/supertokens/inmemorydb/config/SQLiteConfig.java index ada466d1f..25fd59c61 100644 --- a/src/main/java/io/supertokens/inmemorydb/config/SQLiteConfig.java +++ b/src/main/java/io/supertokens/inmemorydb/config/SQLiteConfig.java @@ -141,10 +141,6 @@ public String getTotpUsersTable() { return "totp_users"; } - public String getMfaUserFactorsTable() { - return "mfa_user_factors"; - } - public String getTotpUserDevicesTable() { return "totp_user_devices"; } diff --git a/src/main/java/io/supertokens/inmemorydb/queries/ActiveUsersQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/ActiveUsersQueries.java index 3bb08ca1f..81b14e7f5 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/ActiveUsersQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/ActiveUsersQueries.java @@ -96,35 +96,11 @@ public static int countUsersEnabledTotpAndActiveSince(Start start, AppIdentifier } public static int countUsersEnabledMfa(Start start, AppIdentifier appIdentifier) throws SQLException, StorageQueryException { - String QUERY = "SELECT COUNT(*) as total FROM (SELECT DISTINCT user_id FROM " + Config.getConfig(start).getMfaUserFactorsTable() + " WHERE app_id = ?) AS app_mfa_users"; - - return execute(start, QUERY, pst -> { - pst.setString(1, appIdentifier.getAppId()); - }, result -> { - if (result.next()) { - return result.getInt("total"); - } - return 0; - }); + return 0; // TODO } public static int countUsersEnabledMfaAndActiveSince(Start start, AppIdentifier appIdentifier, long sinceTime) throws SQLException, StorageQueryException { - // Find unique users from mfa_user_factors table and join with user_last_active table - String QUERY = "SELECT COUNT(*) as total FROM (SELECT DISTINCT user_id FROM " + Config.getConfig(start).getMfaUserFactorsTable() + ") AS mfa_users " - + "INNER JOIN " + Config.getConfig(start).getUserLastActiveTable() + " AS user_last_active " - + "ON mfa_users.user_id = user_last_active.user_id " - + "WHERE user_last_active.app_id = ?" - + "AND user_last_active.last_active_time >= ?"; - - return execute(start, QUERY, pst -> { - pst.setString(1, appIdentifier.getAppId()); - pst.setLong(2, sinceTime); - }, result -> { - if (result.next()) { - return result.getInt("total"); - } - return 0; - }); + return 0; // TODO } public static int updateUserLastActive(Start start, AppIdentifier appIdentifier, String userId) diff --git a/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java index 0a203eef7..26b39e54b 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/GeneralQueries.java @@ -406,11 +406,6 @@ public static void createTablesIfNotExists(Start start, Main main) throws SQLExc // index: update(start, TOTPQueries.getQueryToCreateUsedCodesExpiryTimeIndex(start), NO_OP_SETTER); } - - if (!doesTableExists(start, Config.getConfig(start).getMfaUserFactorsTable())) { - getInstance(main).addState(CREATING_NEW_TABLE, null); - update(start, MfaQueries.getQueryToCreateUserFactorsTable(start), NO_OP_SETTER); - } } diff --git a/src/main/java/io/supertokens/inmemorydb/queries/MfaQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/MfaQueries.java index 9cca4bf53..8e65b37a7 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/MfaQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/MfaQueries.java @@ -31,94 +31,4 @@ import static io.supertokens.inmemorydb.QueryExecutorTemplate.update; public class MfaQueries { - public static String getQueryToCreateUserFactorsTable(Start start) { - return "CREATE TABLE IF NOT EXISTS " + Config.getConfig(start).getMfaUserFactorsTable() + " (" - + "app_id VARCHAR(64) DEFAULT 'public'," - + "tenant_id VARCHAR(64) DEFAULT 'public'," - + "user_id VARCHAR(128) NOT NULL," - + "factor_id VARCHAR(64) NOT NULL," - + "PRIMARY KEY (app_id, tenant_id, user_id, factor_id)," - + "FOREIGN KEY (app_id, tenant_id)" - + "REFERENCES " + Config.getConfig(start).getTenantsTable() + " (app_id, tenant_id) ON DELETE CASCADE);"; - } - - public static int enableFactor(Start start, TenantIdentifier tenantIdentifier, String userId, String factorId) - throws StorageQueryException, SQLException { - String QUERY = "INSERT INTO " + Config.getConfig(start).getMfaUserFactorsTable() + " (app_id, tenant_id, user_id, factor_id) VALUES (?, ?, ?, ?) ON CONFLICT DO NOTHING"; - - return update(start, QUERY, pst -> { - pst.setString(1, tenantIdentifier.getAppId()); - pst.setString(2, tenantIdentifier.getTenantId()); - pst.setString(3, userId); - pst.setString(4, factorId); - }); - } - - - public static String[] listFactors(Start start, TenantIdentifier tenantIdentifier, String userId) - throws StorageQueryException, SQLException { - String QUERY = "SELECT factor_id FROM " + Config.getConfig(start).getMfaUserFactorsTable() + " WHERE app_id = ? AND tenant_id = ? AND user_id = ?"; - - return execute(start, QUERY, pst -> { - pst.setString(1, tenantIdentifier.getAppId()); - pst.setString(2, tenantIdentifier.getTenantId()); - pst.setString(3, userId); - }, result -> { - List factors = new ArrayList<>(); - while (result.next()) { - factors.add(result.getString("factor_id")); - } - - return factors.toArray(String[]::new); - }); - } - - public static String[] listFactors(Start start, AppIdentifier appIdentifier, String userId) - throws StorageQueryException, SQLException { - String QUERY = "SELECT factor_id FROM " + Config.getConfig(start).getMfaUserFactorsTable() + " WHERE app_id = ? AND user_id = ?"; - - return execute(start, QUERY, pst -> { - pst.setString(1, appIdentifier.getAppId()); - pst.setString(2, userId); - }, result -> { - List factors = new ArrayList<>(); - while (result.next()) { - factors.add(result.getString("factor_id")); - } - - return factors.toArray(String[]::new); - }); - } - - public static int disableFactor(Start start, TenantIdentifier tenantIdentifier, String userId, String factorId) - throws StorageQueryException, SQLException { - String QUERY = "DELETE FROM " + Config.getConfig(start).getMfaUserFactorsTable() + " WHERE app_id = ? AND tenant_id = ? AND user_id = ? AND factor_id = ?"; - - return update(start, QUERY, pst -> { - pst.setString(1, tenantIdentifier.getAppId()); - pst.setString(2, tenantIdentifier.getTenantId()); - pst.setString(3, userId); - pst.setString(4, factorId); - }); - } - - public static int deleteUser_Transaction(Start start, Connection sqlCon, AppIdentifier appIdentifier, String userId) throws StorageQueryException, SQLException { - String QUERY = "DELETE FROM " + Config.getConfig(start).getMfaUserFactorsTable() + " WHERE app_id = ? AND user_id = ?"; - - return update(sqlCon, QUERY, pst -> { - pst.setString(1, appIdentifier.getAppId()); - pst.setString(2, userId); - }); - } - - public static int deleteUserFromTenant(Start start, TenantIdentifier tenantIdentifier, String userId) - throws StorageQueryException, SQLException { - String QUERY = "DELETE FROM " + Config.getConfig(start).getMfaUserFactorsTable() + " WHERE app_id = ? AND tenant_id = ? AND user_id = ?"; - - return update(start, QUERY, pst -> { - pst.setString(1, tenantIdentifier.getAppId()); - pst.setString(2, tenantIdentifier.getTenantId()); - pst.setString(3, userId); - }); - } } From bab7139b20acca893af9aba0dd0cb1a9039a989f Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 12 Oct 2023 17:39:32 +0530 Subject: [PATCH 04/16] fix: test --- .../io/supertokens/test/FeatureFlagTest.java | 125 +----------------- 1 file changed, 7 insertions(+), 118 deletions(-) diff --git a/src/test/java/io/supertokens/test/FeatureFlagTest.java b/src/test/java/io/supertokens/test/FeatureFlagTest.java index 8c249464b..2c52f5d53 100644 --- a/src/test/java/io/supertokens/test/FeatureFlagTest.java +++ b/src/test/java/io/supertokens/test/FeatureFlagTest.java @@ -21,10 +21,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.supertokens.ProcessState; -import io.supertokens.cronjobs.CronTask; -import io.supertokens.cronjobs.CronTaskTest; -import io.supertokens.cronjobs.Cronjobs; -import io.supertokens.cronjobs.syncCoreConfigWithDb.SyncCoreConfigWithDb; import io.supertokens.emailpassword.EmailPassword; import io.supertokens.featureflag.EE_FEATURES; import io.supertokens.featureflag.FeatureFlag; @@ -32,9 +28,7 @@ import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; import io.supertokens.featureflag.exceptions.NoLicenseKeyFoundException; import io.supertokens.multitenancy.Multitenancy; -import io.supertokens.multitenancy.MultitenancyHelper; import io.supertokens.pluginInterface.STORAGE_TYPE; -import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; @@ -159,9 +153,6 @@ public void testThatCallingGetFeatureFlagAPIReturnsEmptyArray() throws Exception Assert.assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); } - private final String OPAQUE_KEY_WITH_TOTP_FEATURE = "pXhNK=nYiEsb6gJEOYP2kIR6M0kn4XLvNqcwT1XbX8xHtm44K" + - "-lQfGCbaeN0Ieeza39fxkXr=tiiUU=DXxDH40Y=4FLT4CE-rG1ETjkXxO4yucLpJvw3uSegPayoISGL"; - @Test public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception { String[] args = {"../"}; @@ -173,7 +164,7 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception return; } - FeatureFlag.getInstance(process.main).setLicenseKeyAndSyncFeatures(OPAQUE_KEY_WITH_TOTP_FEATURE); + FeatureFlag.getInstance(process.main).setLicenseKeyAndSyncFeatures(OPAQUE_KEY_WITH_MFA_FEATURE); // Get the stats without any users/activity { @@ -191,12 +182,12 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception } else { assert features.size() == 1; } - assert features.contains(new JsonPrimitive("totp")); + assert features.contains(new JsonPrimitive("mfa")); assert maus.size() == 30; assert maus.get(0).getAsInt() == 0; assert maus.get(29).getAsInt() == 0; - JsonObject totpStats = usageStats.get("totp").getAsJsonObject(); + JsonObject totpStats = usageStats.get("mfa").getAsJsonObject().get("totp").getAsJsonObject(); JsonArray totpMaus = totpStats.get("maus").getAsJsonArray(); int totalTotpUsers = totpStats.get("total_users").getAsInt(); @@ -250,12 +241,12 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception assert features.size() == 1; } - assert features.contains(new JsonPrimitive("totp")); + assert features.contains(new JsonPrimitive("mfa")); assert maus.size() == 30; assert maus.get(0).getAsInt() == 2; // 2 users have signed up assert maus.get(29).getAsInt() == 2; - JsonObject totpStats = usageStats.get("totp").getAsJsonObject(); + JsonObject totpStats = usageStats.get("mfa").getAsJsonObject().get("totp").getAsJsonObject(); JsonArray totpMaus = totpStats.get("maus").getAsJsonArray(); int totalTotpUsers = totpStats.get("total_users").getAsInt(); @@ -273,107 +264,6 @@ public void testThatCallingGetFeatureFlagAPIReturnsTotpStats() throws Exception private final static String OPAQUE_KEY_WITH_MFA_FEATURE = "Qk8olVa=v-9PU=snnUFMF4ihMCx4zVBOO6Jd7Nrg6Cg5YyFliEj252ADgpwEpDLfFowA0U5OyVo3XL=U4FMft2HDHCDGg9hWD4iwQQiyjMRi6Mu03CVbAxIkNGaXtJ53"; - @Test - public void testThatCallingGetFeatureFlagAPIReturnsMfaStats() throws Exception { - String[] args = {"../"}; - - TestingProcessManager.TestingProcess process = TestingProcessManager.start(args); - Assert.assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); - - if (StorageLayer.getStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { - return; - } - - FeatureFlag.getInstance(process.main).setLicenseKeyAndSyncFeatures(OPAQUE_KEY_WITH_MFA_FEATURE); - - // Get the stats without any users/activity - { - JsonObject response = HttpRequestForTesting.sendGETRequest(process.getProcess(), "", - "http://localhost:3567/ee/featureflag", - null, 1000, 1000, null, WebserverAPI.getLatestCDIVersion().get(), ""); - Assert.assertEquals("OK", response.get("status").getAsString()); - - JsonArray features = response.get("features").getAsJsonArray(); - JsonObject usageStats = response.get("usageStats").getAsJsonObject(); - JsonArray maus = usageStats.get("maus").getAsJsonArray(); - - if (!StorageLayer.isInMemDb(process.getProcess())) { - assert features.size() == 1; - assert features.get(0).getAsString().equals("mfa"); - } - assert maus.size() == 30; - assert maus.get(0).getAsInt() == 0; - assert maus.get(29).getAsInt() == 0; - - JsonObject mfaStats = usageStats.get("mfa").getAsJsonObject(); - JsonArray mfaMaus = mfaStats.get("maus").getAsJsonArray(); - int totaMfaUsers = mfaStats.get("total_users").getAsInt(); - - assert mfaMaus.size() == 30; - assert mfaMaus.get(0).getAsInt() == 0; - assert mfaMaus.get(29).getAsInt() == 0; - - assert totaMfaUsers == 0; - } - - // First register 2 users for emailpassword recipe. - // This also marks them as active. - JsonObject signUpResponse = Utils.signUpRequest_2_5(process, "random@gmail.com", "validPass123"); - assert signUpResponse.get("status").getAsString().equals("OK"); - - JsonObject signUpResponse2 = Utils.signUpRequest_2_5(process, "random2@gmail.com", "validPass123"); - assert signUpResponse2.get("status").getAsString().equals("OK"); - - // Now enable MFA for the first user by enabling a factor. - JsonObject body = new JsonObject(); - body.addProperty("userId", signUpResponse.get("user").getAsJsonObject().get("id").getAsString()); - body.addProperty("factor", "f1"); - JsonObject res = HttpRequestForTesting.sendJsonPOSTRequest( - process.getProcess(), - "", - "http://localhost:3567/recipe/mfa/factors/enable", - body, - 1000, - 1000, - null, - Utils.getCdiVersionStringLatestForTests(), - "mfa"); - assert res.get("status").getAsString().equals("OK"); - - // Now check the stats again: - { - JsonObject response = HttpRequestForTesting.sendGETRequest(process.getProcess(), "", - "http://localhost:3567/ee/featureflag", - null, 1000, 1000, null, WebserverAPI.getLatestCDIVersion().get(), ""); - Assert.assertEquals("OK", response.get("status").getAsString()); - - JsonArray features = response.get("features").getAsJsonArray(); - JsonObject usageStats = response.get("usageStats").getAsJsonObject(); - JsonArray maus = usageStats.get("maus").getAsJsonArray(); - - if (!StorageLayer.isInMemDb(process.getProcess())) { - assert features.size() == 1; - assert features.get(0).getAsString().equals("mfa"); - } - assert maus.size() == 30; - assert maus.get(0).getAsInt() == 2; // 2 users have signed up - assert maus.get(29).getAsInt() == 2; - - JsonObject mfaStats = usageStats.get("mfa").getAsJsonObject(); - JsonArray mfaMaus = mfaStats.get("maus").getAsJsonArray(); - int totalMfaUsers = mfaStats.get("total_users").getAsInt(); - - assert mfaMaus.size() == 30; - assert mfaMaus.get(0).getAsInt() == 1; // only 1 user has MFA factor enabled - assert mfaMaus.get(29).getAsInt() == 1; - - assert totalMfaUsers == 1; - } - - process.kill(); - Assert.assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); - } - private final String OPAQUE_KEY_WITH_MULTITENANCY_FEATURE = "ijaleljUd2kU9XXWLiqFYv5br8nutTxbyBqWypQdv2N-" + "BocoNriPrnYQd0NXPm8rVkeEocN9ayq0B7c3Pv-BTBIhAZSclXMlgyfXtlwAOJk=9BfESEleW6LyTov47dXu"; @@ -871,10 +761,9 @@ public void testPaidStatsContainsAllEnabledFeatures() throws Exception { String[] licenses = new String[]{ OPAQUE_KEY_WITH_MULTITENANCY_FEATURE, - OPAQUE_KEY_WITH_TOTP_FEATURE, + OPAQUE_KEY_WITH_MFA_FEATURE, OPAQUE_KEY_WITH_DASHBOARD_FEATURE, - OPAQUE_KEY_WITH_ACCOUNT_LINKING_FEATURE, - OPAQUE_KEY_WTIH_MFA_FEATURE + OPAQUE_KEY_WITH_ACCOUNT_LINKING_FEATURE }; Set requiredFeatures = new HashSet<>(); From 2ebe359cab17439af17c166cd3b4262bf104c092 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 13 Oct 2023 12:08:14 +0530 Subject: [PATCH 05/16] fix: api --- coreDriverInterfaceSupported.json | 3 ++- .../java/io/supertokens/utils/SemVer.java | 1 + .../supertokens/webserver/WebserverAPI.java | 3 ++- .../multitenancy/CreateOrUpdateAppAPI.java | 15 +++++++++---- .../CreateOrUpdateConnectionUriDomainAPI.java | 15 +++++++++---- .../CreateOrUpdateTenantOrGetTenantAPI.java | 21 ++++++++++++++----- 6 files changed, 43 insertions(+), 15 deletions(-) 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/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/CreateOrUpdateAppAPI.java b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java index 425a0a161..4af87a98e 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -21,6 +21,7 @@ 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; @@ -54,12 +55,18 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean emailPasswordEnabled = InputParser.parseBooleanOrThrowError(input, "emailPasswordEnabled", true); Boolean thirdPartyEnabled = InputParser.parseBooleanOrThrowError(input, "thirdPartyEnabled", true); Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); - Boolean totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - String[] firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - String[] defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, - "defaultMFARequirements", true); JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); + Boolean totpEnabled = null; + String[] firstFactors = new String[0]; + String[] defaultMFARequirements = new String[0]; + + if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { + totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, "defaultMFARequirements", true); + } + TenantIdentifier sourceTenantIdentifier; try { sourceTenantIdentifier = this.getTenantIdentifierWithStorageFromRequest(req); 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 566184b1d..fca93f4dd 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -20,6 +20,7 @@ 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; @@ -52,12 +53,18 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean emailPasswordEnabled = InputParser.parseBooleanOrThrowError(input, "emailPasswordEnabled", true); Boolean thirdPartyEnabled = InputParser.parseBooleanOrThrowError(input, "thirdPartyEnabled", true); Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); - Boolean totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - String[] firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - String[] defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, - "defaultMFARequirements", true); JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); + Boolean totpEnabled = null; + String[] firstFactors = new String[0]; + String[] defaultMFARequirements = new String[0]; + + if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { + totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, "defaultMFARequirements", true); + } + TenantIdentifier sourceTenantIdentifier; try { sourceTenantIdentifier = this.getTenantIdentifierWithStorageFromRequest(req); 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 42aeccccc..44a64a338 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -22,6 +22,7 @@ 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; @@ -55,13 +56,18 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO Boolean emailPasswordEnabled = InputParser.parseBooleanOrThrowError(input, "emailPasswordEnabled", true); Boolean thirdPartyEnabled = InputParser.parseBooleanOrThrowError(input, "thirdPartyEnabled", true); Boolean passwordlessEnabled = InputParser.parseBooleanOrThrowError(input, "passwordlessEnabled", true); - Boolean totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - String[] firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - String[] defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, - "defaultMFARequirements", true); - JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); + Boolean totpEnabled = null; + String[] firstFactors = new String[0]; + String[] defaultMFARequirements = new String[0]; + + if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { + totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, "defaultMFARequirements", true); + } + TenantIdentifier sourceTenantIdentifier; try { sourceTenantIdentifier = this.getTenantIdentifierWithStorageFromRequest(req); @@ -89,6 +95,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(); From 388050d4ea71728927a24447bda5d676521cff6f Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 17 Oct 2023 18:07:32 +0530 Subject: [PATCH 06/16] fix: mfa multitenancy updates --- .../multitenancy/TenantConfigSQLHelper.java | 3 ++- .../api/multitenancy/BaseCreateOrUpdate.java | 9 +++++---- .../api/multitenancy/CreateOrUpdateAppAPI.java | 18 +++++++++++++----- .../CreateOrUpdateConnectionUriDomainAPI.java | 18 +++++++++++++----- .../CreateOrUpdateTenantOrGetTenantAPI.java | 18 +++++++++++++----- .../test/multitenant/AppTenantUserTest.java | 6 ++---- .../api/TestTenantUserAssociation.java | 1 - .../generator/GenerateMfaConfig.java | 18 +++++++++++++++--- .../test/userIdMapping/UserIdMappingTest.java | 4 +--- 9 files changed, 64 insertions(+), 31 deletions(-) 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 9dd93bab6..c026f9302 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java @@ -21,6 +21,7 @@ import io.supertokens.inmemorydb.queries.utils.JsonUtils; import io.supertokens.pluginInterface.RowMapper; import io.supertokens.pluginInterface.exceptions.StorageQueryException; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.*; import java.sql.Connection; @@ -54,7 +55,7 @@ public TenantConfig map(ResultSet result) throws StorageQueryException { new ThirdPartyConfig(result.getBoolean("third_party_enabled"), this.providers), new PasswordlessConfig(result.getBoolean("passwordless_enabled")), new TotpConfig(false), // TODO - new MfaConfig(new String[0], new String[0]), // TODO + new MfaConfig(new MfaFirstFactors(null, null), new String[0]), // TODO JsonUtils.stringToJsonObject(result.getString("core_config")) ); } catch (Exception e) { 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 a97eda87d..06cfb4a3f 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java @@ -26,6 +26,7 @@ import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.thirdparty.InvalidProviderConfigException; @@ -46,7 +47,7 @@ public BaseCreateOrUpdate(Main main) { protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdentifier, TenantIdentifier targetTenantIdentifier, Boolean emailPasswordEnabled, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, Boolean totpEnabled, - String[] firstFactors, String[] defaultMFARequirements, + MfaFirstFactors firstFactors, String[] defaultRequiredFactors, JsonObject coreConfig, HttpServletResponse resp) throws ServletException, IOException { @@ -138,19 +139,19 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - new MfaConfig(firstFactors, tenantConfig.mfaConfig.defaultMFARequirements), + new MfaConfig(firstFactors, tenantConfig.mfaConfig.defaultRequiredFactors), tenantConfig.coreConfig ); } - if (defaultMFARequirements != null) { + if (defaultRequiredFactors != null) { tenantConfig = new TenantConfig( tenantConfig.tenantIdentifier, tenantConfig.emailPasswordConfig, tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - new MfaConfig(tenantConfig.mfaConfig.firstFactors, defaultMFARequirements), + new MfaConfig(tenantConfig.mfaConfig.firstFactors, defaultRequiredFactors), tenantConfig.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 4af87a98e..00f78b9f7 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -19,6 +19,7 @@ import com.google.gson.JsonObject; import io.supertokens.Main; import io.supertokens.multitenancy.exception.BadPermissionException; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.utils.SemVer; @@ -58,13 +59,20 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); Boolean totpEnabled = null; - String[] firstFactors = new String[0]; - String[] defaultMFARequirements = new String[0]; + MfaFirstFactors firstFactors = new MfaFirstFactors(null, null); + String[] defaultRequiredFactors = null; if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, "defaultMFARequirements", true); + defaultRequiredFactors = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactors", true); + + try { + if (input.has("firstFactors")) { + firstFactors = MfaFirstFactors.fromJson(input.get("firstFactors")); + } + } catch (IllegalArgumentException e) { + throw new ServletException(new BadRequestException(e.getMessage())); + } } TenantIdentifier sourceTenantIdentifier; @@ -78,7 +86,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), appId, null), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultMFARequirements, + totpEnabled, firstFactors, defaultRequiredFactors, 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 fca93f4dd..fe564a228 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -18,6 +18,7 @@ import com.google.gson.JsonObject; import io.supertokens.Main; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.utils.SemVer; @@ -56,13 +57,20 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); Boolean totpEnabled = null; - String[] firstFactors = new String[0]; - String[] defaultMFARequirements = new String[0]; + MfaFirstFactors firstFactors = new MfaFirstFactors(null, null); + String[] defaultRequiredFactors = null; if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, "defaultMFARequirements", true); + defaultRequiredFactors = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactors", true); + + try { + if (input.has("firstFactors")) { + firstFactors = MfaFirstFactors.fromJson(input.get("firstFactors")); + } + } catch (IllegalArgumentException e) { + throw new ServletException(new BadRequestException(e.getMessage())); + } } TenantIdentifier sourceTenantIdentifier; @@ -76,7 +84,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(connectionUriDomain, null, null), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultMFARequirements, + totpEnabled, firstFactors, defaultRequiredFactors, 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 44a64a338..882a60cc9 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -20,6 +20,7 @@ import io.supertokens.Main; import io.supertokens.config.CoreConfig; import io.supertokens.multitenancy.Multitenancy; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.utils.SemVer; @@ -59,13 +60,20 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); Boolean totpEnabled = null; - String[] firstFactors = new String[0]; - String[] defaultMFARequirements = new String[0]; + MfaFirstFactors firstFactors = new MfaFirstFactors(null, null); + String[] defaultRequiredFactors = null; if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - defaultMFARequirements = InputParser.parseStringArrayOrThrowError(input, "defaultMFARequirements", true); + defaultRequiredFactors = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactors", true); + + try { + if (input.has("firstFactors")) { + firstFactors = MfaFirstFactors.fromJson(input.get("firstFactors")); + } + } catch (IllegalArgumentException e) { + throw new ServletException(new BadRequestException(e.getMessage())); + } } TenantIdentifier sourceTenantIdentifier; @@ -79,7 +87,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), sourceTenantIdentifier.getAppId(), tenantId), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultMFARequirements, + totpEnabled, firstFactors, defaultRequiredFactors, coreConfig, resp); } diff --git a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java index 62a9f8b6c..f781a9dff 100644 --- a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java +++ b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java @@ -26,7 +26,6 @@ import io.supertokens.pluginInterface.ActiveUsersStorage; import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; -import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; import io.supertokens.storageLayer.StorageLayer; @@ -77,8 +76,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { // this list contains the package names for recipes which dont use UserIdMapping ArrayList classesToSkip = new ArrayList<>( - List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName(), - MfaStorage.class.getName())); + List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName())); Reflections reflections = new Reflections("io.supertokens.pluginInterface"); Set> classes = reflections.getSubTypesOf(NonAuthRecipeStorage.class); @@ -187,7 +185,7 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception // this list contains the package names for recipes which dont use UserIdMapping ArrayList classesToSkip = new ArrayList<>( - List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName(), MfaStorage.class.getName())); + List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName())); Reflections reflections = new Reflections("io.supertokens.pluginInterface"); Set> classes = reflections.getSubTypesOf(NonAuthRecipeStorage.class); diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java b/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java index 1f79b3e78..0b2dcc3a7 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java @@ -33,7 +33,6 @@ import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.jwt.JWTRecipeStorage; -import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; diff --git a/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java b/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java index fea260357..e12b2b444 100644 --- a/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java +++ b/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java @@ -16,13 +16,24 @@ package io.supertokens.test.multitenant.generator; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; + import java.util.HashSet; import java.util.Random; import java.util.Set; public class GenerateMfaConfig { private static final String[] FACTORS = new String[]{ - "password", "otp-email", "otp-phone", "link-email", "link-phone", "totp", "thirdparty" + "emailpassword", + "thirdparty", + "otp-email", + "otp-phone", + "link-email", + "link-phone" + }; + + private static final String[] OTHER_FACTORS = new String[]{ + "totp", "biometric", "custom" }; private static String[] selectRandomElements(String[] inputArray) { @@ -55,13 +66,14 @@ private static String[] selectRandomElements(String[] inputArray) { public static ConfigGenerator.GeneratedValueAndExpectation generate_firstFactors() { String[] factors = selectRandomElements(FACTORS); + String[] customFactors = selectRandomElements(OTHER_FACTORS); return new ConfigGenerator.GeneratedValueAndExpectation( - factors, + new MfaFirstFactors(factors, customFactors), new ConfigGenerator.Expectation("ok", factors)); } - public static ConfigGenerator.GeneratedValueAndExpectation generate_defaultMFARequirements() { + public static ConfigGenerator.GeneratedValueAndExpectation generate_defaultRequiredFactors() { String[] factors = selectRandomElements(FACTORS); return new ConfigGenerator.GeneratedValueAndExpectation( diff --git a/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java b/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java index 96d9fa5db..cfc9e6db2 100644 --- a/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java +++ b/src/test/java/io/supertokens/test/userIdMapping/UserIdMappingTest.java @@ -25,7 +25,6 @@ import io.supertokens.pluginInterface.ActiveUsersStorage; import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; -import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; @@ -796,8 +795,7 @@ public void checkThatCreateUserIdMappingHasAllNonAuthRecipeChecks() throws Excep // this list contains the package names for recipes which dont use UserIdMapping ArrayList nonAuthRecipesWhichDontNeedUserIdMapping = new ArrayList<>( - List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName(), - MfaStorage.class.getName())); + List.of("io.supertokens.pluginInterface.jwt.JWTRecipeStorage", ActiveUsersStorage.class.getName())); Reflections reflections = new Reflections("io.supertokens.pluginInterface"); Set> classes = reflections.getSubTypesOf(NonAuthRecipeStorage.class); From a57eb0b904f74f8bb6686f7a31f85701c8583850 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 18 Oct 2023 18:41:47 +0530 Subject: [PATCH 07/16] fix: tests --- .../CreateOrUpdateTenantOrGetTenantAPI.java | 4 +- .../io/supertokens/test/StorageLayerTest.java | 2 +- .../api/TestMultitenancyAPIHelper.java | 29 ++- .../test/multitenant/api/TestTenant.java | 233 +++++++++++++++++- 4 files changed, 261 insertions(+), 7 deletions(-) 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 882a60cc9..29d05e625 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -60,7 +60,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); Boolean totpEnabled = null; - MfaFirstFactors firstFactors = new MfaFirstFactors(null, null); + MfaFirstFactors firstFactors = null; String[] defaultRequiredFactors = null; if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { @@ -72,7 +72,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO firstFactors = MfaFirstFactors.fromJson(input.get("firstFactors")); } } catch (IllegalArgumentException e) { - throw new ServletException(new BadRequestException(e.getMessage())); + throw new ServletException(new BadRequestException("firstFactors: " + e.getMessage())); } } 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/multitenant/api/TestMultitenancyAPIHelper.java b/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java index 261a0eb27..2553bdc74 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java @@ -19,6 +19,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import io.supertokens.Main; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.ThirdPartyConfig; import io.supertokens.test.httpRequest.HttpRequestForTesting; @@ -141,6 +142,15 @@ 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, null, null, coreConfig, SemVer.v3_0); + } + + public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, String tenantId, Boolean emailPasswordEnabled, + Boolean thirdPartyEnabled, Boolean passwordlessEnabled, + Boolean totpEnabled, + MfaFirstFactors firstFactors, String[] defaultRequiredFactors, + JsonObject coreConfig, SemVer version) throws HttpResponseException, IOException { JsonObject requestBody = new JsonObject(); requestBody.addProperty("tenantId", tenantId); if (emailPasswordEnabled != null) { @@ -152,12 +162,22 @@ public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, if (passwordlessEnabled != null) { requestBody.addProperty("passwordlessEnabled", passwordlessEnabled); } + if (totpEnabled != null) { + requestBody.addProperty("totpEnabled", totpEnabled); + } + if (firstFactors != null) { + requestBody.add("firstFactors", firstFactors.toJson()); + } + if (defaultRequiredFactors != null) { + requestBody.add("defaultRequiredFactors", new Gson().toJsonTree(defaultRequiredFactors)); + } + 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; @@ -190,11 +210,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/TestTenant.java b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java index b03ebd71c..c8a76b662 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java @@ -16,17 +16,18 @@ 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; import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; +import io.supertokens.mfa.Mfa; import io.supertokens.multitenancy.exception.BadPermissionException; import io.supertokens.multitenancy.exception.CannotModifyBaseConfigException; import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; +import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.storageLayer.StorageLayer; @@ -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; @@ -346,4 +348,231 @@ 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, null, 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, null, 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, null, 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, null, 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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(0, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + + // builtin firstFactor + MfaFirstFactors firstFactors = new MfaFirstFactors(new String[]{"otp-phone"}, null); + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, firstFactors, 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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); + + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, null, 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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); + + // custom factors + firstFactors = new MfaFirstFactors(null, new String[]{"biometric"}); + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, firstFactors, 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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); + + // test both + firstFactors = new MfaFirstFactors(new String[]{"otp-phone", "emailpassword"}, new String[]{"biometric", "custom"}); + response = TestMultitenancyAPIHelper.createTenant( + process.getProcess(), + new TenantIdentifier(null, null, null), + "t1", null, null, null, + null, firstFactors, 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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); + } + + @Test + public void testInvalidValuesForFirstFactor() throws Exception { + try { + JsonObject requestBody = new JsonObject(); + requestBody.addProperty("tenantId", "t1"); + requestBody.addProperty("firstFactors", "hello"); // invalid type + + JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", + HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), + requestBody, 1000, 2500, null, + SemVer.v4_1.get(), "multitenancy"); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertTrue(e.getMessage().contains("Input must be a json array")); + } + + try { + JsonObject requestBody = new JsonObject(); + requestBody.addProperty("tenantId", "t1"); + JsonArray array = new JsonArray(); + array.add(new JsonPrimitive(100)); + requestBody.add("firstFactors", array); // invalid type + + JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", + HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), + requestBody, 1000, 2500, null, + SemVer.v4_1.get(), "multitenancy"); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertTrue(e.getMessage().contains("100 is not a built-in factor")); + } + + try { + JsonObject requestBody = new JsonObject(); + requestBody.addProperty("tenantId", "t1"); + JsonArray array = new JsonArray(); + array.add(new JsonPrimitive("custom")); + requestBody.add("firstFactors", array); // invalid built-in type + + JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", + HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), + requestBody, 1000, 2500, null, + SemVer.v4_1.get(), "multitenancy"); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertTrue(e.getMessage().contains("custom is not a built-in factor")); + } + + try { + JsonObject requestBody = new JsonObject(); + requestBody.addProperty("tenantId", "t1"); + JsonArray array = new JsonArray(); + JsonObject factor = new JsonObject(); + factor.addProperty("type", "custom"); + factor.addProperty("id", "otp-phone"); + array.add(factor); + requestBody.add("firstFactors", array); // built in value in custom + + JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", + HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), + requestBody, 1000, 2500, null, + SemVer.v4_1.get(), "multitenancy"); + fail(); + } catch (HttpResponseException e) { + assertEquals(400, e.statusCode); + assertTrue(e.getMessage().contains("Factor otp-phone cannot be used as a custom factor")); + } + } } From b6354375d250c8356024bb969d60755c2e146894 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 20 Oct 2023 11:25:01 +0530 Subject: [PATCH 08/16] fix: mfa --- .../multitenancy/TenantConfigSQLHelper.java | 3 +- .../api/multitenancy/BaseCreateOrUpdate.java | 9 +- .../multitenancy/CreateOrUpdateAppAPI.java | 20 ++--- .../CreateOrUpdateConnectionUriDomainAPI.java | 18 ++-- .../CreateOrUpdateTenantOrGetTenantAPI.java | 18 ++-- .../api/TestMultitenancyAPIHelper.java | 9 +- .../test/multitenant/api/TestTenant.java | 90 ++----------------- .../generator/GenerateMfaConfig.java | 30 ++++--- 8 files changed, 50 insertions(+), 147 deletions(-) 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 c026f9302..9dd93bab6 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java @@ -21,7 +21,6 @@ import io.supertokens.inmemorydb.queries.utils.JsonUtils; import io.supertokens.pluginInterface.RowMapper; import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.*; import java.sql.Connection; @@ -55,7 +54,7 @@ public TenantConfig map(ResultSet result) throws StorageQueryException { new ThirdPartyConfig(result.getBoolean("third_party_enabled"), this.providers), new PasswordlessConfig(result.getBoolean("passwordless_enabled")), new TotpConfig(false), // TODO - new MfaConfig(new MfaFirstFactors(null, null), new String[0]), // TODO + new MfaConfig(new String[0], new String[0]), // TODO JsonUtils.stringToJsonObject(result.getString("core_config")) ); } catch (Exception e) { 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 06cfb4a3f..b7f03faff 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java @@ -26,7 +26,6 @@ import io.supertokens.pluginInterface.RECIPE_ID; import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.thirdparty.InvalidProviderConfigException; @@ -47,7 +46,7 @@ public BaseCreateOrUpdate(Main main) { protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdentifier, TenantIdentifier targetTenantIdentifier, Boolean emailPasswordEnabled, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, Boolean totpEnabled, - MfaFirstFactors firstFactors, String[] defaultRequiredFactors, + String[] firstFactors, String[] defaultRequiredFactorIds, JsonObject coreConfig, HttpServletResponse resp) throws ServletException, IOException { @@ -139,19 +138,19 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - new MfaConfig(firstFactors, tenantConfig.mfaConfig.defaultRequiredFactors), + new MfaConfig(firstFactors, tenantConfig.mfaConfig.defaultRequiredFactorIds), tenantConfig.coreConfig ); } - if (defaultRequiredFactors != null) { + if (defaultRequiredFactorIds != null) { tenantConfig = new TenantConfig( tenantConfig.tenantIdentifier, tenantConfig.emailPasswordConfig, tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - new MfaConfig(tenantConfig.mfaConfig.firstFactors, defaultRequiredFactors), + new MfaConfig(tenantConfig.mfaConfig.firstFactors, defaultRequiredFactorIds), tenantConfig.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 00f78b9f7..92de49594 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -18,14 +18,11 @@ import com.google.gson.JsonObject; import io.supertokens.Main; -import io.supertokens.multitenancy.exception.BadPermissionException; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; 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; @@ -59,20 +56,13 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); Boolean totpEnabled = null; - MfaFirstFactors firstFactors = new MfaFirstFactors(null, null); - String[] defaultRequiredFactors = null; + String[] firstFactors = null; + String[] defaultRequiredFactorIds = null; if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - defaultRequiredFactors = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactors", true); - - try { - if (input.has("firstFactors")) { - firstFactors = MfaFirstFactors.fromJson(input.get("firstFactors")); - } - } catch (IllegalArgumentException e) { - throw new ServletException(new BadRequestException(e.getMessage())); - } + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); } TenantIdentifier sourceTenantIdentifier; @@ -86,7 +76,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), appId, null), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultRequiredFactors, + totpEnabled, firstFactors, 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 fe564a228..d603152ff 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -18,7 +18,6 @@ import com.google.gson.JsonObject; import io.supertokens.Main; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.utils.SemVer; @@ -57,20 +56,13 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); Boolean totpEnabled = null; - MfaFirstFactors firstFactors = new MfaFirstFactors(null, null); - String[] defaultRequiredFactors = null; + String[] firstFactors = null; + String[] defaultRequiredFactorIds = null; if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - defaultRequiredFactors = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactors", true); - - try { - if (input.has("firstFactors")) { - firstFactors = MfaFirstFactors.fromJson(input.get("firstFactors")); - } - } catch (IllegalArgumentException e) { - throw new ServletException(new BadRequestException(e.getMessage())); - } + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); } TenantIdentifier sourceTenantIdentifier; @@ -84,7 +76,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(connectionUriDomain, null, null), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultRequiredFactors, + totpEnabled, firstFactors, 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 29d05e625..6a19598eb 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -20,7 +20,6 @@ import io.supertokens.Main; import io.supertokens.config.CoreConfig; import io.supertokens.multitenancy.Multitenancy; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.*; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.utils.SemVer; @@ -60,20 +59,13 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject coreConfig = InputParser.parseJsonObjectOrThrowError(input, "coreConfig", true); Boolean totpEnabled = null; - MfaFirstFactors firstFactors = null; - String[] defaultRequiredFactors = null; + String[] firstFactors = null; + String[] defaultRequiredFactorIds = null; if (getVersionFromRequest(req).greaterThanOrEqualTo(SemVer.v4_1)) { totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); - defaultRequiredFactors = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactors", true); - - try { - if (input.has("firstFactors")) { - firstFactors = MfaFirstFactors.fromJson(input.get("firstFactors")); - } - } catch (IllegalArgumentException e) { - throw new ServletException(new BadRequestException("firstFactors: " + e.getMessage())); - } + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); } TenantIdentifier sourceTenantIdentifier; @@ -87,7 +79,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), sourceTenantIdentifier.getAppId(), tenantId), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultRequiredFactors, + totpEnabled, firstFactors, defaultRequiredFactorIds, coreConfig, resp); } 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 2553bdc74..a2e8f9f8d 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestMultitenancyAPIHelper.java @@ -19,7 +19,6 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import io.supertokens.Main; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.ThirdPartyConfig; import io.supertokens.test.httpRequest.HttpRequestForTesting; @@ -149,7 +148,7 @@ public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, String tenantId, Boolean emailPasswordEnabled, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, Boolean totpEnabled, - MfaFirstFactors firstFactors, String[] defaultRequiredFactors, + String[] firstFactors, String[] defaultRequiredFactorIds, JsonObject coreConfig, SemVer version) throws HttpResponseException, IOException { JsonObject requestBody = new JsonObject(); requestBody.addProperty("tenantId", tenantId); @@ -166,10 +165,10 @@ public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, requestBody.addProperty("totpEnabled", totpEnabled); } if (firstFactors != null) { - requestBody.add("firstFactors", firstFactors.toJson()); + requestBody.add("firstFactors", new Gson().toJsonTree(firstFactors)); } - if (defaultRequiredFactors != null) { - requestBody.add("defaultRequiredFactors", new Gson().toJsonTree(defaultRequiredFactors)); + if (defaultRequiredFactorIds != null) { + requestBody.add("defaultRequiredFactorIds", new Gson().toJsonTree(defaultRequiredFactorIds)); } requestBody.add("coreConfig", coreConfig); 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 c8a76b662..9d9d3d87f 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java @@ -21,13 +21,11 @@ import io.supertokens.featureflag.EE_FEATURES; import io.supertokens.featureflag.FeatureFlagTestContent; import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; -import io.supertokens.mfa.Mfa; import io.supertokens.multitenancy.exception.BadPermissionException; import io.supertokens.multitenancy.exception.CannotModifyBaseConfigException; import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.exceptions.InvalidConfigException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; import io.supertokens.storageLayer.StorageLayer; @@ -442,12 +440,12 @@ public void testFirstFactorsArray() throws Exception { assertEquals(0, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); // builtin firstFactor - MfaFirstFactors firstFactors = new MfaFirstFactors(new String[]{"otp-phone"}, null); + String[] firstFactors = new String[]{"otp-phone"}; response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - null, firstFactors, null, + null, new String[]{"otp-phone"}, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -455,7 +453,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), @@ -469,10 +467,10 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); // custom factors - firstFactors = new MfaFirstFactors(null, new String[]{"biometric"}); + firstFactors = new String[]{"biometric"}; response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), new TenantIdentifier(null, null, null), @@ -485,10 +483,10 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); // test both - firstFactors = new MfaFirstFactors(new String[]{"otp-phone", "emailpassword"}, new String[]{"biometric", "custom"}); + firstFactors = new String[]{"otp-phone", "emailpassword", "biometric", "custom"}; response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), new TenantIdentifier(null, null, null), @@ -501,78 +499,6 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, MfaFirstFactors.fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray())); - } - - @Test - public void testInvalidValuesForFirstFactor() throws Exception { - try { - JsonObject requestBody = new JsonObject(); - requestBody.addProperty("tenantId", "t1"); - requestBody.addProperty("firstFactors", "hello"); // invalid type - - JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", - HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), - requestBody, 1000, 2500, null, - SemVer.v4_1.get(), "multitenancy"); - fail(); - } catch (HttpResponseException e) { - assertEquals(400, e.statusCode); - assertTrue(e.getMessage().contains("Input must be a json array")); - } - - try { - JsonObject requestBody = new JsonObject(); - requestBody.addProperty("tenantId", "t1"); - JsonArray array = new JsonArray(); - array.add(new JsonPrimitive(100)); - requestBody.add("firstFactors", array); // invalid type - - JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", - HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), - requestBody, 1000, 2500, null, - SemVer.v4_1.get(), "multitenancy"); - fail(); - } catch (HttpResponseException e) { - assertEquals(400, e.statusCode); - assertTrue(e.getMessage().contains("100 is not a built-in factor")); - } - - try { - JsonObject requestBody = new JsonObject(); - requestBody.addProperty("tenantId", "t1"); - JsonArray array = new JsonArray(); - array.add(new JsonPrimitive("custom")); - requestBody.add("firstFactors", array); // invalid built-in type - - JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", - HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), - requestBody, 1000, 2500, null, - SemVer.v4_1.get(), "multitenancy"); - fail(); - } catch (HttpResponseException e) { - assertEquals(400, e.statusCode); - assertTrue(e.getMessage().contains("custom is not a built-in factor")); - } - - try { - JsonObject requestBody = new JsonObject(); - requestBody.addProperty("tenantId", "t1"); - JsonArray array = new JsonArray(); - JsonObject factor = new JsonObject(); - factor.addProperty("type", "custom"); - factor.addProperty("id", "otp-phone"); - array.add(factor); - requestBody.add("firstFactors", array); // built in value in custom - - JsonObject response = HttpRequestForTesting.sendJsonPUTRequest(process.getProcess(), "", - HttpRequestForTesting.getMultitenantUrl(TenantIdentifier.BASE_TENANT, "/recipe/multitenancy/tenant"), - requestBody, 1000, 2500, null, - SemVer.v4_1.get(), "multitenancy"); - fail(); - } catch (HttpResponseException e) { - assertEquals(400, e.statusCode); - assertTrue(e.getMessage().contains("Factor otp-phone cannot be used as a custom factor")); - } + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); } } diff --git a/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java b/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java index e12b2b444..4e928d2a4 100644 --- a/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java +++ b/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java @@ -16,8 +16,6 @@ package io.supertokens.test.multitenant.generator; -import io.supertokens.pluginInterface.mfa.MfaFirstFactors; - import java.util.HashSet; import java.util.Random; import java.util.Set; @@ -29,11 +27,10 @@ public class GenerateMfaConfig { "otp-email", "otp-phone", "link-email", - "link-phone" - }; - - private static final String[] OTHER_FACTORS = new String[]{ - "totp", "biometric", "custom" + "link-phone", + "totp", + "biometric", + "custom" }; private static String[] selectRandomElements(String[] inputArray) { @@ -65,17 +62,26 @@ private static String[] selectRandomElements(String[] inputArray) { } public static ConfigGenerator.GeneratedValueAndExpectation generate_firstFactors() { - String[] factors = selectRandomElements(FACTORS); - String[] customFactors = selectRandomElements(OTHER_FACTORS); + if (new Random().nextFloat() < 0.15) { + return new ConfigGenerator.GeneratedValueAndExpectation( + null, + new ConfigGenerator.Expectation("ok", null)); + } + String[] factors = selectRandomElements(FACTORS); return new ConfigGenerator.GeneratedValueAndExpectation( - new MfaFirstFactors(factors, customFactors), + factors, new ConfigGenerator.Expectation("ok", factors)); } - public static ConfigGenerator.GeneratedValueAndExpectation generate_defaultRequiredFactors() { - String[] factors = selectRandomElements(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)); From 914572b508d360341cda2c7330061af221ec54aa Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 20 Oct 2023 13:06:03 +0530 Subject: [PATCH 09/16] fix: tests --- src/test/java/io/supertokens/test/CronjobTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/io/supertokens/test/CronjobTest.java b/src/test/java/io/supertokens/test/CronjobTest.java index 31144e076..029214a10 100644 --- a/src/test/java/io/supertokens/test/CronjobTest.java +++ b/src/test/java/io/supertokens/test/CronjobTest.java @@ -943,6 +943,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -950,6 +952,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -957,6 +961,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -964,6 +970,8 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), + new TotpConfig(false), + new MfaConfig(null, null), coreConfig ), false, false, true); From ef7cbc7206e26b1d84dd352966cf1a53e970a0bb Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 20 Oct 2023 15:01:57 +0530 Subject: [PATCH 10/16] fix: tests --- .../api/multitenancy/BaseCreateOrUpdate.java | 7 +- .../multitenancy/CreateOrUpdateAppAPI.java | 14 +- .../CreateOrUpdateConnectionUriDomainAPI.java | 14 +- .../CreateOrUpdateTenantOrGetTenantAPI.java | 14 +- .../test/multitenant/api/TestApp.java | 264 ++++++++++++++++++ .../api/TestConnectionUriDomain.java | 264 ++++++++++++++++++ .../api/TestMultitenancyAPIHelper.java | 53 +++- .../test/multitenant/api/TestTenant.java | 127 ++++++++- 8 files changed, 729 insertions(+), 28 deletions(-) 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 b7f03faff..fd1c9cb72 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java @@ -46,7 +46,8 @@ public BaseCreateOrUpdate(Main main) { protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdentifier, TenantIdentifier targetTenantIdentifier, Boolean emailPasswordEnabled, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, Boolean totpEnabled, - String[] firstFactors, String[] defaultRequiredFactorIds, + boolean hasFirstFactors, String[] firstFactors, + boolean hasDefaultRequiredFactorIds, String[] defaultRequiredFactorIds, JsonObject coreConfig, HttpServletResponse resp) throws ServletException, IOException { @@ -131,7 +132,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent ); } - if (firstFactors != null) { + if (hasFirstFactors) { tenantConfig = new TenantConfig( tenantConfig.tenantIdentifier, tenantConfig.emailPasswordConfig, @@ -143,7 +144,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent ); } - if (defaultRequiredFactorIds != null) { + if (hasDefaultRequiredFactorIds) { tenantConfig = new TenantConfig( tenantConfig.tenantIdentifier, tenantConfig.emailPasswordConfig, 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 92de49594..34345b638 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -57,12 +57,20 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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); - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + hasFirstFactors = input.has("firstFactors"); + if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + } + hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); + if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { + defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + } } TenantIdentifier sourceTenantIdentifier; @@ -76,7 +84,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), appId, null), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultRequiredFactorIds, + 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 d603152ff..5d1bf8bc2 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -57,12 +57,20 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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); - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + hasFirstFactors = input.has("firstFactors"); + if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + } + hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); + if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { + defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + } } TenantIdentifier sourceTenantIdentifier; @@ -76,7 +84,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(connectionUriDomain, null, null), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultRequiredFactorIds, + 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 6a19598eb..6d22342fc 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -60,12 +60,20 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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); - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); - defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + hasFirstFactors = input.has("firstFactors"); + if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { + firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + } + hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); + if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { + defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + } } TenantIdentifier sourceTenantIdentifier; @@ -79,7 +87,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO req, sourceTenantIdentifier, new TenantIdentifier(sourceTenantIdentifier.getConnectionUriDomain(), sourceTenantIdentifier.getAppId(), tenantId), emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - totpEnabled, firstFactors, defaultRequiredFactorIds, + totpEnabled, hasFirstFactors, firstFactors, hasDefaultRequiredFactorIds, defaultRequiredFactorIds, coreConfig, resp); } 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..d179dde68 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; @@ -507,4 +508,267 @@ 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); + assertFalse(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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + + // 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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + } + + @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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + + // 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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + } + } 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..489baac33 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; @@ -487,4 +489,266 @@ 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); + 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, + 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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + + // 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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + } + + @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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + + // 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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + } } 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 57dbb830f..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; @@ -143,13 +183,14 @@ public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, Boolean thirdPartyEnabled, Boolean passwordlessEnabled, JsonObject coreConfig) throws HttpResponseException, IOException { return createTenant(main, sourceTenant, tenantId, emailPasswordEnabled, thirdPartyEnabled, passwordlessEnabled, - null, null, null, coreConfig, SemVer.v3_0); + 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, - String[] firstFactors, String[] defaultRequiredFactorIds, + boolean setFirstFactors, String[] firstFactors, + boolean setDefaultRequiredFactorIds, String[] defaultRequiredFactorIds, JsonObject coreConfig, SemVer version) throws HttpResponseException, IOException { JsonObject requestBody = new JsonObject(); requestBody.addProperty("tenantId", tenantId); @@ -165,10 +206,10 @@ public static JsonObject createTenant(Main main, TenantIdentifier sourceTenant, if (totpEnabled != null) { requestBody.addProperty("totpEnabled", totpEnabled); } - if (firstFactors != null) { + if (setFirstFactors || firstFactors != null) { requestBody.add("firstFactors", new Gson().toJsonTree(firstFactors)); } - if (defaultRequiredFactorIds != null) { + if (setDefaultRequiredFactorIds || defaultRequiredFactorIds != null) { requestBody.add("defaultRequiredFactorIds", new Gson().toJsonTree(defaultRequiredFactorIds)); } 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 9d9d3d87f..3cab78b20 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java @@ -372,7 +372,7 @@ public void testTotpEnabledBoolean() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - true, null, null, + true, false, null, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -384,7 +384,7 @@ public void testTotpEnabledBoolean() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - null, null, null, + null, false, null, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -396,7 +396,7 @@ public void testTotpEnabledBoolean() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - false, null, null, + false, false, null, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -408,7 +408,7 @@ public void testTotpEnabledBoolean() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - null, null, null, + null, false, null, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -436,8 +436,7 @@ public void testFirstFactorsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(0, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); + assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); // builtin firstFactor String[] firstFactors = new String[]{"otp-phone"}; @@ -445,7 +444,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - null, new String[]{"otp-phone"}, null, + null, true, new String[]{"otp-phone"}, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -459,7 +458,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - null, null, null, + null, false, null, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -475,7 +474,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - null, firstFactors, null, + null, true, firstFactors, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -491,7 +490,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), new TenantIdentifier(null, null, null), "t1", null, null, null, - null, firstFactors, null, + null, true, firstFactors, false, null, config, SemVer.v4_1); assertFalse(response.get("createdNew").getAsBoolean()); @@ -500,5 +499,113 @@ public void testFirstFactorsArray() throws Exception { assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + } + + @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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + + // 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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().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); + assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); } } From 8e806824b4090085ebb3e2caab606ebc490f76f2 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 25 Oct 2023 12:24:05 +0530 Subject: [PATCH 11/16] fix: pr comments --- .../io/supertokens/webserver/InputParser.java | 19 ------------------- .../multitenancy/CreateOrUpdateAppAPI.java | 13 +++++++++++-- .../CreateOrUpdateConnectionUriDomainAPI.java | 13 +++++++++++-- .../CreateOrUpdateTenantOrGetTenantAPI.java | 13 +++++++++++-- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/main/java/io/supertokens/webserver/InputParser.java b/src/main/java/io/supertokens/webserver/InputParser.java index 759031435..ebf1e86ee 100644 --- a/src/main/java/io/supertokens/webserver/InputParser.java +++ b/src/main/java/io/supertokens/webserver/InputParser.java @@ -144,25 +144,6 @@ public static String parseStringOrThrowError(JsonObject element, String fieldNam } } - public static String[] parseStringArrayOrThrowError(JsonObject element, String fieldName, boolean nullable) - throws ServletException { - try { - if (nullable && element.get(fieldName) == null) { - return null; - } - JsonArray strings = element.get(fieldName).getAsJsonArray(); - String[] result = new String[strings.size()]; - for (int i = 0; i < strings.size(); i++) { - result[i] = strings.get(i).getAsString(); - } - - return result; - } catch (Exception e) { - throw new ServletException( - new WebserverAPI.BadRequestException("Field name '" + fieldName + "' is invalid in JSON input")); - } - } - public static String parseStringFromElementOrThrowError(JsonElement element, String parentFieldName, boolean nullable) throws ServletException { try { 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 34345b638..2b109cd0c 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -16,6 +16,7 @@ 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; @@ -65,11 +66,19 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); hasFirstFactors = input.has("firstFactors"); if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + 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); + } } hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { - defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + 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); + } } } 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 5d1bf8bc2..c42499ee0 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -16,6 +16,7 @@ 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; @@ -65,11 +66,19 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); hasFirstFactors = input.has("firstFactors"); if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + 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); + } } hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { - defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + 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); + } } } 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 6d22342fc..e8008418a 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -16,6 +16,7 @@ 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; @@ -68,11 +69,19 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO totpEnabled = InputParser.parseBooleanOrThrowError(input, "totpEnabled", true); hasFirstFactors = input.has("firstFactors"); if (hasFirstFactors && !input.get("firstFactors").isJsonNull()) { - firstFactors = InputParser.parseStringArrayOrThrowError(input, "firstFactors", true); + 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); + } } hasDefaultRequiredFactorIds = input.has("defaultRequiredFactorIds"); if (hasDefaultRequiredFactorIds && !input.get("defaultRequiredFactorIds").isJsonNull()) { - defaultRequiredFactorIds = InputParser.parseStringArrayOrThrowError(input, "defaultRequiredFactorIds", true); + 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); + } } } From 3d338f4c170a0156ccf7d654787aba6c46de7da3 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 25 Oct 2023 12:49:58 +0530 Subject: [PATCH 12/16] fix: pr comments --- .../java/io/supertokens/multitenancy/MultitenancyHelper.java | 4 ++-- .../webserver/api/multitenancy/BaseCreateOrUpdate.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java b/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java index cf5c91539..47fa01190 100644 --- a/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java +++ b/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java @@ -75,7 +75,7 @@ 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 TotpConfig(false), new MfaConfig(null, null), + new PasswordlessConfig(true), new TotpConfig(true), new MfaConfig(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 @@ -96,7 +96,7 @@ private TenantConfig[] getAllTenantsFromDb() throws StorageQueryException { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), + new TotpConfig(true), new MfaConfig(null, null), new JsonObject() ) 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 fd1c9cb72..91f78fff9 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java @@ -65,7 +65,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), + new TotpConfig(true), new MfaConfig(null, null), new JsonObject() ); From 15f731247131e8785bb48d3fd7679db1b2266cf4 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 25 Oct 2023 17:29:44 +0530 Subject: [PATCH 13/16] fix: pr comments --- .../ee/test/TestMultitenancyStats.java | 6 +- .../multitenancy/TenantConfigSQLHelper.java | 4 +- .../multitenancy/MultitenancyHelper.java | 7 +- .../api/multitenancy/BaseCreateOrUpdate.java | 27 +- .../CreateOrUpdateThirdPartyConfigAPI.java | 4 +- .../thirdparty/RemoveThirdPartyConfigAPI.java | 4 +- .../io/supertokens/test/CDIVersionTest.java | 10 +- .../java/io/supertokens/test/CronjobTest.java | 60 ++-- .../io/supertokens/test/FeatureFlagTest.java | 20 +- .../io/supertokens/test/HelloAPITest.java | 18 +- .../test/IpAllowDenyRegexTest.java | 8 +- .../io/supertokens/test/PathRouterTest.java | 240 ++++++------- .../test/SuperTokensSaaSSecretTest.java | 20 +- .../test/TestHelloAPIRateLimiting.java | 6 +- .../accountlinking/CreatePrimaryUserTest.java | 8 +- .../test/accountlinking/LinkAccountsTest.java | 8 +- .../test/accountlinking/MultitenantTest.java | 16 +- .../test/accountlinking/SessionTests.java | 16 +- .../api/CreatePrimaryUserAPITest.java | 4 +- .../test/authRecipe/MultitenantAPITest.java | 6 +- .../test/authRecipe/UserPaginationTest.java | 6 +- .../dashboard/apis/MultitenantAPITest.java | 6 +- .../test/emailpassword/EmailPasswordTest.java | 4 +- .../MultitenantEmailPasswordTest.java | 6 +- .../emailpassword/api/MultitenantAPITest.java | 6 +- .../api/MultitenantAPITest.java | 6 +- .../test/multitenant/AppTenantUserTest.java | 32 +- .../test/multitenant/ConfigTest.java | 318 +++++++++--------- .../test/multitenant/LoadTest.java | 4 +- .../supertokens/test/multitenant/LogTest.java | 26 +- .../RequestConnectionUriDomainTest.java | 26 +- .../test/multitenant/SigningKeysTest.java | 12 +- .../test/multitenant/StorageLayerTest.java | 116 +++---- .../test/multitenant/TestAppData.java | 7 +- .../test/multitenant/api/TestApp.java | 58 ++-- .../api/TestConnectionUriDomain.java | 58 ++-- .../TestSkipValidationInCreateThirdParty.java | 4 +- .../test/multitenant/api/TestTenant.java | 56 +-- .../TestTenantIdIsNotPresentForOlderCDI.java | 12 +- .../generator/GenerateMfaConfig.java | 89 ----- .../generator/GenerateTenantConfig.java | 72 +++- .../passwordless/api/MultitenantAPITest.java | 6 +- .../test/session/api/MultitenantAPITest.java | 6 +- .../thirdparty/api/MultitenantAPITest.java | 6 +- .../test/totp/api/MultitenantAPITest.java | 6 +- .../userIdMapping/api/MultitenantAPITest.java | 16 +- 46 files changed, 707 insertions(+), 749 deletions(-) delete mode 100644 src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java 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 60aaeb496..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,7 +78,7 @@ public void testPaidStatsIsSentForAllAppsInMultitenancy() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ), false); @@ -87,7 +87,7 @@ public void testPaidStatsIsSentForAllAppsInMultitenancy() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ), false); @@ -96,7 +96,7 @@ public void testPaidStatsIsSentForAllAppsInMultitenancy() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 9dd93bab6..dce7bfffb 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/multitenancy/TenantConfigSQLHelper.java @@ -54,8 +54,8 @@ public TenantConfig map(ResultSet result) throws StorageQueryException { new ThirdPartyConfig(result.getBoolean("third_party_enabled"), this.providers), new PasswordlessConfig(result.getBoolean("passwordless_enabled")), new TotpConfig(false), // TODO - new MfaConfig(new String[0], new String[0]), // TODO - JsonUtils.stringToJsonObject(result.getString("core_config")) + 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 47fa01190..647ccedff 100644 --- a/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java +++ b/src/main/java/io/supertokens/multitenancy/MultitenancyHelper.java @@ -75,8 +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 TotpConfig(true), new MfaConfig(null, null), - 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 @@ -97,8 +97,7 @@ private TenantConfig[] getAllTenantsFromDb() throws StorageQueryException { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(true), - new MfaConfig(null, null), - new JsonObject() + null, null, new JsonObject() ) }; } 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 91f78fff9..edc284730 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/BaseCreateOrUpdate.java @@ -66,8 +66,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(true), - new MfaConfig(null, null), - new JsonObject() + null, null, new JsonObject() ); } else { // We disable all recipes by default while creating tenant @@ -77,8 +76,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new ThirdPartyConfig(false, null), new PasswordlessConfig(false), new TotpConfig(false), - new MfaConfig(null, null), - new JsonObject() + null, null, new JsonObject() ); } createdNew = true; @@ -91,8 +89,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - tenantConfig.mfaConfig, - tenantConfig.coreConfig + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -103,8 +100,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent new ThirdPartyConfig(thirdPartyEnabled, tenantConfig.thirdPartyConfig.providers), tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - tenantConfig.mfaConfig, - tenantConfig.coreConfig + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -115,8 +111,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, new PasswordlessConfig(passwordlessEnabled), tenantConfig.totpConfig, - tenantConfig.mfaConfig, - tenantConfig.coreConfig + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -127,8 +122,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, new TotpConfig(totpEnabled), - tenantConfig.mfaConfig, - tenantConfig.coreConfig + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -139,8 +133,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - new MfaConfig(firstFactors, tenantConfig.mfaConfig.defaultRequiredFactorIds), - tenantConfig.coreConfig + firstFactors, tenantConfig.defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -151,8 +144,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - new MfaConfig(tenantConfig.mfaConfig.firstFactors, defaultRequiredFactorIds), - tenantConfig.coreConfig + tenantConfig.firstFactors, defaultRequiredFactorIds, tenantConfig.coreConfig ); } @@ -164,8 +156,7 @@ protected void handle(HttpServletRequest req, TenantIdentifier sourceTenantIdent tenantConfig.thirdPartyConfig, tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - tenantConfig.mfaConfig, - coreConfig + tenantConfig.firstFactors, tenantConfig.defaultRequiredFactorIds, coreConfig ); } 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 81ea90d3e..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 @@ -115,8 +115,8 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO newProviders.toArray(new ThirdPartyConfig.Provider[0])), tenantConfig.passwordlessConfig, tenantConfig.totpConfig, - tenantConfig.mfaConfig, - tenantConfig.coreConfig); + 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 044d29331..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 @@ -83,8 +83,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I config.thirdPartyConfig.enabled, newProviders.toArray(new ThirdPartyConfig.Provider[0])), config.passwordlessConfig, config.totpConfig, - config.mfaConfig, - config.coreConfig); + 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 bc985e60e..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,16 +272,16 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 TotpConfig(false), new MfaConfig(null, null), - 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 029214a10..de47144d0 100644 --- a/src/test/java/io/supertokens/test/CronjobTest.java +++ b/src/test/java/io/supertokens/test/CronjobTest.java @@ -463,7 +463,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -472,7 +472,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -481,7 +481,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -490,7 +490,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); @@ -505,7 +505,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, config ), false); @@ -515,7 +515,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -524,7 +524,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -533,7 +533,7 @@ public void testAddingTenantsDoesNotIncreaseCronJobs() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, config ), false); @@ -563,7 +563,7 @@ public void testTargetTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -572,7 +572,7 @@ public void testTargetTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -581,7 +581,7 @@ public void testTargetTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -590,7 +590,7 @@ public void testTargetTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); @@ -623,7 +623,7 @@ public void testPerTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -632,7 +632,7 @@ public void testPerTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -641,7 +641,7 @@ public void testPerTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -650,7 +650,7 @@ public void testPerTenantCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); @@ -684,7 +684,7 @@ public void testPerAppCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -693,7 +693,7 @@ public void testPerAppCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -702,7 +702,7 @@ public void testPerAppCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -711,7 +711,7 @@ public void testPerAppCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); @@ -749,7 +749,7 @@ public void testPerUserPoolCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -758,7 +758,7 @@ public void testPerUserPoolCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); JsonObject config = new JsonObject(); @@ -770,7 +770,7 @@ public void testPerUserPoolCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, config ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -779,7 +779,7 @@ public void testPerUserPoolCronTask() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, config ), false); @@ -820,7 +820,7 @@ public void testThatCoreAutomaticallySyncsToConfigChangesInDb() throws Exception new ThirdPartyConfig(false, null), new PasswordlessConfig(false), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() ), false); @@ -842,7 +842,7 @@ public void testThatCoreAutomaticallySyncsToConfigChangesInDb() throws Exception new ThirdPartyConfig(false, null), new PasswordlessConfig(false), new TotpConfig(false), - new MfaConfig(null, null), + null, null, new JsonObject() )); @@ -944,7 +944,7 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -953,7 +953,7 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -962,7 +962,7 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + null, null, coreConfig ), false, false, true); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -971,7 +971,7 @@ public void testThatCronJobsHaveTenantsInfoAfterRestart() throws Exception { new ThirdPartyConfig(true, null), new PasswordlessConfig(true), new TotpConfig(false), - new MfaConfig(null, null), + 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 0a7467c64..5da1a28cc 100644 --- a/src/test/java/io/supertokens/test/FeatureFlagTest.java +++ b/src/test/java/io/supertokens/test/FeatureFlagTest.java @@ -291,7 +291,7 @@ public void testFeatureFlagWithMultitenancyFor500Tenants() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, new JsonObject() ) ); @@ -353,7 +353,7 @@ public void testThatMultitenantStatsAreAccurate() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, coreConfig ) ); @@ -381,7 +381,7 @@ public void testThatMultitenantStatsAreAccurate() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, coreConfig ) ); @@ -454,7 +454,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, new JsonObject() ) ); @@ -473,7 +473,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, coreConfig ) ); @@ -501,7 +501,7 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, coreConfig ) ); @@ -583,7 +583,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, coreConfig ) ); @@ -603,7 +603,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, coreConfig ) ); @@ -631,7 +631,7 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { null, null, null, null, null, null, null) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, coreConfig ) ); @@ -704,7 +704,7 @@ public void testPaidFeaturesAreEnabledIfUsingInMemoryDatabase() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 cae41b3e5..fb2e9836a 100644 --- a/src/test/java/io/supertokens/test/HelloAPITest.java +++ b/src/test/java/io/supertokens/test/HelloAPITest.java @@ -118,7 +118,7 @@ public void testHelloAPIWithBasePath3() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -127,7 +127,7 @@ public void testHelloAPIWithBasePath3() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -136,7 +136,7 @@ public void testHelloAPIWithBasePath3() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -204,7 +204,7 @@ public void testWithBasePathThatHelloAPIDoesNotRequireAPIKeys() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -213,7 +213,7 @@ public void testWithBasePathThatHelloAPIDoesNotRequireAPIKeys() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -222,7 +222,7 @@ public void testWithBasePathThatHelloAPIDoesNotRequireAPIKeys() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -291,7 +291,7 @@ public void testThatHelloAPIDoesNotRequireAPIKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -300,7 +300,7 @@ public void testThatHelloAPIDoesNotRequireAPIKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject() ), false); @@ -309,7 +309,7 @@ public void testThatHelloAPIDoesNotRequireAPIKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 c6066a7c3..61c2004b9 100644 --- a/src/test/java/io/supertokens/test/IpAllowDenyRegexTest.java +++ b/src/test/java/io/supertokens/test/IpAllowDenyRegexTest.java @@ -385,13 +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), new MfaConfig(null, null), + 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), new MfaConfig(null, null), + new TotpConfig(false),null, null, new JsonObject() ), false); @@ -427,13 +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), new MfaConfig(null, null), + 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), new MfaConfig(null, null), + 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 db548e481..4132bf6f3 100644 --- a/src/test/java/io/supertokens/test/PathRouterTest.java +++ b/src/test/java/io/supertokens/test/PathRouterTest.java @@ -91,8 +91,8 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -103,8 +103,8 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -115,8 +115,8 @@ public void basicTenantIdFetchingTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -266,8 +266,8 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -278,8 +278,8 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -290,8 +290,8 @@ public void basicTenantIdFetchingWihQueryParamTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -441,8 +441,8 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -453,8 +453,8 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -465,8 +465,8 @@ public void basicTenantIdFetchingWithBasePathTest() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -626,8 +626,8 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -638,8 +638,8 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -650,8 +650,8 @@ public void basicTenantIdFetchingWithBasePathTest2() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -812,8 +812,8 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -824,8 +824,8 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -836,8 +836,8 @@ public void basicTenantIdFetchingWithBasePathTest3() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -995,8 +995,8 @@ public void withRecipeRouterTest() throws Exception { new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1006,8 +1006,8 @@ public void withRecipeRouterTest() throws Exception { new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); @@ -1339,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1348,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1357,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1366,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); @@ -1464,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1473,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -1482,8 +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 TotpConfig(false), new MfaConfig(null, null), - new JsonObject()), + new TotpConfig(false), + null, null, new JsonObject()), false ); @@ -1584,13 +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), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -1649,8 +1649,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1661,8 +1661,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1673,8 +1673,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1685,8 +1685,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1697,8 +1697,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1709,8 +1709,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1721,8 +1721,8 @@ public void basicAppIdTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1957,8 +1957,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1969,8 +1969,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1981,8 +1981,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -1993,8 +1993,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2005,8 +2005,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2017,8 +2017,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2029,8 +2029,8 @@ public void basicAppIdWithBasePathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2249,8 +2249,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2261,8 +2261,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2273,8 +2273,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2285,8 +2285,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2297,8 +2297,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2309,8 +2309,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2321,8 +2321,8 @@ public void basicAppIdWithBase2PathTesting() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false ); @@ -2558,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2567,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2576,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2585,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -2636,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2645,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); @@ -2704,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2713,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2722,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2731,8 +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 TotpConfig(false), new MfaConfig(null, null), - new JsonObject()), + new TotpConfig(false), + null, null, new JsonObject()), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -2740,8 +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 TotpConfig(false), new MfaConfig(null, null), - new JsonObject()), + new TotpConfig(false), + null, null, new JsonObject()), false ); @@ -2873,13 +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), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - 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/SuperTokensSaaSSecretTest.java b/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java index bed7173e3..c9f73e2e1 100644 --- a/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java +++ b/src/test/java/io/supertokens/test/SuperTokensSaaSSecretTest.java @@ -358,8 +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 TotpConfig(false), new MfaConfig(null, null), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantConfig[] tenantConfigs = Multitenancy.getAllTenants(process.main); @@ -401,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - 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"); @@ -465,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - j), true); + new TotpConfig(false), + null, null, j), true); fail(); } catch (BadPermissionException e) { assertEquals(e.getMessage(), "Not allowed to modify protected configs."); @@ -552,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - j)); + new TotpConfig(false), + null, null, j)); { JsonObject response = HttpRequestForTesting.sendJsonRequest(process.getProcess(), "", @@ -632,8 +632,8 @@ public void testLogContainsCorrectCud() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 56daf54d4..dd2ce6b8a 100644 --- a/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java +++ b/src/test/java/io/supertokens/test/TestHelloAPIRateLimiting.java @@ -78,7 +78,7 @@ private void createApps(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -99,7 +99,7 @@ private void createApps(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -120,7 +120,7 @@ private void createApps(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + 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 36d564351..ebacc13df 100644 --- a/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java @@ -422,8 +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 TotpConfig(false), new MfaConfig(null, null), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", StorageLayer.getStorage(process.main)); @@ -469,8 +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 TotpConfig(false), new MfaConfig(null, null), - 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 1ef94dc17..23bab1b97 100644 --- a/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java @@ -465,8 +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 TotpConfig(false), new MfaConfig(null, null), - new JsonObject())); + new TotpConfig(false), + null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", StorageLayer.getStorage(process.main)); @@ -519,8 +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 TotpConfig(false), new MfaConfig(null, null), - 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 306907984..9c988bc4f 100644 --- a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java @@ -99,8 +99,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -120,8 +120,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -141,8 +141,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -162,8 +162,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 fdbf537da..56497c44c 100644 --- a/src/test/java/io/supertokens/test/accountlinking/SessionTests.java +++ b/src/test/java/io/supertokens/test/accountlinking/SessionTests.java @@ -89,8 +89,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -110,8 +110,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -131,8 +131,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -152,8 +152,8 @@ private void createTenants(Main main) new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 6803c6613..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,8 +452,8 @@ public void createPrimaryUserInTenantWithAnotherStorage() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 0112eb45d..a3f7fceb8 100644 --- a/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java @@ -122,7 +122,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, config ) ); @@ -143,7 +143,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, config ) ); @@ -164,7 +164,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 12efc86db..1654c3960 100644 --- a/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java +++ b/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java @@ -120,7 +120,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, config ) ); @@ -141,7 +141,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, config ) ); @@ -162,7 +162,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 8e3f86612..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,7 +109,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, config ) ); @@ -130,7 +130,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false),null, null, config ) ); @@ -151,7 +151,7 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 cb4dfd8a6..a8ad869ca 100644 --- a/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java +++ b/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java @@ -936,7 +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), new MfaConfig(null, null), + new TotpConfig(false), null, null, new JsonObject())); TenantIdentifierWithStorage tenantIdentifierWithStorage = new TenantIdentifierWithStorage(null, null, "t1", @@ -974,7 +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), new MfaConfig(null, null), + 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 518cab796..6ed9fdeaf 100644 --- a/src/test/java/io/supertokens/test/emailpassword/MultitenantEmailPasswordTest.java +++ b/src/test/java/io/supertokens/test/emailpassword/MultitenantEmailPasswordTest.java @@ -84,7 +84,7 @@ private void createTenants(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -105,7 +105,7 @@ private void createTenants(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -126,7 +126,7 @@ private void createTenants(TestingProcessManager.TestingProcess process) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + 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 db935ca1c..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,7 +117,7 @@ private void createTenants(Boolean includeHashingKey) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -142,7 +142,7 @@ private void createTenants(Boolean includeHashingKey) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -167,7 +167,7 @@ private void createTenants(Boolean includeHashingKey) new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + 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 b10386548..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,7 +105,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -126,7 +126,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -147,7 +147,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 f781a9dff..e1aa2e9bf 100644 --- a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java +++ b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java @@ -105,8 +105,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -114,8 +114,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); TenantIdentifierWithStorage tWithStorage = t.withStorage( @@ -147,8 +147,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -156,8 +156,8 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); UserIdMapping.assertThatUserIdIsNotBeingUsedInNonAuthRecipes(tWithStorage.toAppIdentifierWithStorage(), @@ -206,8 +206,8 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -215,8 +215,8 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); TenantIdentifierWithStorage appWithStorage = app.withStorage( @@ -281,8 +281,8 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantConfig( @@ -290,8 +290,8 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 64dd865ae..fa9a5f7c2 100644 --- a/src/test/java/io/supertokens/test/multitenant/ConfigTest.java +++ b/src/test/java/io/supertokens/test/multitenant/ConfigTest.java @@ -157,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); Assert.assertEquals(Config.getConfig(process.getProcess()).getRefreshTokenValidity(), (long) 144001 * 60 * 1000); @@ -210,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); fail(); } catch (InvalidConfigException e) { assert (e.getMessage() @@ -247,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); fail(); } catch (InvalidConfigException e) { assert (e.getMessage() @@ -298,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig)}, new ArrayList<>()); + new TotpConfig(false), + null, null, tenantConfig)}, new ArrayList<>()); } @@ -348,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -360,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -370,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -380,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } Config.loadAllTenantConfig(process.getProcess(), tenants, new ArrayList<>()); @@ -447,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } { @@ -459,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig); + new TotpConfig(false), + null, null, tenantConfig); } try { @@ -500,8 +500,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -513,8 +513,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -526,8 +526,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -539,8 +539,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -552,8 +552,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -565,8 +565,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -583,8 +583,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -596,8 +596,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -609,8 +609,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -622,8 +622,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -635,8 +635,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -648,8 +648,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -661,8 +661,8 @@ public void testCreationOfTenantsUsingValidSourceTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -708,8 +708,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -726,8 +726,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -739,8 +739,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -757,8 +757,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); @@ -770,8 +770,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -788,8 +788,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -806,8 +806,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -824,8 +824,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -842,8 +842,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -860,8 +860,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -878,8 +878,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -896,8 +896,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -914,8 +914,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -932,8 +932,8 @@ public void testInvalidCasesOfTenantCreation() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); fail(); @@ -973,8 +973,8 @@ public void testUpdationOfDefaultTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -1012,8 +1012,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); } @@ -1031,8 +1031,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); fail(); @@ -1050,8 +1050,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ) ); @@ -1066,8 +1066,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); } @@ -1084,8 +1084,8 @@ public void testThatDifferentTenantsInSameAppCannotHaveDifferentAPIKeys() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ) ); } @@ -1161,8 +1161,8 @@ public void testConfigNormalisation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1182,8 +1182,8 @@ public void testConfigNormalisation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig2 = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1221,8 +1221,8 @@ public void testTenantConfigIsNormalisedFromCUD1() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1240,8 +1240,8 @@ public void testTenantConfigIsNormalisedFromCUD1() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1283,8 +1283,8 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1302,8 +1302,8 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1321,8 +1321,8 @@ public void testTenantConfigIsNormalisedFromCUD2() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfigJson + new TotpConfig(false), + null, null, coreConfigJson ), false); CoreConfig coreConfig = Config.getConfig(tenantIdentifier, process.getProcess()); @@ -1355,8 +1355,8 @@ public void testInvalidConfigWhileCreatingNewTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); fail(); } catch (InvalidConfigException e) { @@ -1389,8 +1389,8 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1405,8 +1405,8 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1426,8 +1426,8 @@ public void testThatConfigChangesReloadsConfig() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Config configAfter = Config.getInstance(t1, process.getProcess()); @@ -1462,16 +1462,16 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1486,16 +1486,16 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig - ), false); + new TotpConfig(false), + null, null, coreConfig + ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1514,8 +1514,8 @@ public void testThatConfigChangesInAppReloadsConfigInTenant() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Config configAfter = Config.getInstance(t1, process.getProcess()); @@ -1549,8 +1549,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1564,8 +1564,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1584,8 +1584,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Storage storageLayerAfter = StorageLayer.getStorage(t1, process.getProcess()); @@ -1605,8 +1605,8 @@ public void testThatConfigChangesReloadsStorageLayer() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); Storage storageLayerAfter = StorageLayer.getStorage(t1, process.getProcess()); @@ -1640,8 +1640,8 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1656,8 +1656,8 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1676,8 +1676,8 @@ public void testThatConfigChangesReloadsFeatureFlag() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); FeatureFlag featureFlagAfter = FeatureFlag.getInstance(process.getProcess(), t1); @@ -1711,8 +1711,8 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); } @@ -1730,8 +1730,8 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); assertNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.TENANTS_CHANGED_DURING_REFRESH_FROM_DB)); @@ -1760,8 +1760,8 @@ public void testThatConfigChangesReloadsSigningKeys() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - coreConfig + new TotpConfig(false), + null, null, coreConfig ), false); AccessTokenSigningKey accessTokenSigningKeyAfter = AccessTokenSigningKey.getInstance(t1, process.getProcess()); @@ -1803,8 +1803,8 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ), false); // Now load a new set of configs @@ -1823,32 +1823,32 @@ public void testLoadAllTenantConfigWithDifferentConfigSavedInTheDb() throws Exce new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config1 + new TotpConfig(false), + null, null, config1 ), new TenantConfig( new TenantIdentifier(null, "a2", null), new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config2 + new TotpConfig(false), + null, null, config2 ), new TenantConfig( new TenantIdentifier(null, "a2", "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config3 + new TotpConfig(false), + null, null, config3 ), new TenantConfig( new TenantIdentifier(null, "a1", null), new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config4 + new TotpConfig(false), + null, null, config4 ), }; Config.loadAllTenantConfig(process.getProcess(), tenantConfigs); @@ -1894,8 +1894,8 @@ public void testThatMistypedConfigThrowsError() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - mistypedConfig + new TotpConfig(false), + null, null, mistypedConfig ), false); fail(); } catch (InvalidConfigException e) { @@ -1948,8 +1948,8 @@ public void testCoreSpecificConfigIsNotAllowedForNewTenants() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ), false); fail(); } catch (InvalidConfigException e) { @@ -2038,8 +2038,8 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ), false); fail(); } catch (InvalidConfigException e) { @@ -2102,8 +2102,8 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ), false); JsonObject config2 = new JsonObject(); @@ -2124,8 +2124,8 @@ public void testAllConflictingConfigs() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 0afb4d88b..b691cde88 100644 --- a/src/test/java/io/supertokens/test/multitenant/LoadTest.java +++ b/src/test/java/io/supertokens/test/multitenant/LoadTest.java @@ -75,8 +75,8 @@ public void testCreating100TenantsAndCheckOnlyOneInstanceOfStorageLayerIsCreated new EmailPasswordConfig(false), new ThirdPartyConfig(false, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - 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 9be6b3cca..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,45 +80,45 @@ public void testLogThatEachLineIsUniqueOnStartup() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 TotpConfig(false), new MfaConfig(null, null), - 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 TotpConfig(false), new MfaConfig(null, null), - 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 TotpConfig(false), new MfaConfig(null, null), - 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 TotpConfig(false), new MfaConfig(null, null), - 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 TotpConfig(false), new MfaConfig(null, null), - 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/RequestConnectionUriDomainTest.java b/src/test/java/io/supertokens/test/multitenant/RequestConnectionUriDomainTest.java index 7f1e4330c..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,13 +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), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - tenant2Config), false); + new TotpConfig(false), + null, null, tenant2Config), false); Webserver.getInstance(process.getProcess()).addAPI(new WebserverAPI(process.getProcess(), "") { @@ -251,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -260,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig), + new TotpConfig(false), + null, null, tenantConfig), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -269,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenant2Config), + new TotpConfig(false), + null, null, tenant2Config), false ); Multitenancy.addNewOrUpdateAppOrTenant( @@ -278,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - 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 c37ae35f5..97ca78fc7 100644 --- a/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java +++ b/src/test/java/io/supertokens/test/multitenant/SigningKeysTest.java @@ -118,8 +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), - new TotpConfig(false), new MfaConfig(null, null), - tenantConfig)}; + new TotpConfig(false), + null, null, tenantConfig)}; for (TenantConfig config : tenants) { Multitenancy.addNewOrUpdateAppOrTenant(process.getProcess(), new TenantIdentifier(null, null, null), @@ -190,13 +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), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - 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 93d8364e8..b78f69997 100644 --- a/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java +++ b/src/test/java/io/supertokens/test/multitenant/StorageLayerTest.java @@ -183,8 +183,8 @@ public void testUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -289,8 +289,8 @@ public void testUpdationOfDefaultTenantWithNullClientType() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -393,8 +393,8 @@ public void testForNullsInUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -488,8 +488,8 @@ public void testForNullClientsListInUpdationOfDefaultTenant() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -556,8 +556,8 @@ public void testForNullProvidersListInUpdationOfDefaultTenant() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -641,8 +641,8 @@ public void testCreateTenantPersistsDataCorrectly() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); TenantConfig[] tenantConfigs = mtStorage.getAllTenants(); @@ -758,8 +758,8 @@ public void testCreationOfDuplicationTenantThrowsDuplicateTenantException() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); try { @@ -797,8 +797,8 @@ public void testCreationOfDuplicationTenantThrowsDuplicateTenantException() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateTenantException e) { @@ -908,8 +908,8 @@ public void testOverwriteTenantOfNonExistantTenantThrowsTenantOrAppNotFoundExcep ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (TenantOrAppNotFoundException e) { @@ -1012,8 +1012,8 @@ public void testCreateTenantWithDuplicateProviderIdThrowsException() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateThirdPartyIdException e) { @@ -1089,8 +1089,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderIdThrowsDuplicateTenan ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); } catch (DuplicateTenantException e) { fail(); @@ -1159,8 +1159,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderIdThrowsDuplicateTenan ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateTenantException e) { @@ -1236,8 +1236,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderClientTypeThrowsDuplic ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); } catch (DuplicateTenantException e) { fail(); @@ -1286,8 +1286,8 @@ public void testCreateDuplicateTenantWithDuplicateProviderClientTypeThrowsDuplic ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateTenantException e) { @@ -1399,8 +1399,8 @@ public void testCreateTenantWithDuplicateClientTypeThrowsException() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateClientTypeException e) { @@ -1504,8 +1504,8 @@ public void testOverwriteTenantWithDuplicateProviderIdThrowsException() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateThirdPartyIdException e) { @@ -1617,8 +1617,8 @@ public void testOverwriteTenantWithDuplicateClientTypeThrowsException() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); fail(); } catch (DuplicateClientTypeException e) { @@ -1707,8 +1707,8 @@ public void testOverwriteTenantForRaceConditions() ) }), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() )); break; } catch (Exception e) { @@ -1792,32 +1792,32 @@ public void testThatStoragePointingToSameDbSharesThInstance() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config1 + new TotpConfig(false), + null, null, config1 ), new TenantConfig( new TenantIdentifier(null, null, "t2"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config1 + new TotpConfig(false), + null, null, config1 ), new TenantConfig( new TenantIdentifier(null, "a1", null), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config2 + new TotpConfig(false), + null, null, config2 ), new TenantConfig( new TenantIdentifier(null, "a1", "t1"), new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config2 + new TotpConfig(false), + null, null, config2 ) }); @@ -1874,8 +1874,8 @@ public void testThatStorageIsClosedAfterTenantDeletion() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ), false); Storage storage = StorageLayer.getStorage(new TenantIdentifier(null, null, "t1"), process.getProcess()); @@ -1921,16 +1921,16 @@ public void testThatStorageIsClosedOnlyWhenNoMoreTenantsArePointingToIt() throws new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ), false); Storage storage = StorageLayer.getStorage(new TenantIdentifier(null, null, "t1"), process.getProcess()); @@ -1981,16 +1981,16 @@ public void testStorageDoesNotLoadAgainAfterTenantDeletionWhenRefreshedFromDb() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ), false); @@ -2063,8 +2063,8 @@ public void testThatOriginalStorageIsNotClosedIfTheStorageForATenantChangesAndTh new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - new JsonObject() + new TotpConfig(false), + null, null, new JsonObject() ), false); Storage storage = StorageLayer.getBaseStorage(process.getProcess()); @@ -2079,8 +2079,8 @@ public void testThatOriginalStorageIsNotClosedIfTheStorageForATenantChangesAndTh new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 36397449c..20f06c851 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", "first_factors", "default_required_factor_ids"}; TenantIdentifier app = new TenantIdentifier(null, "a1", null); @@ -113,8 +112,8 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 d179dde68..fb1341656 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestApp.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestApp.java @@ -528,7 +528,7 @@ public void testTotpEnabledBoolean() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); response = TestMultitenancyAPIHelper.createApp( process.getProcess(), @@ -598,7 +598,7 @@ public void testFirstFactorsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + assertTrue(tenant.get("firstFactors").isJsonNull()); // builtin firstFactor String[] firstFactors = new String[]{"otp-phone"}; @@ -612,9 +612,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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(), @@ -626,9 +626,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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"}; @@ -642,9 +642,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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"}; @@ -658,9 +658,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); response = TestMultitenancyAPIHelper.createApp( process.getProcess(), @@ -672,7 +672,7 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + assertTrue(tenant.get("firstFactors").isJsonNull()); } @Test @@ -694,7 +694,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); // builtin firstFactor String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; @@ -708,9 +708,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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(), @@ -722,9 +722,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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"}; @@ -738,9 +738,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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"}; @@ -754,9 +754,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(4, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); response = TestMultitenancyAPIHelper.createApp( process.getProcess(), @@ -768,7 +768,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); } } 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 489baac33..1d294bdfc 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java @@ -509,7 +509,7 @@ public void testTotpEnabledBoolean() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertFalse(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); + assertTrue(tenant.get("totp").getAsJsonObject().get("enabled").getAsBoolean()); response = TestMultitenancyAPIHelper.createConnectionUriDomain( process.getProcess(), @@ -579,7 +579,7 @@ public void testFirstFactorsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + assertTrue(tenant.get("firstFactors").isJsonNull()); // builtin firstFactor String[] firstFactors = new String[]{"otp-phone"}; @@ -593,9 +593,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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(), @@ -607,9 +607,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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"}; @@ -623,9 +623,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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"}; @@ -639,9 +639,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); response = TestMultitenancyAPIHelper.createConnectionUriDomain( process.getProcess(), @@ -653,7 +653,7 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + assertTrue(tenant.get("firstFactors").isJsonNull()); } @Test @@ -675,7 +675,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); // builtin firstFactor String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; @@ -689,9 +689,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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(), @@ -703,9 +703,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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"}; @@ -719,9 +719,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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"}; @@ -735,9 +735,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(4, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); response = TestMultitenancyAPIHelper.createConnectionUriDomain( process.getProcess(), @@ -749,6 +749,6 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); } } 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 84f5f3490..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,8 +68,8 @@ public void testSkipValidation() throws Exception { new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - 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 3cab78b20..0cd2a60a8 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java @@ -436,7 +436,7 @@ public void testFirstFactorsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + assertTrue(tenant.get("firstFactors").isJsonNull()); // builtin firstFactor String[] firstFactors = new String[]{"otp-phone"}; @@ -450,9 +450,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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(), @@ -464,9 +464,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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"}; @@ -480,9 +480,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + 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"}; @@ -496,9 +496,9 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonArray()); - assertEquals(4, tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("firstFactors").getAsJsonArray(), String[].class)); + assertTrue(tenant.get("firstFactors").isJsonArray()); + assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); + assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), @@ -510,7 +510,7 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("firstFactors").isJsonNull()); + assertTrue(tenant.get("firstFactors").isJsonNull()); } @Test @@ -532,7 +532,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); // builtin firstFactor String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; @@ -546,9 +546,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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(), @@ -560,9 +560,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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"}; @@ -576,9 +576,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(1, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + 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"}; @@ -592,9 +592,9 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonArray()); - assertEquals(4, tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); + assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); + assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), @@ -606,6 +606,6 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("mfa").getAsJsonObject().get("defaultRequiredFactorIds").isJsonNull()); + assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); } } 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 212cc8698..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,8 +121,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -142,8 +142,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -163,8 +163,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(true, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } diff --git a/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java b/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java deleted file mode 100644 index 4e928d2a4..000000000 --- a/src/test/java/io/supertokens/test/multitenant/generator/GenerateMfaConfig.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.HashSet; -import java.util.Random; -import java.util.Set; - -public class GenerateMfaConfig { - 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_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)); - } -} 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 77833877e..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( @@ -54,10 +97,31 @@ public static ConfigGenerator.GeneratedValueAndExpectation generate_totpConfig() return ConfigGenerator.generate(TotpConfig.class); } - public static ConfigGenerator.GeneratedValueAndExpectation generate_mfaConfig() - throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, IllegalAccessException, - InstantiationException { - return ConfigGenerator.generate(MfaConfig.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() { 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 50d0b45e3..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,7 +108,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -129,7 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -150,7 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 c31966044..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,7 +109,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -130,7 +130,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -151,7 +151,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 f85b9a0d8..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,7 +108,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -129,7 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -150,7 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(true, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), + 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 5476133c1..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,7 +108,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -129,7 +129,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + new TotpConfig(false), null, null, config ) ); @@ -150,7 +150,7 @@ private void createTenants() new EmailPasswordConfig(false), new ThirdPartyConfig(false, null), new PasswordlessConfig(true), - new TotpConfig(false), new MfaConfig(null, null), + 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 3c54fbc6c..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,8 +106,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -127,8 +127,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -148,8 +148,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } @@ -169,8 +169,8 @@ private void createTenants() new EmailPasswordConfig(true), new ThirdPartyConfig(false, null), new PasswordlessConfig(false), - new TotpConfig(false), new MfaConfig(null, null), - config + new TotpConfig(false), + null, null, config ) ); } From 8683b9a40299e7ef5ddfe3dbaecbc48f56831f93 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 25 Oct 2023 18:03:21 +0530 Subject: [PATCH 14/16] fix: tests --- .../supertokens/test/multitenant/api/TestApp.java | 13 +++++++------ .../multitenant/api/TestConnectionUriDomain.java | 13 +++++++------ .../test/multitenant/api/TestTenant.java | 13 +++++++------ 3 files changed, 21 insertions(+), 18 deletions(-) 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 fb1341656..a32fe75f0 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestApp.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestApp.java @@ -51,6 +51,7 @@ import java.io.IOException; import java.rmi.ServerException; +import java.util.Set; import static org.junit.Assert.*; @@ -598,7 +599,7 @@ public void testFirstFactorsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("firstFactors").isJsonNull()); + assertNull(tenant.get("firstFactors")); // builtin firstFactor String[] firstFactors = new String[]{"otp-phone"}; @@ -660,7 +661,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("firstFactors").isJsonArray()); assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + assertEquals(Set.of(firstFactors), Set.of(new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class))); response = TestMultitenancyAPIHelper.createApp( process.getProcess(), @@ -672,7 +673,7 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("firstFactors").isJsonNull()); + assertNull(tenant.get("firstFactors")); } @Test @@ -694,7 +695,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); + assertNull(tenant.get("defaultRequiredFactorIds")); // builtin firstFactor String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; @@ -756,7 +757,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + assertEquals(Set.of(defaultRequiredFactorIds), Set.of(new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class))); response = TestMultitenancyAPIHelper.createApp( process.getProcess(), @@ -768,7 +769,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, "a1", null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); + assertNull(tenant.get("defaultRequiredFactorIds")); } } 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 1d294bdfc..39a70a157 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java @@ -48,6 +48,7 @@ import org.junit.Test; import java.io.IOException; +import java.util.Set; import static org.junit.Assert.*; @@ -579,7 +580,7 @@ public void testFirstFactorsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("firstFactors").isJsonNull()); + assertNull(tenant.get("firstFactors")); // builtin firstFactor String[] firstFactors = new String[]{"otp-phone"}; @@ -641,7 +642,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("firstFactors").isJsonArray()); assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + assertEquals(Set.of(firstFactors), Set.of(new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class))); response = TestMultitenancyAPIHelper.createConnectionUriDomain( process.getProcess(), @@ -653,7 +654,7 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("firstFactors").isJsonNull()); + assertNull(tenant.get("firstFactors")); } @Test @@ -675,7 +676,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); + assertNull(tenant.get("defaultRequiredFactorIds")); // builtin firstFactor String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; @@ -737,7 +738,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + assertEquals(Set.of(defaultRequiredFactorIds), Set.of(new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class))); response = TestMultitenancyAPIHelper.createConnectionUriDomain( process.getProcess(), @@ -749,6 +750,6 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier("127.0.0.1", null, null), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); + assertNull(tenant.get("defaultRequiredFactorIds")); } } 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 0cd2a60a8..e4c849b8e 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java @@ -46,6 +46,7 @@ import org.junit.Test; import java.io.IOException; +import java.util.Set; import static org.junit.Assert.*; @@ -436,7 +437,7 @@ public void testFirstFactorsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("firstFactors").isJsonNull()); + assertNull(tenant.get("firstFactors")); // builtin firstFactor String[] firstFactors = new String[]{"otp-phone"}; @@ -498,7 +499,7 @@ public void testFirstFactorsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("firstFactors").isJsonArray()); assertEquals(4, tenant.get("firstFactors").getAsJsonArray().size()); - assertEquals(firstFactors, new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class)); + assertEquals(Set.of(firstFactors), Set.of(new Gson().fromJson(tenant.get("firstFactors").getAsJsonArray(), String[].class))); response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), @@ -510,7 +511,7 @@ public void testFirstFactorsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("firstFactors").isJsonNull()); + assertNull(tenant.get("firstFactors")); } @Test @@ -532,7 +533,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { JsonObject tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); + assertNull(tenant.get("defaultRequiredFactorIds")); // builtin firstFactor String[] defaultRequiredFactorIds = new String[]{"otp-phone"}; @@ -594,7 +595,7 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { process.getProcess(), SemVer.v4_1); assertTrue(tenant.get("defaultRequiredFactorIds").isJsonArray()); assertEquals(4, tenant.get("defaultRequiredFactorIds").getAsJsonArray().size()); - assertEquals(defaultRequiredFactorIds, new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class)); + assertEquals(Set.of(defaultRequiredFactorIds), Set.of(new Gson().fromJson(tenant.get("defaultRequiredFactorIds").getAsJsonArray(), String[].class))); response = TestMultitenancyAPIHelper.createTenant( process.getProcess(), @@ -606,6 +607,6 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { tenant = TestMultitenancyAPIHelper.getTenant(new TenantIdentifier(null, null, "t1"), process.getProcess(), SemVer.v4_1); - assertTrue(tenant.get("defaultRequiredFactorIds").isJsonNull()); + assertNull(tenant.get("defaultRequiredFactorIds")); } } From 59c794e803cafc79c2448052e73e805d05475ea9 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 26 Oct 2023 12:34:57 +0530 Subject: [PATCH 15/16] fix: tests --- src/test/java/io/supertokens/test/multitenant/TestAppData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/supertokens/test/multitenant/TestAppData.java b/src/test/java/io/supertokens/test/multitenant/TestAppData.java index 20f06c851..988b93185 100644 --- a/src/test/java/io/supertokens/test/multitenant/TestAppData.java +++ b/src/test/java/io/supertokens/test/multitenant/TestAppData.java @@ -103,7 +103,7 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { return; } - String[] tablesToIgnore = new String[]{"tenant_thirdparty_provider_clients", "tenant_thirdparty_providers", "first_factors", "default_required_factor_ids"}; + 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); From b6f6ac00d3c62b1e6a6612baa72769ae857067cf Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 26 Oct 2023 13:13:16 +0530 Subject: [PATCH 16/16] fix: pr comments --- .../multitenancy/CreateOrUpdateAppAPI.java | 9 +++++ .../CreateOrUpdateConnectionUriDomainAPI.java | 9 +++++ .../CreateOrUpdateTenantOrGetTenantAPI.java | 9 +++++ .../test/multitenant/api/TestApp.java | 38 +++++++++++++++++++ .../api/TestConnectionUriDomain.java | 38 +++++++++++++++++++ .../test/multitenant/api/TestTenant.java | 38 +++++++++++++++++++ 6 files changed, 141 insertions(+) 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 2b109cd0c..7df23ccf1 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateAppAPI.java @@ -29,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 CreateOrUpdateAppAPI extends BaseCreateOrUpdate { @@ -71,6 +74,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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()) { @@ -79,6 +85,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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")); + } } } 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 c42499ee0..dd3298b89 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateConnectionUriDomainAPI.java @@ -29,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 { @@ -71,6 +74,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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()) { @@ -79,6 +85,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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")); + } } } 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 e8008418a..c42b1a10d 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/CreateOrUpdateTenantOrGetTenantAPI.java @@ -31,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 { @@ -74,6 +77,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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()) { @@ -82,6 +88,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO 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")); + } } } 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 a32fe75f0..127a82143 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestApp.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestApp.java @@ -772,4 +772,42 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { 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 39a70a157..debbb2948 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestConnectionUriDomain.java @@ -752,4 +752,42 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { 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/TestTenant.java b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java index e4c849b8e..967300276 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenant.java @@ -609,4 +609,42 @@ public void testDefaultRequiredFactorIdsArray() throws Exception { 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()); + } + + } }