From 388d398cd0bb2f6ce8e1a3d3040baf6afaed0802 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 5 Mar 2024 15:32:34 +0530 Subject: [PATCH] fix: cicd tests (#946) * fix: cicd tests * fix: cicd tests * fix: cicd tests * fix: cicd tests * fix: cicd tests --- .../storageLayer/StorageLayer.java | 11 +++++++ .../api/TestWithNonAuthRecipes.java | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/main/java/io/supertokens/storageLayer/StorageLayer.java b/src/main/java/io/supertokens/storageLayer/StorageLayer.java index 1de61142a..5145e7c1c 100644 --- a/src/main/java/io/supertokens/storageLayer/StorageLayer.java +++ b/src/main/java/io/supertokens/storageLayer/StorageLayer.java @@ -24,6 +24,7 @@ import io.supertokens.inmemorydb.Start; import io.supertokens.output.Logging; import io.supertokens.pluginInterface.LOG_LEVEL; +import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.authRecipe.AuthRecipeStorage; import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; @@ -461,6 +462,16 @@ public static StorageAndUserIdMapping findStorageAndUserIdMappingForUser( AppIdentifier appIdentifier, Storage[] storages, String userId, UserIdType userIdType) throws StorageQueryException, UnknownUserIdException { + if (storages.length == 0) { + throw new IllegalStateException("should never come here"); + } + + if (storages[0].getType() != STORAGE_TYPE.SQL) { + // for non sql plugin, there will be only one storage as multitenancy is not supported + assert storages.length == 1; + return new StorageAndUserIdMapping(storages[0], null); + } + if (userIdType == UserIdType.SUPERTOKENS) { for (Storage storage : storages) { if (((AuthRecipeStorage) storage).doesUserIdExist(appIdentifier, userId)) { diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestWithNonAuthRecipes.java b/src/test/java/io/supertokens/test/multitenant/api/TestWithNonAuthRecipes.java index 84a93064d..7798ce2bf 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestWithNonAuthRecipes.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestWithNonAuthRecipes.java @@ -24,6 +24,7 @@ import io.supertokens.featureflag.exceptions.FeatureNotEnabledException; import io.supertokens.multitenancy.exception.BadPermissionException; import io.supertokens.multitenancy.exception.CannotModifyBaseConfigException; +import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.StorageUtils; import io.supertokens.pluginInterface.authRecipe.AuthRecipeUserInfo; @@ -76,6 +77,14 @@ public void beforeEach() throws InterruptedException, InvalidProviderConfigExcep process.startProcess(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED)); + if (StorageLayer.getBaseStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + if (StorageLayer.isInMemDb(process.getProcess())) { + return; + } + JsonObject config = new JsonObject(); StorageLayer.getBaseStorage(process.getProcess()).modifyConfigToAddANewUserPoolForTesting(config, 1); TestMultitenancyAPIHelper.createTenant(process.getProcess(), TenantIdentifier.BASE_TENANT, "t1", true, true, @@ -87,6 +96,14 @@ public void beforeEach() throws InterruptedException, InvalidProviderConfigExcep @Test public void testThatUserMetadataIsSavedInTheStorageWhereUserExists() throws Exception { + if (StorageLayer.getBaseStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + if (StorageLayer.isInMemDb(process.getProcess())) { + return; + } + TenantIdentifier t0 = new TenantIdentifier(null, null, null); Storage t0Storage = (StorageLayer.getStorage(t0, process.getProcess())); @@ -176,6 +193,14 @@ public void testThatUserMetadataIsSavedInTheStorageWhereUserExists() throws Exce @Test public void testThatRoleIsStoredInPublicTenantAndUserRoleMappingInTheUserTenantStorage() throws Exception { + if (StorageLayer.getBaseStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + if (StorageLayer.isInMemDb(process.getProcess())) { + return; + } + TenantIdentifier t0 = new TenantIdentifier(null, null, null); Storage t0Storage = (StorageLayer.getStorage(t0, process.getProcess())); @@ -266,6 +291,14 @@ public void testThatRoleIsStoredInPublicTenantAndUserRoleMappingInTheUserTenantS @Test public void testEmailVerificationWithUsersOnDifferentTenantStorages() throws Exception { + if (StorageLayer.getBaseStorage(process.getProcess()).getType() != STORAGE_TYPE.SQL) { + return; + } + + if (StorageLayer.isInMemDb(process.getProcess())) { + return; + } + TenantIdentifier t0 = new TenantIdentifier(null, null, null); Storage t0Storage = (StorageLayer.getStorage(t0, process.getProcess()));