Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Sep 29, 2023
1 parent 0387df7 commit bbd412b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/main/java/io/supertokens/useridmapping/UserIdMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/io/supertokens/test/FeatureFlagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {"../"};
Expand All @@ -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<EE_FEATURES> requiredFeatures = new HashSet<>();
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/io/supertokens/test/StorageLayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -103,5 +104,4 @@ public void totpCodeLengthTest() throws Exception {
TOTPUsedCode code = new TOTPUsedCode("user", "12345678", true, nextDay, now);
insertUsedCodeUtil(storage, code);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bbd412b

Please sign in to comment.