diff --git a/src/main/java/io/supertokens/useridmapping/UserIdMapping.java b/src/main/java/io/supertokens/useridmapping/UserIdMapping.java index 687e8fea2..4bd304811 100644 --- a/src/main/java/io/supertokens/useridmapping/UserIdMapping.java +++ b/src/main/java/io/supertokens/useridmapping/UserIdMapping.java @@ -27,6 +27,7 @@ import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException; import io.supertokens.pluginInterface.jwt.JWTRecipeStorage; +import io.supertokens.pluginInterface.mfa.MfaStorage; import io.supertokens.pluginInterface.multitenancy.AppIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.TenantIdentifierWithStorage; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; @@ -342,6 +343,14 @@ public static void assertThatUserIdIsNotBeingUsedInNonAuthRecipes( new WebserverAPI.BadRequestException("UserId is already in use in EmailVerification recipe")); } } + { + if (storage.isUserIdBeingUsedInNonAuthRecipe(appIdentifierWithStorage, + MfaStorage.class.getName(), + userId)) { + throw new ServletException( + new WebserverAPI.BadRequestException("UserId is already in use in MFA recipe")); + } + } { if (storage.isUserIdBeingUsedInNonAuthRecipe(appIdentifierWithStorage, JWTRecipeStorage.class.getName(), diff --git a/src/test/java/io/supertokens/test/FeatureFlagTest.java b/src/test/java/io/supertokens/test/FeatureFlagTest.java index 1193c474f..480b60f2f 100644 --- a/src/test/java/io/supertokens/test/FeatureFlagTest.java +++ b/src/test/java/io/supertokens/test/FeatureFlagTest.java @@ -854,6 +854,9 @@ public void testNetworkCallIsMadeInCoreInit() throws Exception { private final String OPAQUE_KEY_WITH_ACCOUNT_LINKING_FEATURE = "N2uEOdEzd1XZZ5VBSTGYaM7Ia4s8wAqRWFAxLqTYrB6GQ=" + "vssOLo3c=PkFgcExkaXs=IA-d9UWccoNKsyUgNhOhcKtM1bjC5OLrYRpTAgN-2EbKYsQGGQRQHuUN4EO1V"; + private final String OPAQUE_KEY_WTIH_MFA_FEATURE = "F1a=1VUxo7-tHNqFDwuhkkCPCB378A57uRU4=rVW01XBv63YizRb6ItTBu" + + "FHXQIvmceLTlOekCmHv7mwzEZJJKmO9N8pclQSbs4UBz8pzW5d107TIctJgBwy4upnBHUf"; + @Test public void testPaidStatsContainsAllEnabledFeatures() throws Exception { String[] args = {"../"}; @@ -866,7 +869,8 @@ public void testPaidStatsContainsAllEnabledFeatures() throws Exception { OPAQUE_KEY_WITH_MULTITENANCY_FEATURE, OPAQUE_KEY_WITH_TOTP_FEATURE, OPAQUE_KEY_WITH_DASHBOARD_FEATURE, - OPAQUE_KEY_WITH_ACCOUNT_LINKING_FEATURE + OPAQUE_KEY_WITH_ACCOUNT_LINKING_FEATURE, + OPAQUE_KEY_WTIH_MFA_FEATURE }; Set requiredFeatures = new HashSet<>(); diff --git a/src/test/java/io/supertokens/test/StorageLayerTest.java b/src/test/java/io/supertokens/test/StorageLayerTest.java index df64313bd..1b9c72922 100644 --- a/src/test/java/io/supertokens/test/StorageLayerTest.java +++ b/src/test/java/io/supertokens/test/StorageLayerTest.java @@ -57,7 +57,8 @@ public static void insertUsedCodeUtil(TOTPSQLStorage storage, TOTPUsedCode usedC }); } catch (StorageTransactionLogicException e) { Exception actual = e.actualException; - if (actual instanceof UnknownDeviceException || actual instanceof UsedCodeAlreadyExistsException) { + if (actual instanceof UnknownDeviceException || actual instanceof UsedCodeAlreadyExistsException || + actual instanceof UnknownTotpUserIdException) { throw actual; } else { throw e; @@ -86,7 +87,7 @@ public void totpCodeLengthTest() throws Exception { TOTPDevice d1 = new TOTPDevice("user", "d1", "secret", 30, 1, false); storage.createDevice(new AppIdentifier(null, null), d1); - + // Try code with length > 8 try { TOTPUsedCode code = new TOTPUsedCode("user", "123456789", true, nextDay, now); @@ -103,5 +104,4 @@ public void totpCodeLengthTest() throws Exception { TOTPUsedCode code = new TOTPUsedCode("user", "12345678", true, nextDay, now); insertUsedCodeUtil(storage, code); } - } diff --git a/src/test/java/io/supertokens/test/multitenant/TestAppData.java b/src/test/java/io/supertokens/test/multitenant/TestAppData.java index 5d3b75039..225df2491 100644 --- a/src/test/java/io/supertokens/test/multitenant/TestAppData.java +++ b/src/test/java/io/supertokens/test/multitenant/TestAppData.java @@ -26,6 +26,7 @@ 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; @@ -95,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}); + new EE_FEATURES[]{EE_FEATURES.MULTI_TENANCY, EE_FEATURES.TOTP, EE_FEATURES.MFA}); process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); @@ -166,6 +167,9 @@ 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);