From c58bf21f4b79a39a73d604417fce1136a2f962ed Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Tue, 5 Mar 2024 15:04:05 +0530 Subject: [PATCH] fix: cicd tests --- .../api/session/SessionRemoveAPI.java | 16 ++++++--- .../webserver/api/session/SessionUserAPI.java | 19 +++++++---- .../api/TestWithNonAuthRecipes.java | 33 +++++++++++++++++++ 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/supertokens/webserver/api/session/SessionRemoveAPI.java b/src/main/java/io/supertokens/webserver/api/session/SessionRemoveAPI.java index 2686de03d..3458e405e 100644 --- a/src/main/java/io/supertokens/webserver/api/session/SessionRemoveAPI.java +++ b/src/main/java/io/supertokens/webserver/api/session/SessionRemoveAPI.java @@ -120,13 +120,19 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I // exist, we use the storage for the tenantId passed in the request. AppIdentifier appIdentifier = getAppIdentifier(req); Storage[] storages = StorageLayer.getStoragesForApp(main, appIdentifier); - try { - StorageAndUserIdMapping storageAndUserIdMapping = StorageLayer.findStorageAndUserIdMappingForUser( - appIdentifier, storages, userId, UserIdType.ANY); - storage = storageAndUserIdMapping.storage; - } catch (UnknownUserIdException e) { + + if (StorageLayer.getBaseStorage(main).getType() == STORAGE_TYPE.SQL) { + try { + StorageAndUserIdMapping storageAndUserIdMapping = StorageLayer.findStorageAndUserIdMappingForUser( + appIdentifier, storages, userId, UserIdType.ANY); + storage = storageAndUserIdMapping.storage; + } catch (UnknownUserIdException e) { + storage = getTenantStorage(req); + } + } else { storage = getTenantStorage(req); } + sessionHandlesRevoked = Session.revokeAllSessionsForUser( main, appIdentifier, storage, userId, revokeSessionsForLinkedAccounts); } else { diff --git a/src/main/java/io/supertokens/webserver/api/session/SessionUserAPI.java b/src/main/java/io/supertokens/webserver/api/session/SessionUserAPI.java index 8e7b53e2e..f7f72f618 100644 --- a/src/main/java/io/supertokens/webserver/api/session/SessionUserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/session/SessionUserAPI.java @@ -23,6 +23,7 @@ import io.supertokens.StorageAndUserIdMapping; import io.supertokens.multitenancy.exception.BadPermissionException; import io.supertokens.pluginInterface.RECIPE_ID; +import io.supertokens.pluginInterface.STORAGE_TYPE; import io.supertokens.pluginInterface.Storage; import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException; import io.supertokens.pluginInterface.exceptions.StorageQueryException; @@ -85,14 +86,20 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO AppIdentifier appIdentifier = getAppIdentifier(req); Storage[] storages = StorageLayer.getStoragesForApp(main, appIdentifier); Storage storage; - try { - StorageAndUserIdMapping storageAndUserIdMapping = - StorageLayer.findStorageAndUserIdMappingForUser( - appIdentifier, storages, userId, UserIdType.ANY); - storage = storageAndUserIdMapping.storage; - } catch (UnknownUserIdException e) { + + if (StorageLayer.getBaseStorage(main).getType() == STORAGE_TYPE.SQL) { + try { + StorageAndUserIdMapping storageAndUserIdMapping = + StorageLayer.findStorageAndUserIdMappingForUser( + appIdentifier, storages, userId, UserIdType.ANY); + storage = storageAndUserIdMapping.storage; + } catch (UnknownUserIdException e) { + storage = getTenantStorage(req); + } + } else { storage = getTenantStorage(req); } + sessionHandles = Session.getAllNonExpiredSessionHandlesForUser( main, appIdentifier, storage, userId, fetchSessionsForAllLinkedAccounts); 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()));