From 311b9b054b79e9220becb4811ed866e95bc30eaf Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 4 Mar 2024 11:19:24 +0530 Subject: [PATCH] fix: PR comments --- src/main/java/io/supertokens/ActiveUsers.java | 20 +-- .../io/supertokens/authRecipe/AuthRecipe.java | 6 +- .../java/io/supertokens/inmemorydb/Start.java | 9 +- .../inmemorydb/queries/UserRolesQueries.java | 2 - .../io/supertokens/userroles/UserRoles.java | 24 +-- .../supertokens/webserver/WebserverAPI.java | 8 +- .../CanCreatePrimaryUserAPI.java | 2 +- .../accountlinking/CanLinkAccountsAPI.java | 4 +- .../accountlinking/CreatePrimaryUserAPI.java | 2 +- .../api/accountlinking/LinkAccountsAPI.java | 4 +- .../api/accountlinking/UnlinkAccountAPI.java | 2 +- .../api/core/ActiveUsersCountAPI.java | 5 +- .../webserver/api/core/ConfigAPI.java | 11 +- .../webserver/api/core/DeleteUserAPI.java | 2 +- .../webserver/api/core/GetUserByIdAPI.java | 2 +- .../webserver/api/core/HelloAPI.java | 8 +- .../webserver/api/emailpassword/UserAPI.java | 4 +- .../emailverification/UnverifyEmailAPI.java | 2 +- .../api/emailverification/VerifyEmailAPI.java | 2 +- .../api/multitenancy/ListTenantsAPI.java | 5 +- .../webserver/api/passwordless/UserAPI.java | 4 +- .../api/session/RefreshSessionAPI.java | 4 +- .../api/session/SessionRemoveAPI.java | 77 +++++++-- .../webserver/api/thirdparty/UserAPI.java | 2 +- .../api/totp/CreateOrUpdateTotpDeviceAPI.java | 13 +- .../webserver/api/totp/GetTotpDevicesAPI.java | 6 +- .../api/totp/RemoveTotpDeviceAPI.java | 5 +- .../webserver/api/totp/VerifyTotpAPI.java | 4 - .../api/totp/VerifyTotpDeviceAPI.java | 4 - .../useridmapping/RemoveUserIdMappingAPI.java | 2 +- .../UpdateExternalUserIdInfoAPI.java | 2 +- .../api/useridmapping/UserIdMappingAPI.java | 14 +- .../usermetadata/RemoveUserMetadataAPI.java | 2 +- .../api/usermetadata/UserMetadataAPI.java | 4 +- .../api/userroles/GetUsersForRoleAPI.java | 2 +- .../api/userroles/RemoveRoleAPI.java | 4 +- .../api/userroles/RemoveUserRoleAPI.java | 2 +- .../io/supertokens/test/FeatureFlagTest.java | 18 +-- .../accountlinking/CreatePrimaryUserTest.java | 10 +- .../GetUserByAccountInfoTest.java | 104 ++++++------- .../test/accountlinking/LinkAccountsTest.java | 10 +- .../test/accountlinking/MultitenantTest.java | 146 +++++++++--------- .../test/accountlinking/SessionTests.java | 66 ++++---- .../test/authRecipe/MultitenantAPITest.java | 28 ++-- .../test/authRecipe/UserPaginationTest.java | 12 +- .../dashboard/apis/MultitenantAPITest.java | 4 +- .../test/emailpassword/EmailPasswordTest.java | 10 +- .../test/multitenant/AppTenantUserTest.java | 36 ++--- .../test/multitenant/TestAppData.java | 44 +++--- .../multitenant/api/TestPermissionChecks.java | 6 +- .../TestTenantIdIsNotPresentForOlderCDI.java | 12 +- .../api/TestTenantUserAssociation.java | 78 +++++----- .../api/TestWithNonAuthRecipes.java | 28 ++-- .../test/totp/api/TotpUserIdMappingTest.java | 4 +- .../test/userRoles/UserRolesStorageTest.java | 5 +- 55 files changed, 449 insertions(+), 447 deletions(-) diff --git a/src/main/java/io/supertokens/ActiveUsers.java b/src/main/java/io/supertokens/ActiveUsers.java index 78d9885a4..7ee3c5534 100644 --- a/src/main/java/io/supertokens/ActiveUsers.java +++ b/src/main/java/io/supertokens/ActiveUsers.java @@ -31,29 +31,15 @@ public static void updateLastActive(Main main, String userId) { } } - public static int countUsersActiveSince(AppIdentifier appIdentifier, Storage storage, long time) + public static int countUsersActiveSince(Main main, AppIdentifier appIdentifier, long time) throws StorageQueryException, TenantOrAppNotFoundException { + Storage storage = StorageLayer.getStorage(appIdentifier.getAsPublicTenantIdentifier(), main); return StorageUtils.getActiveUsersStorage(storage).countUsersActiveSince(appIdentifier, time); } @TestOnly public static int countUsersActiveSince(Main main, long time) throws StorageQueryException, TenantOrAppNotFoundException { - return countUsersActiveSince(new AppIdentifier(null, null), - StorageLayer.getStorage(main), time); - } - - public static void removeActiveUser(AppIdentifier appIdentifier, Storage storage, String userId) - throws StorageQueryException { - try { - ((AuthRecipeSQLStorage) StorageUtils.getActiveUsersStorage(storage)).startTransaction(con -> { - StorageUtils.getActiveUsersStorage(storage).deleteUserActive_Transaction(con, appIdentifier, userId); - ((AuthRecipeSQLStorage) StorageUtils.getActiveUsersStorage(storage)).commitTransaction(con); - return null; - }); - - } catch (StorageTransactionLogicException e) { - throw new StorageQueryException(e.actualException); - } + return countUsersActiveSince(main, new AppIdentifier(null, null), time); } } diff --git a/src/main/java/io/supertokens/authRecipe/AuthRecipe.java b/src/main/java/io/supertokens/authRecipe/AuthRecipe.java index 6d355209f..e480f45f2 100644 --- a/src/main/java/io/supertokens/authRecipe/AuthRecipe.java +++ b/src/main/java/io/supertokens/authRecipe/AuthRecipe.java @@ -252,7 +252,7 @@ private static CanLinkAccountsResult canLinkAccountsHelper(TransactionConnection TenantIdentifier tenantIdentifier = new TenantIdentifier( appIdentifier.getConnectionUriDomain(), appIdentifier.getAppId(), tenantId); - // we do not bother with getting the tenantIdentifierWithStorage here because + // we do not bother with getting the storage for each tenant here because // we get the tenants from the user itself, and the user can only be shared across // tenants of the same storage - therefore, the storage will be the same. @@ -656,7 +656,7 @@ public static long getUsersCountForTenant(TenantIdentifier tenantIdentifier, tenantIdentifier, includeRecipeIds); } - public static long getUsersCountAcrossAllTenants(AppIdentifier appIdentappIdentifierfierWithStorages, + public static long getUsersCountAcrossAllTenants(AppIdentifier appIdentifier, Storage[] storages, RECIPE_ID[] includeRecipeIds) throws StorageQueryException, @@ -665,7 +665,7 @@ public static long getUsersCountAcrossAllTenants(AppIdentifier appIdentappIdenti for (Storage storage : storages) { count += StorageUtils.getAuthRecipeStorage(storage).getUsersCount( - appIdentappIdentifierfierWithStorages, includeRecipeIds); + appIdentifier, includeRecipeIds); } return count; diff --git a/src/main/java/io/supertokens/inmemorydb/Start.java b/src/main/java/io/supertokens/inmemorydb/Start.java index 129adee22..2dbcaaf54 100644 --- a/src/main/java/io/supertokens/inmemorydb/Start.java +++ b/src/main/java/io/supertokens/inmemorydb/Start.java @@ -1861,7 +1861,7 @@ public int deleteUserMetadata(AppIdentifier appIdentifier, String userId) throws @Override public void addRoleToUser(TenantIdentifier tenantIdentifier, String userId, String role) - throws StorageQueryException, UnknownRoleException, DuplicateUserRoleMappingException, + throws StorageQueryException, DuplicateUserRoleMappingException, TenantOrAppNotFoundException { try { UserRolesQueries.addRoleToUser(this, tenantIdentifier, userId, role); @@ -1870,13 +1870,6 @@ public void addRoleToUser(TenantIdentifier tenantIdentifier, String userId, Stri SQLiteConfig config = Config.getConfig(this); String serverErrorMessage = e.getMessage(); - if (isForeignKeyConstraintError( - serverErrorMessage, - config.getRolesTable(), - new String[]{"app_id", "role"}, - new Object[]{tenantIdentifier.getAppId(), role})) { - throw new UnknownRoleException(); - } if (isPrimaryKeyError(serverErrorMessage, config.getUserRolesTable(), new String[]{"app_id", "tenant_id", "user_id", "role"})) { throw new DuplicateUserRoleMappingException(); diff --git a/src/main/java/io/supertokens/inmemorydb/queries/UserRolesQueries.java b/src/main/java/io/supertokens/inmemorydb/queries/UserRolesQueries.java index 721bcae06..e9eb86980 100644 --- a/src/main/java/io/supertokens/inmemorydb/queries/UserRolesQueries.java +++ b/src/main/java/io/supertokens/inmemorydb/queries/UserRolesQueries.java @@ -74,8 +74,6 @@ public static String getQueryToCreateUserRolesTable(Start start) { + "user_id VARCHAR(128) NOT NULL," + "role VARCHAR(255) NOT NULL," + "PRIMARY KEY(app_id, tenant_id, user_id, role)," - + "FOREIGN KEY(app_id, role) REFERENCES " + Config.getConfig(start).getRolesTable() - + " (app_id, role) ON DELETE CASCADE," + "FOREIGN KEY(app_id, tenant_id) REFERENCES " + Config.getConfig(start).getTenantsTable() + " (app_id, tenant_id) ON DELETE CASCADE" + ");"; diff --git a/src/main/java/io/supertokens/userroles/UserRoles.java b/src/main/java/io/supertokens/userroles/UserRoles.java index ceb3a86ef..5d69d6e95 100644 --- a/src/main/java/io/supertokens/userroles/UserRoles.java +++ b/src/main/java/io/supertokens/userroles/UserRoles.java @@ -44,9 +44,7 @@ public static boolean addRoleToUser(Main main, TenantIdentifier tenantIdentifier // We do this because it's not straight forward to replicate roles to all storages of an app Storage appStorage = StorageLayer.getStorage( tenantIdentifier.toAppIdentifier().getAsPublicTenantIdentifier(), main); - - String[] roles = getRoles(tenantIdentifier.toAppIdentifier(), appStorage); - if (!Arrays.asList(roles).contains(role)) { + if (!doesRoleExist(tenantIdentifier.toAppIdentifier(), appStorage, role)) { throw new UnknownRoleException(); } @@ -287,15 +285,23 @@ public static String[] getRolesThatHavePermission(Main main, } // delete a role - public static boolean deleteRole(AppIdentifier appIdentifier, Storage storage, String role) - throws StorageQueryException { - return StorageUtils.getUserRolesStorage(storage).deleteRole(appIdentifier, role); + public static boolean deleteRole(Main main, AppIdentifier appIdentifier, String role) + throws StorageQueryException, TenantOrAppNotFoundException { + + Storage[] storages = StorageLayer.getStoragesForApp(main, appIdentifier); + boolean deletedRole = false; + for (Storage storage : storages) { + UserRolesSQLStorage userRolesStorage = StorageUtils.getUserRolesStorage(storage); + deletedRole = userRolesStorage.deleteRole(appIdentifier, role) || deletedRole; + } + + return deletedRole; } @TestOnly - public static boolean deleteRole(Main main, String role) throws StorageQueryException { - Storage storage = StorageLayer.getStorage(main); - return deleteRole(new AppIdentifier(null, null), storage, role); + public static boolean deleteRole(Main main, String role) throws StorageQueryException, + TenantOrAppNotFoundException { + return deleteRole(main, new AppIdentifier(null, null), role); } // retrieve all roles that have been created diff --git a/src/main/java/io/supertokens/webserver/WebserverAPI.java b/src/main/java/io/supertokens/webserver/WebserverAPI.java index 60f311efc..65cb7c200 100644 --- a/src/main/java/io/supertokens/webserver/WebserverAPI.java +++ b/src/main/java/io/supertokens/webserver/WebserverAPI.java @@ -231,7 +231,7 @@ private String getTenantId(HttpServletRequest req) { apiPath = "/" + apiPath; } if (apiPath.equals("/")) { - if ((path.equals("") || path.equals("/"))) { + if (path.equals("") || path.equals("/")) { return null; } } else { @@ -316,7 +316,7 @@ protected Storage getTenantStorage(HttpServletRequest req) protected Storage[] enforcePublicTenantAndGetAllStoragesForApp(HttpServletRequest req) throws ServletException, BadPermissionException, TenantOrAppNotFoundException { if (getTenantId(req) != null) { - throw new BadPermissionException("Only public tenantId can this app specific API"); + throw new BadPermissionException("Only public tenantId can call this app specific API"); } AppIdentifier appIdentifier = getAppIdentifier(req); @@ -330,7 +330,7 @@ protected Storage enforcePublicTenantAndGetPublicTenantStorage( this.getTenantId(req)); if (getTenantId(req) != null) { - throw new BadPermissionException("Only public tenantId can this app specific API"); + throw new BadPermissionException("Only public tenantId can call this app specific API"); } return StorageLayer.getStorage(tenantIdentifier, main); @@ -345,7 +345,7 @@ protected StorageAndUserIdMapping getStorageAndUserIdMappingForTenantSpecificApi userIdType); } - protected StorageAndUserIdMapping getStorageAndUserIdMappingForAppSpecificApi( + protected StorageAndUserIdMapping enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( HttpServletRequest req, String userId, UserIdType userIdType) throws StorageQueryException, TenantOrAppNotFoundException, UnknownUserIdException, ServletException, BadPermissionException { diff --git a/src/main/java/io/supertokens/webserver/api/accountlinking/CanCreatePrimaryUserAPI.java b/src/main/java/io/supertokens/webserver/api/accountlinking/CanCreatePrimaryUserAPI.java index 55917b79a..589cf3fdf 100644 --- a/src/main/java/io/supertokens/webserver/api/accountlinking/CanCreatePrimaryUserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/accountlinking/CanCreatePrimaryUserAPI.java @@ -61,7 +61,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO try { String userId = inputRecipeUserId; StorageAndUserIdMapping storageAndMapping = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, inputRecipeUserId, UserIdType.ANY); storage = storageAndMapping.storage; if (storageAndMapping.userIdMapping != null) { diff --git a/src/main/java/io/supertokens/webserver/api/accountlinking/CanLinkAccountsAPI.java b/src/main/java/io/supertokens/webserver/api/accountlinking/CanLinkAccountsAPI.java index 83e2671cb..bc8011efc 100644 --- a/src/main/java/io/supertokens/webserver/api/accountlinking/CanLinkAccountsAPI.java +++ b/src/main/java/io/supertokens/webserver/api/accountlinking/CanLinkAccountsAPI.java @@ -65,7 +65,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO String recipeUserId = inputRecipeUserId; { StorageAndUserIdMapping mappingAndStorage = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, inputRecipeUserId, UserIdType.ANY); if (mappingAndStorage.userIdMapping != null) { recipeUserId = mappingAndStorage.userIdMapping.superTokensUserId; @@ -75,7 +75,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO String primaryUserId = inputPrimaryUserId; { StorageAndUserIdMapping mappingAndStorage = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, inputPrimaryUserId, UserIdType.ANY); if (mappingAndStorage.userIdMapping != null) { primaryUserId = mappingAndStorage.userIdMapping.superTokensUserId; diff --git a/src/main/java/io/supertokens/webserver/api/accountlinking/CreatePrimaryUserAPI.java b/src/main/java/io/supertokens/webserver/api/accountlinking/CreatePrimaryUserAPI.java index 89be22302..c912fcf54 100644 --- a/src/main/java/io/supertokens/webserver/api/accountlinking/CreatePrimaryUserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/accountlinking/CreatePrimaryUserAPI.java @@ -63,7 +63,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { String userId = inputRecipeUserId; StorageAndUserIdMapping mappingAndStorage = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, inputRecipeUserId, UserIdType.ANY); storage = mappingAndStorage.storage; if (mappingAndStorage.userIdMapping != null) { diff --git a/src/main/java/io/supertokens/webserver/api/accountlinking/LinkAccountsAPI.java b/src/main/java/io/supertokens/webserver/api/accountlinking/LinkAccountsAPI.java index 5e709fe62..6c4e29e6e 100644 --- a/src/main/java/io/supertokens/webserver/api/accountlinking/LinkAccountsAPI.java +++ b/src/main/java/io/supertokens/webserver/api/accountlinking/LinkAccountsAPI.java @@ -67,7 +67,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I String recipeUserId = inputRecipeUserId; { StorageAndUserIdMapping mappingAndStorage = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, inputRecipeUserId, UserIdType.ANY); if (mappingAndStorage.userIdMapping != null) { recipeUserId = mappingAndStorage.userIdMapping.superTokensUserId; @@ -77,7 +77,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I String primaryUserId = inputPrimaryUserId; { StorageAndUserIdMapping mappingAndStorage = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, inputPrimaryUserId, UserIdType.ANY); if (mappingAndStorage.userIdMapping != null) { primaryUserId = mappingAndStorage.userIdMapping.superTokensUserId; diff --git a/src/main/java/io/supertokens/webserver/api/accountlinking/UnlinkAccountAPI.java b/src/main/java/io/supertokens/webserver/api/accountlinking/UnlinkAccountAPI.java index 8bcab2088..5b1801db2 100644 --- a/src/main/java/io/supertokens/webserver/api/accountlinking/UnlinkAccountAPI.java +++ b/src/main/java/io/supertokens/webserver/api/accountlinking/UnlinkAccountAPI.java @@ -59,7 +59,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { String userId = inputRecipeUserId; StorageAndUserIdMapping mappingAndStorage = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, inputRecipeUserId, UserIdType.ANY); if (mappingAndStorage.userIdMapping != null) { userId = mappingAndStorage.userIdMapping.superTokensUserId; diff --git a/src/main/java/io/supertokens/webserver/api/core/ActiveUsersCountAPI.java b/src/main/java/io/supertokens/webserver/api/core/ActiveUsersCountAPI.java index df20d926f..927e9c68c 100644 --- a/src/main/java/io/supertokens/webserver/api/core/ActiveUsersCountAPI.java +++ b/src/main/java/io/supertokens/webserver/api/core/ActiveUsersCountAPI.java @@ -52,9 +52,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO } try { - int count = ActiveUsers.countUsersActiveSince( - this.getAppIdentifier(req), - this.enforcePublicTenantAndGetPublicTenantStorage(req), sinceTimestamp); + enforcePublicTenantAndGetPublicTenantStorage(req); // to enforce this API is called from public tenant + int count = ActiveUsers.countUsersActiveSince(main, this.getAppIdentifier(req), sinceTimestamp); JsonObject result = new JsonObject(); result.addProperty("status", "OK"); result.addProperty("count", count); diff --git a/src/main/java/io/supertokens/webserver/api/core/ConfigAPI.java b/src/main/java/io/supertokens/webserver/api/core/ConfigAPI.java index 3eca2d329..7a8f7a6f2 100644 --- a/src/main/java/io/supertokens/webserver/api/core/ConfigAPI.java +++ b/src/main/java/io/supertokens/webserver/api/core/ConfigAPI.java @@ -52,14 +52,9 @@ protected boolean checkAPIKey(HttpServletRequest req) { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String pid = InputParser.getQueryParamOrThrowError(req, "pid", false); - try { - TenantIdentifier tenantIdentifier = getTenantIdentifier(req); - getTenantStorage(req); // to check if tenant exists - if (!tenantIdentifier.equals(new TenantIdentifier(null, null, null))) { - throw new ServletException(new BadPermissionException("you can call this only from the base connection uri domain, public app and tenant")); - } - } catch (TenantOrAppNotFoundException e) { - throw new ServletException(e); + TenantIdentifier tenantIdentifier = getTenantIdentifier(req); + if (!tenantIdentifier.equals(new TenantIdentifier(null, null, null))) { + throw new ServletException(new BadPermissionException("you can call this only from the base connection uri domain, public app and tenant")); } if ((ProcessHandle.current().pid() + "").equals(pid)) { diff --git a/src/main/java/io/supertokens/webserver/api/core/DeleteUserAPI.java b/src/main/java/io/supertokens/webserver/api/core/DeleteUserAPI.java index 1348d09bb..c47817c90 100644 --- a/src/main/java/io/supertokens/webserver/api/core/DeleteUserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/core/DeleteUserAPI.java @@ -60,7 +60,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); AuthRecipe.deleteUser(getAppIdentifier(req), storageAndUserIdMapping.storage, userId, removeAllLinkedAccounts, diff --git a/src/main/java/io/supertokens/webserver/api/core/GetUserByIdAPI.java b/src/main/java/io/supertokens/webserver/api/core/GetUserByIdAPI.java index ef1a53d93..b4d33d462 100644 --- a/src/main/java/io/supertokens/webserver/api/core/GetUserByIdAPI.java +++ b/src/main/java/io/supertokens/webserver/api/core/GetUserByIdAPI.java @@ -58,7 +58,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO try { AppIdentifier appIdentifier = this.getAppIdentifier(req); StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); // if a userIdMapping exists, pass the superTokensUserId to the getUserUsingId function if (storageAndUserIdMapping.userIdMapping != null) { userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; diff --git a/src/main/java/io/supertokens/webserver/api/core/HelloAPI.java b/src/main/java/io/supertokens/webserver/api/core/HelloAPI.java index 62f4f5851..b414ad543 100644 --- a/src/main/java/io/supertokens/webserver/api/core/HelloAPI.java +++ b/src/main/java/io/supertokens/webserver/api/core/HelloAPI.java @@ -80,7 +80,10 @@ private void handleRequest(HttpServletRequest req, HttpServletResponse resp) thr // API is app specific try { - RateLimiter rateLimiter = RateLimiter.getInstance(getAppIdentifier(req), super.main, 200); + AppIdentifier appIdentifier = getAppIdentifier(req); + Storage[] storages = StorageLayer.getStoragesForApp(main, appIdentifier); // throws tenantOrAppNotFoundException + + RateLimiter rateLimiter = RateLimiter.getInstance(appIdentifier, super.main, 200); if (!rateLimiter.checkRequest()) { if (Main.isTesting) { super.sendTextResponse(200, "RateLimitedHello", resp); @@ -90,9 +93,6 @@ private void handleRequest(HttpServletRequest req, HttpServletResponse resp) thr return; } - AppIdentifier appIdentifier = getAppIdentifier(req); - Storage[] storages = StorageLayer.getStoragesForApp(main, appIdentifier); - for (Storage storage : storages) { // even if the public tenant does not exist, the following function will return a null // idea here is to test that the storage is working diff --git a/src/main/java/io/supertokens/webserver/api/emailpassword/UserAPI.java b/src/main/java/io/supertokens/webserver/api/emailpassword/UserAPI.java index 1974d22d6..6195213fc 100644 --- a/src/main/java/io/supertokens/webserver/api/emailpassword/UserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/emailpassword/UserAPI.java @@ -84,7 +84,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO if (userId != null) { // Query by userId StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); // if a userIdMapping exists, pass the superTokensUserId to the getUserUsingId function if (storageAndUserIdMapping.userIdMapping != null) { userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; @@ -166,7 +166,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO try { StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); // if a userIdMapping exists, pass the superTokensUserId to the updateUsersEmailOrPassword if (storageAndUserIdMapping.userIdMapping != null) { userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; diff --git a/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java b/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java index 454936944..f3c7664ca 100644 --- a/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java +++ b/src/main/java/io/supertokens/webserver/api/emailverification/UnverifyEmailAPI.java @@ -61,7 +61,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I AppIdentifier appIdentifier = getAppIdentifier(req); Storage storage; try { - StorageAndUserIdMapping storageAndUidMapping = getStorageAndUserIdMappingForAppSpecificApi( + StorageAndUserIdMapping storageAndUidMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); storage = storageAndUidMapping.storage; } catch (UnknownUserIdException e) { diff --git a/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java b/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java index ecc08be38..c4d782452 100644 --- a/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java +++ b/src/main/java/io/supertokens/webserver/api/emailverification/VerifyEmailAPI.java @@ -111,7 +111,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws Servl AppIdentifier appIdentifier = getAppIdentifier(req); Storage storage; try { - StorageAndUserIdMapping storageAndUserIdMapping = getStorageAndUserIdMappingForAppSpecificApi( + StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { diff --git a/src/main/java/io/supertokens/webserver/api/multitenancy/ListTenantsAPI.java b/src/main/java/io/supertokens/webserver/api/multitenancy/ListTenantsAPI.java index b2fe19ef6..98fe89054 100644 --- a/src/main/java/io/supertokens/webserver/api/multitenancy/ListTenantsAPI.java +++ b/src/main/java/io/supertokens/webserver/api/multitenancy/ListTenantsAPI.java @@ -52,10 +52,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO TenantIdentifier tenantIdentifier = getTenantIdentifier(req); Storage storage = getTenantStorage(req); - if (!tenantIdentifier.getTenantId().equals(TenantIdentifier.DEFAULT_TENANT_ID)) { - throw new BadPermissionException("Only the public tenantId is allowed to list all tenants " + - "associated with this app"); - } + enforcePublicTenantAndGetPublicTenantStorage(req); // enforce that this API is called using public tenant TenantConfig[] tenantConfigs = Multitenancy.getAllTenantsForApp(tenantIdentifier.toAppIdentifier(), main); JsonArray tenantsArray = new JsonArray(); diff --git a/src/main/java/io/supertokens/webserver/api/passwordless/UserAPI.java b/src/main/java/io/supertokens/webserver/api/passwordless/UserAPI.java index 98e61b06d..49ff69ff6 100644 --- a/src/main/java/io/supertokens/webserver/api/passwordless/UserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/passwordless/UserAPI.java @@ -82,7 +82,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO try { AppIdentifier appIdentifier = getAppIdentifier(req); StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); if (storageAndUserIdMapping.userIdMapping != null) { userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; } @@ -165,7 +165,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO try { AppIdentifier appIdentifier = getAppIdentifier(req); StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); // if a userIdMapping exists, pass the superTokensUserId to the updateUser if (storageAndUserIdMapping.userIdMapping != null) { userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; diff --git a/src/main/java/io/supertokens/webserver/api/session/RefreshSessionAPI.java b/src/main/java/io/supertokens/webserver/api/session/RefreshSessionAPI.java index 1813769a7..a62df469c 100644 --- a/src/main/java/io/supertokens/webserver/api/session/RefreshSessionAPI.java +++ b/src/main/java/io/supertokens/webserver/api/session/RefreshSessionAPI.java @@ -114,14 +114,14 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I UnsupportedJWTSigningAlgorithmException e) { throw new ServletException(e); } catch (AccessTokenPayloadError | UnauthorisedException e) { - Logging.debug(main, appIdentifier.getAsPublicTenantIdentifier(), + Logging.debug(main, getTenantIdentifier(req), Utils.exceptionStacktraceToString(e)); JsonObject reply = new JsonObject(); reply.addProperty("status", "UNAUTHORISED"); reply.addProperty("message", e.getMessage()); super.sendJsonResponse(200, reply, resp); } catch (TokenTheftDetectedException e) { - Logging.debug(main, appIdentifier.getAsPublicTenantIdentifier(), + Logging.debug(main, getTenantIdentifier(req), Utils.exceptionStacktraceToString(e)); JsonObject reply = new JsonObject(); reply.addProperty("status", "TOKEN_THEFT_DETECTED"); 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 12b1cec58..2de495b62 100644 --- a/src/main/java/io/supertokens/webserver/api/session/SessionRemoveAPI.java +++ b/src/main/java/io/supertokens/webserver/api/session/SessionRemoveAPI.java @@ -21,9 +21,12 @@ import com.google.gson.JsonPrimitive; import io.supertokens.ActiveUsers; import io.supertokens.Main; +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; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.TenantIdentifier; @@ -39,6 +42,10 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; public class SessionRemoveAPI extends WebserverAPI { private static final long serialVersionUID = -2082970815993229316L; @@ -54,7 +61,9 @@ public String getPath() { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific. also operates on all tenants in an app if `revokeAcrossAllTenants` is set to true + // API is app specific when `userId` is passed and `revokeAcrossAllTenants` is set to true + // API is app specific when revoking using `sessionHandles` + // API is tenant specific in all other cases (when `userId` is passed and `revokeAcrossAllTenants` is set to false) JsonObject input = InputParser.parseJsonObjectOrThrowError(req); String userId = InputParser.parseStringOrThrowError(input, "userId", true); @@ -101,28 +110,48 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } if (userId != null) { + Storage storage = null; try { - TenantIdentifier tenantIdentifier = getTenantIdentifier(req); - Storage storage = getTenantStorage(req); - String[] sessionHandlesRevoked; + if (revokeAcrossAllTenants) { + StorageAndUserIdMapping storageAndUserIdMapping = null; + try { + storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( + req, userId, UserIdType.ANY); + storage = storageAndUserIdMapping.storage; + } catch (UnknownUserIdException e) { + storage = getTenantStorage(req); + } + AppIdentifier appIdentifier = getAppIdentifier(req); + sessionHandlesRevoked = Session.revokeAllSessionsForUser( - main, tenantIdentifier.toAppIdentifier(), storage, userId, revokeSessionsForLinkedAccounts); + main, appIdentifier, storage, userId, revokeSessionsForLinkedAccounts); } else { + StorageAndUserIdMapping storageAndUserIdMapping = null; + try { + storageAndUserIdMapping = getStorageAndUserIdMappingForTenantSpecificApi( + req, userId, UserIdType.ANY); + storage = storageAndUserIdMapping.storage; + } catch (UnknownUserIdException e) { + storage = getTenantStorage(req); + } + TenantIdentifier tenantIdentifier = getTenantIdentifier(req); + sessionHandlesRevoked = Session.revokeAllSessionsForUser( main, tenantIdentifier, storage, userId, revokeSessionsForLinkedAccounts); } if (storage.getType() == STORAGE_TYPE.SQL) { try { + AppIdentifier appIdentifier = getAppIdentifier(req); UserIdMapping userIdMapping = io.supertokens.useridmapping.UserIdMapping.getUserIdMapping( - tenantIdentifier.toAppIdentifier(), storage, userId, UserIdType.ANY); + appIdentifier, storage, userId, UserIdType.ANY); if (userIdMapping != null) { - ActiveUsers.updateLastActive(tenantIdentifier.toAppIdentifier(), main, + ActiveUsers.updateLastActive(appIdentifier, main, userIdMapping.superTokensUserId); } else { - ActiveUsers.updateLastActive(tenantIdentifier.toAppIdentifier(), main, userId); + ActiveUsers.updateLastActive(appIdentifier, main, userId); } } catch (StorageQueryException ignored) { } @@ -135,25 +164,45 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I } result.add("sessionHandlesRevoked", sessionHandlesRevokedJSON); super.sendJsonResponse(200, result, resp); - } catch (StorageQueryException | TenantOrAppNotFoundException e) { + } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } } else { try { + enforcePublicTenantAndGetPublicTenantStorage(req); // enforce public tenant AppIdentifier appIdentifier = getAppIdentifier(req); - Storage storage = getTenantStorage(req); - String[] sessionHandlesRevoked = Session.revokeSessionUsingSessionHandles(main, - appIdentifier, storage, sessionHandles); + Map> sessionHandlesByTenantId = new HashMap<>(); + + for (String sessionHandle : sessionHandles) { + String tenantId = Session.getTenantIdFromSessionHandle(sessionHandle); + if (!sessionHandlesByTenantId.containsKey(tenantId)) { + sessionHandlesByTenantId.put(tenantId, new ArrayList<>()); + } + sessionHandlesByTenantId.get(tenantId).add(sessionHandle); + } + List allSessionHandlesRevoked = new ArrayList<>(); + for (Map.Entry> entry : sessionHandlesByTenantId.entrySet()) { + String tenantId = entry.getKey(); + List sessionHandlesForTenant = entry.getValue(); + Storage storage = + StorageLayer.getStorage(new TenantIdentifier( + appIdentifier.getConnectionUriDomain(), appIdentifier.getAppId(), tenantId), main); + + String[] sessionHandlesRevoked = Session.revokeSessionUsingSessionHandles(main, + appIdentifier, storage, sessionHandlesForTenant.toArray(new String[0])); + allSessionHandlesRevoked.addAll(List.of(sessionHandlesRevoked)); + } + JsonObject result = new JsonObject(); result.addProperty("status", "OK"); JsonArray sessionHandlesRevokedJSON = new JsonArray(); - for (String sessionHandle : sessionHandlesRevoked) { + for (String sessionHandle : allSessionHandlesRevoked) { sessionHandlesRevokedJSON.add(new JsonPrimitive(sessionHandle)); } result.add("sessionHandlesRevoked", sessionHandlesRevokedJSON); super.sendJsonResponse(200, result, resp); - } catch (StorageQueryException | TenantOrAppNotFoundException e) { + } catch (StorageQueryException | TenantOrAppNotFoundException | BadPermissionException e) { throw new ServletException(e); } } diff --git a/src/main/java/io/supertokens/webserver/api/thirdparty/UserAPI.java b/src/main/java/io/supertokens/webserver/api/thirdparty/UserAPI.java index efd0f81c6..f8ef39376 100644 --- a/src/main/java/io/supertokens/webserver/api/thirdparty/UserAPI.java +++ b/src/main/java/io/supertokens/webserver/api/thirdparty/UserAPI.java @@ -81,7 +81,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO AppIdentifier appIdentifier = getAppIdentifier(req); try { StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, UserIdType.ANY); // if a userIdMapping exists, pass the superTokensUserId to the getUserUsingId function if (storageAndUserIdMapping.userIdMapping != null) { userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; diff --git a/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java b/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java index 31c0c8ee9..7aeaf35d5 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/CreateOrUpdateTotpDeviceAPI.java @@ -74,12 +74,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I // While sending the usage stats we do a join, so totp tables also must use internal user id. // Try to find the appIdentifier with right storage based on the userId - StorageAndUserIdMapping storageAndUserIdMapping = getStorageAndUserIdMappingForAppSpecificApi( + StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); - - if (storageAndUserIdMapping.userIdMapping != null) { - userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; - } storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { // if the user is not found, just use the public tenant storage @@ -130,13 +126,10 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO // Try to find the appIdentifier with right storage based on the userId StorageAndUserIdMapping storageAndUserIdMapping = - getStorageAndUserIdMappingForAppSpecificApi( + enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); - - if (storageAndUserIdMapping.userIdMapping != null) { - userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; - } storage = storageAndUserIdMapping.storage; + } catch (UnknownUserIdException e) { // if the user is not found, just use the public storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); diff --git a/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java b/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java index 400674c70..4b5e9905a 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/GetTotpDevicesAPI.java @@ -54,12 +54,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO // While sending the usage stats we do a join, so totp tables also must use internal user id. // Try to find the appIdentifier with right storage based on the userId - StorageAndUserIdMapping storageAndUserIdMapping = getStorageAndUserIdMappingForAppSpecificApi( + StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); - - if (storageAndUserIdMapping.userIdMapping != null) { - userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; - } storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { // if the user is not found, just use the storage of the tenant of interest diff --git a/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java b/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java index fd56fdcd4..d8dde49c3 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/RemoveTotpDeviceAPI.java @@ -60,12 +60,9 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I // While sending the usage stats we do a join, so totp tables also must use internal user id. // Try to find the appIdentifier with right storage based on the userId - StorageAndUserIdMapping storageAndUserIdMapping = getStorageAndUserIdMappingForAppSpecificApi( + StorageAndUserIdMapping storageAndUserIdMapping = enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); - if (storageAndUserIdMapping.userIdMapping != null) { - userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; - } storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { // if the user is not found, just use the storage of the tenant of interest diff --git a/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpAPI.java b/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpAPI.java index 46adb2cc8..b81975402 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpAPI.java @@ -65,10 +65,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I StorageAndUserIdMapping storageAndUserIdMapping = getStorageAndUserIdMappingForTenantSpecificApi( req, userId, UserIdType.ANY); - - if (storageAndUserIdMapping.userIdMapping != null) { - userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; - } storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { // if the user is not found, just use the storage of the tenant of interest diff --git a/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpDeviceAPI.java b/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpDeviceAPI.java index 3728119cf..54222050d 100644 --- a/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpDeviceAPI.java +++ b/src/main/java/io/supertokens/webserver/api/totp/VerifyTotpDeviceAPI.java @@ -67,10 +67,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I StorageAndUserIdMapping storageAndUserIdMapping = getStorageAndUserIdMappingForTenantSpecificApi( req, userId, UserIdType.ANY); - - if (storageAndUserIdMapping.userIdMapping != null) { - userId = storageAndUserIdMapping.userIdMapping.superTokensUserId; - } storage = storageAndUserIdMapping.storage; } catch (UnknownUserIdException e) { // if the user is not found, just use the storage of the tenant of interest diff --git a/src/main/java/io/supertokens/webserver/api/useridmapping/RemoveUserIdMappingAPI.java b/src/main/java/io/supertokens/webserver/api/useridmapping/RemoveUserIdMappingAPI.java index 195f314c9..ba2892e6b 100644 --- a/src/main/java/io/supertokens/webserver/api/useridmapping/RemoveUserIdMappingAPI.java +++ b/src/main/java/io/supertokens/webserver/api/useridmapping/RemoveUserIdMappingAPI.java @@ -86,7 +86,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, userIdType); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, userIdType); boolean didMappingExist = UserIdMapping.deleteUserIdMapping( getAppIdentifier(req), diff --git a/src/main/java/io/supertokens/webserver/api/useridmapping/UpdateExternalUserIdInfoAPI.java b/src/main/java/io/supertokens/webserver/api/useridmapping/UpdateExternalUserIdInfoAPI.java index cde30fc02..8acf3ff60 100644 --- a/src/main/java/io/supertokens/webserver/api/useridmapping/UpdateExternalUserIdInfoAPI.java +++ b/src/main/java/io/supertokens/webserver/api/useridmapping/UpdateExternalUserIdInfoAPI.java @@ -95,7 +95,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO try { StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, userIdType); + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, userIdType); if (UserIdMapping.updateOrDeleteExternalUserIdInfo( getAppIdentifier(req), diff --git a/src/main/java/io/supertokens/webserver/api/useridmapping/UserIdMappingAPI.java b/src/main/java/io/supertokens/webserver/api/useridmapping/UserIdMappingAPI.java index 07ca76829..0bd993e07 100644 --- a/src/main/java/io/supertokens/webserver/api/useridmapping/UserIdMappingAPI.java +++ b/src/main/java/io/supertokens/webserver/api/useridmapping/UserIdMappingAPI.java @@ -162,10 +162,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO // Request from (app1, tenant1) will return user1 and request from (app1, tenant2) will return user2 // Request from (app1, tenant3) may result in either user1 or user2 - StorageAndUserIdMapping appIdentifierWithStorageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi(req, userId, userIdType); + StorageAndUserIdMapping storageAndUserIdMapping = + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi(req, userId, userIdType); - if (appIdentifierWithStorageAndUserIdMapping.userIdMapping == null) { + if (storageAndUserIdMapping.userIdMapping == null) { JsonObject response = new JsonObject(); response.addProperty("status", "UNKNOWN_MAPPING_ERROR"); super.sendJsonResponse(200, response, resp); @@ -175,12 +175,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject response = new JsonObject(); response.addProperty("status", "OK"); response.addProperty("superTokensUserId", - appIdentifierWithStorageAndUserIdMapping.userIdMapping.superTokensUserId); + storageAndUserIdMapping.userIdMapping.superTokensUserId); response.addProperty("externalUserId", - appIdentifierWithStorageAndUserIdMapping.userIdMapping.externalUserId); - if (appIdentifierWithStorageAndUserIdMapping.userIdMapping.externalUserIdInfo != null) { + storageAndUserIdMapping.userIdMapping.externalUserId); + if (storageAndUserIdMapping.userIdMapping.externalUserIdInfo != null) { response.addProperty("externalUserIdInfo", - appIdentifierWithStorageAndUserIdMapping.userIdMapping.externalUserIdInfo); + storageAndUserIdMapping.userIdMapping.externalUserIdInfo); } super.sendJsonResponse(200, response, resp); diff --git a/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java b/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java index 47a6e0ad0..c8901064e 100644 --- a/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java +++ b/src/main/java/io/supertokens/webserver/api/usermetadata/RemoveUserMetadataAPI.java @@ -58,7 +58,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { try { StorageAndUserIdMapping storageAndUserIdMapping = - this.getStorageAndUserIdMappingForAppSpecificApi( + this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); UserMetadata.deleteUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId); } catch (UnknownUserIdException e) { diff --git a/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java b/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java index 4444d0551..c11d47faa 100644 --- a/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java +++ b/src/main/java/io/supertokens/webserver/api/usermetadata/UserMetadataAPI.java @@ -57,7 +57,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO try { JsonObject metadata; try { - StorageAndUserIdMapping storageAndUserIdMapping = this.getStorageAndUserIdMappingForAppSpecificApi( + StorageAndUserIdMapping storageAndUserIdMapping = this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); metadata = UserMetadata.getUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId); } catch (UnknownUserIdException e) { @@ -86,7 +86,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO JsonObject metadata; try { - StorageAndUserIdMapping storageAndUserIdMapping = this.getStorageAndUserIdMappingForAppSpecificApi( + StorageAndUserIdMapping storageAndUserIdMapping = this.enforcePublicTenantAndGetStorageAndUserIdMappingForAppSpecificApi( req, userId, UserIdType.ANY); metadata = UserMetadata.updateUserMetadata(appIdentifier, storageAndUserIdMapping.storage, userId, update); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java index c1c6cd0d1..87f3d3f08 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/GetUsersForRoleAPI.java @@ -51,7 +51,7 @@ public String getPath() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific, but uses public tenant storage + // API is tenant specific String role = InputParser.getQueryParamOrThrowError(req, "role", false); // normalize roles diff --git a/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java index acc130085..66f59c7a2 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/RemoveRoleAPI.java @@ -61,9 +61,9 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I try { AppIdentifier appIdentifier = getAppIdentifier(req); - Storage storage = enforcePublicTenantAndGetPublicTenantStorage(req); + enforcePublicTenantAndGetPublicTenantStorage(req); // enforce this API is called from public tenant - boolean didRoleExist = UserRoles.deleteRole(appIdentifier, storage, role); + boolean didRoleExist = UserRoles.deleteRole(main, appIdentifier, role); JsonObject response = new JsonObject(); response.addProperty("status", "OK"); diff --git a/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java b/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java index ff94b4bbd..7b76eb31b 100644 --- a/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java +++ b/src/main/java/io/supertokens/webserver/api/userroles/RemoveUserRoleAPI.java @@ -50,7 +50,7 @@ public String getPath() { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - // API is tenant specific, but uses public tenant storage + // API is tenant specific JsonObject input = InputParser.parseJsonObjectOrThrowError(req); String userId = InputParser.parseStringOrThrowError(input, "userId", false); String role = InputParser.parseStringOrThrowError(input, "role", false); diff --git a/src/test/java/io/supertokens/test/FeatureFlagTest.java b/src/test/java/io/supertokens/test/FeatureFlagTest.java index d6d324a13..c842475d9 100644 --- a/src/test/java/io/supertokens/test/FeatureFlagTest.java +++ b/src/test/java/io/supertokens/test/FeatureFlagTest.java @@ -357,17 +357,17 @@ public void testThatMultitenantStatsAreAccurate() throws Exception { ) ); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getStorage(tenantIdentifier, process.getProcess())); if (i % 3 == 0) { // Create a user EmailPassword.signUp( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "user@example.com", + tenantIdentifier, storage, process.getProcess(), "user@example.com", "password"); } else if (i % 3 == 1) { // Create a session Session.createNewSession( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "userid", new JsonObject(), + tenantIdentifier, storage, process.getProcess(), "userid", new JsonObject(), new JsonObject()); } else { // Create an enterprise provider @@ -476,17 +476,17 @@ public void testThatMultitenantStatsAreAccurateForAnApp() throws Exception { ) ); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getStorage(tenantIdentifier, process.getProcess())); if (i % 3 == 0) { // Create a user EmailPassword.signUp( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "user@example.com", + tenantIdentifier, storage, process.getProcess(), "user@example.com", "password"); } else if (i % 3 == 1) { // Create a session Session.createNewSession( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "userid", new JsonObject(), + tenantIdentifier, storage, process.getProcess(), "userid", new JsonObject(), new JsonObject()); } else { // Create an enterprise provider @@ -605,17 +605,17 @@ public void testThatMultitenantStatsAreAccurateForACud() throws Exception { ) ); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getStorage(tenantIdentifier, process.getProcess())); if (i % 3 == 0) { // Create a user EmailPassword.signUp( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "user@example.com", + tenantIdentifier, storage, process.getProcess(), "user@example.com", "password"); } else if (i % 3 == 1) { // Create a session Session.createNewSession( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), "userid", new JsonObject(), + tenantIdentifier, storage, process.getProcess(), "userid", new JsonObject(), new JsonObject()); } else { // Create an enterprise provider diff --git a/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java b/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java index 72b15214e..5be161397 100644 --- a/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/CreatePrimaryUserTest.java @@ -425,9 +425,9 @@ public void makePrimaryUserFailsCauseAnotherAccountWithSameEmailAlreadyAPrimaryU new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), new JsonObject())); - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(process.main)); + Storage storage = (StorageLayer.getStorage(process.main)); AuthRecipeUserInfo emailPasswordUser = EmailPassword.signUp(new TenantIdentifier(null, null, "t1"), - tenantIdentifierWithStorage, process.getProcess(), + storage, process.getProcess(), "test@example.com", "pass1234"); @@ -438,7 +438,7 @@ public void makePrimaryUserFailsCauseAnotherAccountWithSameEmailAlreadyAPrimaryU "test@example.com"); Multitenancy.addUserIdToTenant(process.main, new TenantIdentifier(null, null, "t1"), - tenantIdentifierWithStorage, + storage, signInUpResponse.user.getSupertokensUserId()); try { @@ -473,9 +473,9 @@ public void makePrimarySucceedsEvenIfAnotherAccountWithSameEmailButInADifferentT new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), new JsonObject())); - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(process.main)); + Storage storage = (StorageLayer.getStorage(process.main)); AuthRecipeUserInfo emailPasswordUser = EmailPassword.signUp(new TenantIdentifier(null, null, "t1"), - tenantIdentifierWithStorage, process.getProcess(), + storage, process.getProcess(), "test@example.com", "pass1234"); diff --git a/src/test/java/io/supertokens/test/accountlinking/GetUserByAccountInfoTest.java b/src/test/java/io/supertokens/test/accountlinking/GetUserByAccountInfoTest.java index 59afa63d8..e920629b2 100644 --- a/src/test/java/io/supertokens/test/accountlinking/GetUserByAccountInfoTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/GetUserByAccountInfoTest.java @@ -114,10 +114,10 @@ public void testListUsersByAccountInfoForUnlinkedAccounts() throws Exception { AuthRecipeUserInfo user3 = createPasswordlessUserWithEmail(process.getProcess(), "test3@example.com"); AuthRecipeUserInfo user4 = createPasswordlessUserWithPhone(process.getProcess(), "+919876543210"); - Storage tenantIdentifierWithStorage = (StorageLayer.getBaseStorage(process.getProcess())); + Storage storage = (StorageLayer.getBaseStorage(process.getProcess())); AuthRecipeUserInfo userToTest = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, null, null)[0]; assertNotNull(userToTest.getSupertokensUserId()); assertFalse(userToTest.isPrimaryUser); @@ -129,29 +129,29 @@ public void testListUsersByAccountInfoForUnlinkedAccounts() throws Exception { assert(userToTest.loginMethods[0].timeJoined > 0); // test for result - assertEquals(user1, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage + assertEquals(user1, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage , false, "test1@example.com", null, null, null)[0]); - assertEquals(user2, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage + assertEquals(user2, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage , false, null, null, "google", "userid1")[0]); - assertEquals(user2, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage + assertEquals(user2, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage , false, "test2@example.com", null, "google", "userid1")[0]); - assertEquals(user3, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage + assertEquals(user3, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage , false, "test3@example.com", null, null, null)[0]); - assertEquals(user4, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage + assertEquals(user4, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage , false, null, "+919876543210", null, null)[0]); // test for no result - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, "test1@example.com", "+919876543210", null, null).length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, "test2@example.com", "+919876543210", null, null).length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, "test3@example.com", "+919876543210", null, null).length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, null, "+919876543210", "google", "userid1").length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, "test1@gmail.com", null, "google", "userid1").length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, "test3@gmail.com", null, "google", "userid1").length); process.kill(); @@ -177,31 +177,31 @@ public void testListUsersByAccountInfoForUnlinkedAccountsWithUnionOption() throw AuthRecipeUserInfo user3 = createPasswordlessUserWithEmail(process.getProcess(), "test3@example.com"); AuthRecipeUserInfo user4 = createPasswordlessUserWithPhone(process.getProcess(), "+919876543210"); - Storage tenantIdentifierWithStorage = (StorageLayer.getBaseStorage(process.getProcess())); + Storage storage = (StorageLayer.getBaseStorage(process.getProcess())); { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, true, "test1@example.com", "+919876543210", null, null); + storage, true, "test1@example.com", "+919876543210", null, null); assertEquals(2, users.length); assertTrue(Arrays.asList(users).contains(user1)); assertTrue(Arrays.asList(users).contains(user4)); } { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, true, "test1@example.com", null, "google", "userid1"); + storage, true, "test1@example.com", null, "google", "userid1"); assertEquals(2, users.length); assertTrue(Arrays.asList(users).contains(user1)); assertTrue(Arrays.asList(users).contains(user2)); } { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, true, null, "+919876543210", "google", "userid1"); + storage, true, null, "+919876543210", "google", "userid1"); assertEquals(2, users.length); assertTrue(Arrays.asList(users).contains(user4)); assertTrue(Arrays.asList(users).contains(user2)); } { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, true, "test1@example.com", "+919876543210", "google", "userid1"); + storage, true, "test1@example.com", "+919876543210", "google", "userid1"); assertEquals(3, users.length); assertTrue(Arrays.asList(users).contains(user1)); assertTrue(Arrays.asList(users).contains(user2)); @@ -226,14 +226,14 @@ public void testUnknownAccountInfo() throws Exception { return; } - Storage tenantIdentifierWithStorage = (StorageLayer.getBaseStorage(process.getProcess())); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getBaseStorage(process.getProcess())); + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, "test1@example.com", null, null, null).length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, null, null, "google", "userid1").length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, "test3@example.com", null, null, null).length); - assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, tenantIdentifierWithStorage, + assertEquals(0, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, storage, false, null, "+919876543210", null, null).length); process.kill(); @@ -261,25 +261,25 @@ public void testListUserByAccountInfoWhenAccountsAreLinked1() throws Exception { AuthRecipeUserInfo primaryUser = AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId()).user; AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), primaryUser.getSupertokensUserId()); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getBaseStorage(process.getProcess())); primaryUser = AuthRecipe.getUserById(process.getProcess(), user1.getSupertokensUserId()); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test2@example.com", null, null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, null, null, "google", "userid1")[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, "google", "userid1")[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test2@example.com", null, "google", "userid1")[0]); process.kill(); @@ -307,16 +307,16 @@ public void testListUserByAccountInfoWhenAccountsAreLinked2() throws Exception { AuthRecipeUserInfo primaryUser = AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId()).user; AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), primaryUser.getSupertokensUserId()); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getBaseStorage(process.getProcess())); primaryUser = AuthRecipe.getUserById(process.getProcess(), user1.getSupertokensUserId()); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test2@example.com", null, null, null)[0]); process.kill(); @@ -344,16 +344,16 @@ public void testListUserByAccountInfoWhenAccountsAreLinked3() throws Exception { AuthRecipeUserInfo primaryUser = AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId()).user; AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), primaryUser.getSupertokensUserId()); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getBaseStorage(process.getProcess())); primaryUser = AuthRecipe.getUserById(process.getProcess(), user1.getSupertokensUserId()); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test2@example.com", null, null, null)[0]); process.kill(); @@ -381,19 +381,19 @@ public void testListUserByAccountInfoWhenAccountsAreLinked4() throws Exception { AuthRecipeUserInfo primaryUser = AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId()).user; AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), primaryUser.getSupertokensUserId()); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getBaseStorage(process.getProcess())); primaryUser = AuthRecipe.getUserById(process.getProcess(), user1.getSupertokensUserId()); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, null, "+919876543210", null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", "+919876543210", null, null)[0]); process.kill(); @@ -421,25 +421,25 @@ public void testListUserByAccountInfoWhenAccountsAreLinked5() throws Exception { AuthRecipeUserInfo primaryUser = AuthRecipe.createPrimaryUser(process.getProcess(), user1.getSupertokensUserId()).user; AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), primaryUser.getSupertokensUserId()); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getBaseStorage(process.getProcess())); primaryUser = AuthRecipe.getUserById(process.getProcess(), user1.getSupertokensUserId()); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test2@example.com", null, null, null)[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, null, null, "google", "userid1")[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test1@example.com", null, "google", "userid1")[0]); assertEquals(primaryUser, AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test2@example.com", null, "google", "userid1")[0]); process.kill(); @@ -473,23 +473,23 @@ public void testForEmptyResults() throws Exception { AuthRecipe.linkAccounts(process.getProcess(), user2.getSupertokensUserId(), primaryUser.getSupertokensUserId()); AuthRecipe.linkAccounts(process.getProcess(), user3.getSupertokensUserId(), primaryUser.getSupertokensUserId()); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getBaseStorage(process.getProcess())); { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, "test5@example.com", null, null, null); assertEquals(0, users.length); } { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, null, null, "google", "userid5"); assertEquals(0, users.length); } { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, + storage, false, null, "+9876", null, null); assertEquals(0, users.length); } @@ -531,12 +531,12 @@ public void testGetUserByAccountInfoOrdersUserBasedOnTimeJoined() throws Excepti AuthRecipe.createPrimaryUser(process.getProcess(), user4.getSupertokensUserId()); - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getBaseStorage(process.getProcess())); { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, true, "test1@example.com", null, + storage, true, "test1@example.com", null, null, null); assertEquals(3, users.length); @@ -546,7 +546,7 @@ public void testGetUserByAccountInfoOrdersUserBasedOnTimeJoined() throws Excepti } { AuthRecipeUserInfo[] users = AuthRecipe.getUsersByAccountInfo(TenantIdentifier.BASE_TENANT, - tenantIdentifierWithStorage, false, "test1@example.com", null, + storage, false, "test1@example.com", null, null, null); assertEquals(3, users.length); diff --git a/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java b/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java index 10066d51f..44bca0c5b 100644 --- a/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/LinkAccountsTest.java @@ -468,10 +468,10 @@ public void linkAccountFailureCauseAccountInfoAssociatedWithAPrimaryUserEvenIfIn new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), new JsonObject())); - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(process.main)); + Storage storage = (StorageLayer.getStorage(process.main)); AuthRecipeUserInfo user = - EmailPassword.signUp(new TenantIdentifier(null, null, "t1"), tenantIdentifierWithStorage, + EmailPassword.signUp(new TenantIdentifier(null, null, "t1"), storage, process.getProcess(), "test@example.com", "password"); assert (!user.isPrimaryUser); @@ -480,7 +480,7 @@ public void linkAccountFailureCauseAccountInfoAssociatedWithAPrimaryUserEvenIfIn Thread.sleep(50); ThirdParty.SignInUpResponse signInUpResponse = ThirdParty.signInUp( - new TenantIdentifier(null, null, "t1"), tenantIdentifierWithStorage, + new TenantIdentifier(null, null, "t1"), storage, process.getProcess(), "google", "user-google", "test@example.com"); @@ -523,10 +523,10 @@ public void linkAccountSuccessAcrossTenants() throws Exception { new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), new JsonObject())); - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(process.main)); + Storage storage = (StorageLayer.getStorage(process.main)); AuthRecipeUserInfo user = EmailPassword.signUp(new TenantIdentifier(null, null, "t1"), - tenantIdentifierWithStorage, process.getProcess(), + storage, process.getProcess(), "test@example.com", "password"); assert (!user.isPrimaryUser); AuthRecipe.createPrimaryUser(process.main, user.getSupertokensUserId()); diff --git a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java index 638068b7f..865008ea3 100644 --- a/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java +++ b/src/test/java/io/supertokens/test/accountlinking/MultitenantTest.java @@ -185,27 +185,27 @@ public void testUserAreNotAutomaticallySharedBetweenTenantsOfLinkedAccountsForPl t1 = new TenantIdentifier(null, "a1", null); t2 = new TenantIdentifier(null, "a1", "t1"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password"); - Passwordless.CreateCodeResponse user2Code = Passwordless.createCode(t1, t1WithStorage, process.getProcess(), + Passwordless.CreateCodeResponse user2Code = Passwordless.createCode(t1, t1Storage, process.getProcess(), "test@example.com", null, null, null); - AuthRecipeUserInfo user2 = Passwordless.consumeCode(t1, t1WithStorage, process.getProcess(), user2Code.deviceId, + AuthRecipeUserInfo user2 = Passwordless.consumeCode(t1, t1Storage, process.getProcess(), user2Code.deviceId, user2Code.deviceIdHash, user2Code.userInputCode, null).user; - AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, + AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId()); - AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, user2.getSupertokensUserId(), + AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1Storage, user2.getSupertokensUserId(), user1.getSupertokensUserId()); - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, user1.getSupertokensUserId()); + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, user1.getSupertokensUserId()); { // user2 should not be shared in tenant2 - Passwordless.CreateCodeResponse user3Code = Passwordless.createCode(t2, t2WithStorage, process.getProcess(), + Passwordless.CreateCodeResponse user3Code = Passwordless.createCode(t2, t2Storage, process.getProcess(), "test@example.com", null, null, null); - Passwordless.ConsumeCodeResponse res = Passwordless.consumeCode(t2, t2WithStorage, process.getProcess(), + Passwordless.ConsumeCodeResponse res = Passwordless.consumeCode(t2, t2Storage, process.getProcess(), user3Code.deviceId, user3Code.deviceIdHash, user3Code.userInputCode, null); assertTrue(res.createdNewUser); } @@ -233,23 +233,23 @@ public void testUserAreNotAutomaticallySharedBetweenTenantsOfLinkedAccountsForTP t1 = new TenantIdentifier(null, "a1", null); t2 = new TenantIdentifier(null, "a1", "t1"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password"); - AuthRecipeUserInfo user2 = ThirdParty.signInUp(t1, t1WithStorage, process.getProcess(), "google", "googleid1", + AuthRecipeUserInfo user2 = ThirdParty.signInUp(t1, t1Storage, process.getProcess(), "google", "googleid1", "test@example.com").user; - AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, + AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId()); - AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, user2.getSupertokensUserId(), + AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1Storage, user2.getSupertokensUserId(), user1.getSupertokensUserId()); - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, user1.getSupertokensUserId()); + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, user1.getSupertokensUserId()); { // user2 should not be shared in tenant2 - ThirdParty.SignInUpResponse res = ThirdParty.signInUp(t2, t2WithStorage, process.getProcess(), "google", + ThirdParty.SignInUpResponse res = ThirdParty.signInUp(t2, t2Storage, process.getProcess(), "google", "googleid1", "test@example.com"); assertTrue(res.createdNewUser); } @@ -277,28 +277,28 @@ public void testTenantDeletionWithAccountLinking() throws Exception { t1 = new TenantIdentifier(null, "a1", null); t2 = new TenantIdentifier(null, "a1", "t1"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t2, t2WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t2, t2Storage, process.getProcess(), "test@example.com", "password"); - AuthRecipeUserInfo user2 = ThirdParty.signInUp(t2, t2WithStorage, process.getProcess(), "google", "googleid1", + AuthRecipeUserInfo user2 = ThirdParty.signInUp(t2, t2Storage, process.getProcess(), "google", "googleid1", "test@example.com").user; - AuthRecipe.createPrimaryUser(process.getProcess(), t2.toAppIdentifier(), t2WithStorage, + AuthRecipe.createPrimaryUser(process.getProcess(), t2.toAppIdentifier(), t2Storage, user1.getSupertokensUserId()); - AuthRecipe.linkAccounts(process.getProcess(), t2.toAppIdentifier(), t2WithStorage, user2.getSupertokensUserId(), + AuthRecipe.linkAccounts(process.getProcess(), t2.toAppIdentifier(), t2Storage, user2.getSupertokensUserId(), user1.getSupertokensUserId()); Multitenancy.deleteTenant(t2, process.getProcess()); - AuthRecipeUserInfo getUser1 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1WithStorage, + AuthRecipeUserInfo getUser1 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId()); for (LoginMethod lm : getUser1.loginMethods) { assertEquals(0, lm.tenantIds.size()); } - AuthRecipeUserInfo getUser2 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1WithStorage, + AuthRecipeUserInfo getUser2 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1Storage, user2.getSupertokensUserId()); for (LoginMethod lm : getUser2.loginMethods) { assertEquals(0, lm.tenantIds.size()); @@ -327,44 +327,44 @@ public void testTenantDeletionWithAccountLinkingWithUserRoles() throws Exception t1 = new TenantIdentifier(null, "a1", null); t2 = new TenantIdentifier(null, "a1", "t1"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t2, t2WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t2, t2Storage, process.getProcess(), "test@example.com", "password"); - AuthRecipeUserInfo user2 = ThirdParty.signInUp(t2, t2WithStorage, process.getProcess(), "google", "googleid1", + AuthRecipeUserInfo user2 = ThirdParty.signInUp(t2, t2Storage, process.getProcess(), "google", "googleid1", "test@example.com").user; - AuthRecipe.createPrimaryUser(process.getProcess(), t2.toAppIdentifier(), t2WithStorage, + AuthRecipe.createPrimaryUser(process.getProcess(), t2.toAppIdentifier(), t2Storage, user1.getSupertokensUserId()); - AuthRecipe.linkAccounts(process.getProcess(), t2.toAppIdentifier(), t2WithStorage, user2.getSupertokensUserId(), + AuthRecipe.linkAccounts(process.getProcess(), t2.toAppIdentifier(), t2Storage, user2.getSupertokensUserId(), user1.getSupertokensUserId()); - UserRoles.createNewRoleOrModifyItsPermissions(t2.toAppIdentifier(), t2WithStorage, "admin", new String[]{"p1"}); - UserRoles.addRoleToUser(process.getProcess(), t2, t2WithStorage, user1.getSupertokensUserId(), "admin"); + UserRoles.createNewRoleOrModifyItsPermissions(t2.toAppIdentifier(), t2Storage, "admin", new String[]{"p1"}); + UserRoles.addRoleToUser(process.getProcess(), t2, t2Storage, user1.getSupertokensUserId(), "admin"); Multitenancy.deleteTenant(t2, process.getProcess()); createTenants(process.getProcess()); // create the tenant again - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, user1.getSupertokensUserId()); // add + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, user1.getSupertokensUserId()); // add // the user to the tenant again - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, user2.getSupertokensUserId()); // add + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, user2.getSupertokensUserId()); // add // the user to the tenant again - AuthRecipeUserInfo getUser1 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1WithStorage, + AuthRecipeUserInfo getUser1 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId()); for (LoginMethod lm : getUser1.loginMethods) { assertEquals(1, lm.tenantIds.size()); } - AuthRecipeUserInfo getUser2 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1WithStorage, + AuthRecipeUserInfo getUser2 = AuthRecipe.getUserById(t1.toAppIdentifier(), t1Storage, user2.getSupertokensUserId()); for (LoginMethod lm : getUser2.loginMethods) { assertEquals(1, lm.tenantIds.size()); } - String[] roles = UserRoles.getRolesForUser(t2, t2WithStorage, user1.getSupertokensUserId()); + String[] roles = UserRoles.getRolesForUser(t2, t2Storage, user1.getSupertokensUserId()); assertEquals(0, roles.length); // must be deleted with tenant process.kill(); @@ -714,8 +714,8 @@ public void testVariousCases() throws Exception { new TestCaseStep() { @Override public void execute(Main main) throws Exception { - Storage t1WithStorage = (StorageLayer.getStorage(t1, main)); - AuthRecipeUserInfo user = AuthRecipe.getUserById(t1.toAppIdentifier(), t1WithStorage, + Storage t1Storage = (StorageLayer.getStorage(t1, main)); + AuthRecipeUserInfo user = AuthRecipe.getUserById(t1.toAppIdentifier(), t1Storage, TestCase.users.get(0).getSupertokensUserId()); assertEquals(2, user.loginMethods.length); assertTrue(user.loginMethods[0].tenantIds.contains(t2.getTenantId())); @@ -756,16 +756,16 @@ public void execute(Main main) throws Exception { new TestCaseStep() { @Override public void execute(Main main) throws Exception { - Storage t1WithStorage = (StorageLayer.getStorage(t1, main)); - AuthRecipe.deleteUser(t1.toAppIdentifier(), t1WithStorage, + Storage t1Storage = (StorageLayer.getStorage(t1, main)); + AuthRecipe.deleteUser(t1.toAppIdentifier(), t1Storage, TestCase.users.get(1).getSupertokensUserId()); } }, new TestCaseStep() { @Override public void execute(Main main) throws Exception { - Storage t1WithStorage = (StorageLayer.getStorage(t1, main)); - AuthRecipeUserInfo user = AuthRecipe.getUserById(t1.toAppIdentifier(), t1WithStorage, + Storage t1Storage = (StorageLayer.getStorage(t1, main)); + AuthRecipeUserInfo user = AuthRecipe.getUserById(t1.toAppIdentifier(), t1Storage, TestCase.users.get(0).getSupertokensUserId()); assertNull(user); } @@ -928,8 +928,8 @@ public CreateEmailPasswordUser(TenantIdentifier tenantIdentifier, String email) @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - AuthRecipeUserInfo user = EmailPassword.signUp(tenantIdentifier, tenantIdentifierWithStorage, main, email, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + AuthRecipeUserInfo user = EmailPassword.signUp(tenantIdentifier, storage, main, email, "password"); TestCase.addUser(user); } @@ -946,11 +946,11 @@ public CreatePlessUserWithEmail(TenantIdentifier tenantIdentifier, String email) @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); Passwordless.CreateCodeResponse code = Passwordless.createCode(tenantIdentifier, - tenantIdentifierWithStorage, main, + storage, main, email, null, null, null); - AuthRecipeUserInfo user = Passwordless.consumeCode(tenantIdentifier, tenantIdentifierWithStorage, main, + AuthRecipeUserInfo user = Passwordless.consumeCode(tenantIdentifier, storage, main, code.deviceId, code.deviceIdHash, code.userInputCode, null).user; TestCase.addUser(user); @@ -968,11 +968,11 @@ public CreatePlessUserWithPhone(TenantIdentifier tenantIdentifier, String phoneN @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); Passwordless.CreateCodeResponse code = Passwordless.createCode(tenantIdentifier, - tenantIdentifierWithStorage, main, + storage, main, null, phoneNumber, null, null); - AuthRecipeUserInfo user = Passwordless.consumeCode(tenantIdentifier, tenantIdentifierWithStorage, main, + AuthRecipeUserInfo user = Passwordless.consumeCode(tenantIdentifier, storage, main, code.deviceId, code.deviceIdHash, code.userInputCode, null).user; TestCase.addUser(user); @@ -994,8 +994,8 @@ public CreateThirdPartyUser(TenantIdentifier tenantIdentifier, String thirdParty @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - AuthRecipeUserInfo user = ThirdParty.signInUp(tenantIdentifier, tenantIdentifierWithStorage, main, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + AuthRecipeUserInfo user = ThirdParty.signInUp(tenantIdentifier, storage, main, thirdPartyId, thirdPartyUserId, email).user; TestCase.addUser(user); @@ -1013,8 +1013,8 @@ public MakePrimaryUser(TenantIdentifier tenantIdentifier, int userIndex) { @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - AuthRecipe.createPrimaryUser(main, tenantIdentifier.toAppIdentifier(), tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + AuthRecipe.createPrimaryUser(main, tenantIdentifier.toAppIdentifier(), storage, TestCase.users.get(userIndex).getSupertokensUserId()); } } @@ -1032,8 +1032,8 @@ public LinkAccounts(TenantIdentifier tenantIdentifier, int primaryUserIndex, int @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - AuthRecipe.linkAccounts(main, tenantIdentifier.toAppIdentifier(), tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + AuthRecipe.linkAccounts(main, tenantIdentifier.toAppIdentifier(), storage, TestCase.users.get(recipeUserIndex).getSupertokensUserId(), TestCase.users.get(primaryUserIndex).getSupertokensUserId()); } } @@ -1049,8 +1049,8 @@ public AssociateUserToTenant(TenantIdentifier tenantIdentifier, int userIndex) { @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - Multitenancy.addUserIdToTenant(main, tenantIdentifier, tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + Multitenancy.addUserIdToTenant(main, tenantIdentifier, storage, TestCase.users.get(userIndex).getSupertokensUserId()); } } @@ -1068,8 +1068,8 @@ public UpdateEmailPasswordUserEmail(TenantIdentifier tenantIdentifier, int userI @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - EmailPassword.updateUsersEmailOrPassword(tenantIdentifier.toAppIdentifier(), tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + EmailPassword.updateUsersEmailOrPassword(tenantIdentifier.toAppIdentifier(), storage, main, TestCase.users.get(userIndex).getSupertokensUserId(), email, null); } } @@ -1087,8 +1087,8 @@ public UpdatePlessUserEmail(TenantIdentifier tenantIdentifier, int userIndex, St @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - Passwordless.updateUser(tenantIdentifier.toAppIdentifier(), tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + Passwordless.updateUser(tenantIdentifier.toAppIdentifier(), storage, TestCase.users.get(userIndex).getSupertokensUserId(), new Passwordless.FieldUpdate(email), null); } } @@ -1106,8 +1106,8 @@ public UpdatePlessUserPhone(TenantIdentifier tenantIdentifier, int userIndex, St @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - Passwordless.updateUser(tenantIdentifier.toAppIdentifier(), tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + Passwordless.updateUser(tenantIdentifier.toAppIdentifier(), storage, TestCase.users.get(userIndex).getSupertokensUserId(), null, new Passwordless.FieldUpdate(phoneNumber)); } } @@ -1123,8 +1123,8 @@ public UnlinkAccount(TenantIdentifier tenantIdentifier, int userIndex) { @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - AuthRecipe.unlinkAccounts(main, tenantIdentifier.toAppIdentifier(), tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + AuthRecipe.unlinkAccounts(main, tenantIdentifier.toAppIdentifier(), storage, TestCase.users.get(userIndex).getSupertokensUserId()); } } @@ -1140,8 +1140,8 @@ public SignInEmailPasswordUser(TenantIdentifier tenantIdentifier, int userIndex) @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - EmailPassword.signIn(tenantIdentifier, tenantIdentifierWithStorage, main, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + EmailPassword.signIn(tenantIdentifier, storage, main, TestCase.users.get(userIndex).loginMethods[0].email, "password"); } } @@ -1157,8 +1157,8 @@ public DisassociateUserFromTenant(TenantIdentifier tenantIdentifier, int userInd @Override public void execute(Main main) throws Exception { - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(tenantIdentifier, main)); - Multitenancy.removeUserIdFromTenant(main, tenantIdentifier, tenantIdentifierWithStorage, + Storage storage = (StorageLayer.getStorage(tenantIdentifier, main)); + Multitenancy.removeUserIdFromTenant(main, tenantIdentifier, storage, TestCase.users.get(userIndex).getSupertokensUserId(), null); } } diff --git a/src/test/java/io/supertokens/test/accountlinking/SessionTests.java b/src/test/java/io/supertokens/test/accountlinking/SessionTests.java index 2633d5b33..c84b8aac1 100644 --- a/src/test/java/io/supertokens/test/accountlinking/SessionTests.java +++ b/src/test/java/io/supertokens/test/accountlinking/SessionTests.java @@ -283,27 +283,27 @@ public void testSessionBehaviourWhenUserBelongsTo2TenantsAndThenLinkedToSomeOthe createTenants(process.getProcess()); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password"); - AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test1@example.com", + AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test1@example.com", "password"); AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), - t1WithStorage, user2.getSupertokensUserId()); - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, user1.getSupertokensUserId()); + t1Storage, user2.getSupertokensUserId()); + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, user1.getSupertokensUserId()); - SessionInformationHolder session1 = Session.createNewSession(t2, t2WithStorage, process.getProcess(), + SessionInformationHolder session1 = Session.createNewSession(t2, t2Storage, process.getProcess(), user1.getSupertokensUserId(), new JsonObject(), new JsonObject()); // Linking user1 to user2 on t1 should revoke the session - AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, + AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId(), user2.getSupertokensUserId()); try { - Session.getSession(t2, t2WithStorage, session1.session.handle); + Session.getSession(t2, t2Storage, session1.session.handle); fail(); } catch (UnauthorisedException e) { // ok @@ -329,27 +329,27 @@ public void testSessionBehaviourWhenUserBelongsTo2TenantsAndThenLinkedToSomeOthe createTenants(process.getProcess()); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password"); - AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test1@example.com", + AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test1@example.com", "password"); AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), - t1WithStorage, user2.getSupertokensUserId()); + t1Storage, user2.getSupertokensUserId()); - SessionInformationHolder session1 = Session.createNewSession(t2, t2WithStorage, process.getProcess(), + SessionInformationHolder session1 = Session.createNewSession(t2, t2Storage, process.getProcess(), user1.getSupertokensUserId(), new JsonObject(), new JsonObject()); // Linking user1 to user2 on t1 should revoke the session - AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, + AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId(), user2.getSupertokensUserId()); try { // session gets removed on t2 as well - Session.getSession(t2, t2WithStorage, session1.session.handle); + Session.getSession(t2, t2Storage, session1.session.handle); fail(); } catch (UnauthorisedException e) { // ok @@ -375,26 +375,26 @@ public void testSessionBehaviourWhenUserBelongsTo2TenantsAndThenLinkedToSomeOthe createTenants(process.getProcess()); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password"); - AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test1@example.com", + AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test1@example.com", "password"); - AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, + AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1Storage, user2.getSupertokensUserId()); - AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, user1.getSupertokensUserId(), + AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId(), user2.getSupertokensUserId()); - SessionInformationHolder session1 = Session.createNewSession(t2, t2WithStorage, process.getProcess(), + SessionInformationHolder session1 = Session.createNewSession(t2, t2Storage, process.getProcess(), user1.getSupertokensUserId(), new JsonObject(), new JsonObject()); - AuthRecipe.unlinkAccounts(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, user2.getSupertokensUserId()); + AuthRecipe.unlinkAccounts(process.getProcess(), t1.toAppIdentifier(), t1Storage, user2.getSupertokensUserId()); // session must be intact - Session.getSession(t2, t2WithStorage, session1.session.handle); + Session.getSession(t2, t2Storage, session1.session.handle); process.kill(); assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED)); @@ -416,20 +416,20 @@ public void testCreateSessionUsesPrimaryUserIdEvenWhenTheUserIsNotInThatTenant() createTenants(process.getProcess()); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user1 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password"); - AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test1@example.com", + AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test1@example.com", "password"); - AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, + AuthRecipe.createPrimaryUser(process.getProcess(), t1.toAppIdentifier(), t1Storage, user2.getSupertokensUserId()); - AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1WithStorage, user1.getSupertokensUserId(), + AuthRecipe.linkAccounts(process.getProcess(), t1.toAppIdentifier(), t1Storage, user1.getSupertokensUserId(), user2.getSupertokensUserId()); - SessionInformationHolder session1 = Session.createNewSession(t2, t2WithStorage, process.getProcess(), + SessionInformationHolder session1 = Session.createNewSession(t2, t2Storage, process.getProcess(), user1.getSupertokensUserId(), new JsonObject(), new JsonObject()); // Should still consider the primaryUserId diff --git a/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java b/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java index 9742481d0..77b0ff9ea 100644 --- a/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/authRecipe/MultitenantAPITest.java @@ -211,7 +211,7 @@ private void createUsers() { // passwordless users recipeToUsers.put("passwordless", new ArrayList<>()); for (TenantIdentifier tenant : new TenantIdentifier[]{t1, t2, t3}) { - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getStorage(tenant, process.getProcess())); { if (tenantToUsers.get(tenant) == null) { @@ -220,14 +220,14 @@ private void createUsers() Passwordless.CreateCodeResponse codeResponse = Passwordless.createCode( tenant, - tenantIdentifierWithStorage, + storage, process.getProcess(), "user@example.com", null, null, "abcd" ); Passwordless.ConsumeCodeResponse response = Passwordless.consumeCode( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), codeResponse.deviceId, codeResponse.deviceIdHash, "abcd", null); tenantToUsers.get(tenant).add(response.user.getSupertokensUserId()); @@ -235,14 +235,14 @@ private void createUsers() } { Passwordless.CreateCodeResponse codeResponse = Passwordless.createCode( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), "user@gmail.com", null, null, "abcd" ); Passwordless.ConsumeCodeResponse response = Passwordless.consumeCode( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), codeResponse.deviceId, codeResponse.deviceIdHash, "abcd", null); tenantToUsers.get(tenant).add(response.user.getSupertokensUserId()); @@ -250,14 +250,14 @@ private void createUsers() } { Passwordless.CreateCodeResponse codeResponse = Passwordless.createCode( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), null, "+1234567890", null, "abcd" ); Passwordless.ConsumeCodeResponse response = Passwordless.consumeCode( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), codeResponse.deviceId, codeResponse.deviceIdHash, "abcd", null); tenantToUsers.get(tenant).add(response.user.getSupertokensUserId()); @@ -265,14 +265,14 @@ private void createUsers() } { Passwordless.CreateCodeResponse codeResponse = Passwordless.createCode( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), null, "+9876543210", null, "abcd" ); Passwordless.ConsumeCodeResponse response = Passwordless.consumeCode( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), codeResponse.deviceId, codeResponse.deviceIdHash, "abcd", null); tenantToUsers.get(tenant).add(response.user.getSupertokensUserId()); @@ -288,29 +288,29 @@ private void createUsers() tenantToUsers.put(tenant, new ArrayList<>()); } - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getStorage(tenant, process.getProcess())); ThirdParty.SignInUpResponse user1 = ThirdParty.signInUp( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), "google", "googleid1", "user@example.com"); tenantToUsers.get(tenant).add(user1.user.getSupertokensUserId()); recipeToUsers.get("thirdparty").add(user1.user.getSupertokensUserId()); ThirdParty.SignInUpResponse user2 = ThirdParty.signInUp( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), "google", "googleid2", "user@gmail.com"); tenantToUsers.get(tenant).add(user2.user.getSupertokensUserId()); recipeToUsers.get("thirdparty").add(user2.user.getSupertokensUserId()); ThirdParty.SignInUpResponse user3 = ThirdParty.signInUp( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), "facebook", "facebookid1", "user@example.com"); tenantToUsers.get(tenant).add(user3.user.getSupertokensUserId()); recipeToUsers.get("thirdparty").add(user3.user.getSupertokensUserId()); ThirdParty.SignInUpResponse user4 = ThirdParty.signInUp( - tenant, tenantIdentifierWithStorage, + tenant, storage, process.getProcess(), "facebook", "facebookid2", "user@gmail.com"); tenantToUsers.get(tenant).add(user4.user.getSupertokensUserId()); recipeToUsers.get("thirdparty").add(user4.user.getSupertokensUserId()); diff --git a/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java b/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java index 1a38a670a..ce47e885d 100644 --- a/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java +++ b/src/test/java/io/supertokens/test/authRecipe/UserPaginationTest.java @@ -182,12 +182,12 @@ private void createUsers(TenantIdentifier tenantIdentifier, int numUsers, String tenantToUsers.put(tenantIdentifier, new ArrayList<>()); } - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getStorage(tenantIdentifier, process.getProcess())); for (int i = 0; i < numUsers; i++) { { AuthRecipeUserInfo user = EmailPassword.signUp( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), + tenantIdentifier, storage, process.getProcess(), prefix + "epuser" + i + "@example.com", "password" + i); tenantToUsers.get(tenantIdentifier).add(user.getSupertokensUserId()); if (!recipeToUsers.containsKey("emailpassword")) { @@ -197,14 +197,14 @@ private void createUsers(TenantIdentifier tenantIdentifier, int numUsers, String } { Passwordless.CreateCodeResponse codeResponse = Passwordless.createCode( - tenantIdentifier, tenantIdentifierWithStorage, + tenantIdentifier, storage, process.getProcess(), prefix + "pluser" + i + "@example.com", null, null, "abcd" ); Passwordless.ConsumeCodeResponse response = Passwordless.consumeCode( - tenantIdentifier, tenantIdentifierWithStorage, + tenantIdentifier, storage, process.getProcess(), codeResponse.deviceId, codeResponse.deviceIdHash, "abcd", null); tenantToUsers.get(tenantIdentifier).add(response.user.getSupertokensUserId()); @@ -216,11 +216,11 @@ private void createUsers(TenantIdentifier tenantIdentifier, int numUsers, String } { ThirdParty.SignInUpResponse user1 = ThirdParty.signInUp( - tenantIdentifier, tenantIdentifierWithStorage, + tenantIdentifier, storage, process.getProcess(), "google", "googleid" + i, prefix + "tpuser" + i + "@example.com"); tenantToUsers.get(tenantIdentifier).add(user1.user.getSupertokensUserId()); ThirdParty.SignInUpResponse user2 = ThirdParty.signInUp( - tenantIdentifier, tenantIdentifierWithStorage, + tenantIdentifier, storage, process.getProcess(), "facebook", "fbid" + i, prefix + "tpuser" + i + "@example.com"); tenantToUsers.get(tenantIdentifier).add(user2.user.getSupertokensUserId()); 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 bdf0e47c1..4ca94e890 100644 --- a/src/test/java/io/supertokens/test/dashboard/apis/MultitenantAPITest.java +++ b/src/test/java/io/supertokens/test/dashboard/apis/MultitenantAPITest.java @@ -170,9 +170,9 @@ public void testSessionBehavior() throws Exception { String email = "test@example.com"; String password = "testPass123"; - Storage appIdentifierWithStorage = ( + Storage appIdentifierStorage = ( StorageLayer.getStorage(t1, process.getProcess())); - Dashboard.signUpDashboardUser(t1.toAppIdentifier(), appIdentifierWithStorage, process.getProcess(), email, + Dashboard.signUpDashboardUser(t1.toAppIdentifier(), appIdentifierStorage, process.getProcess(), email, password); // create a session diff --git a/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java b/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java index 79da774a1..3e6a81c13 100644 --- a/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java +++ b/src/test/java/io/supertokens/test/emailpassword/EmailPasswordTest.java @@ -938,9 +938,9 @@ public void updateEmailSucceedsIfEmailUsedByOtherPrimaryUserInDifferentTenantWhi new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), new JsonObject())); - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(process.main)); + Storage storage = (StorageLayer.getStorage(process.main)); AuthRecipeUserInfo user0 = EmailPassword.signUp( - new TenantIdentifier(null, null, "t1"), tenantIdentifierWithStorage, process.getProcess(), + new TenantIdentifier(null, null, "t1"), storage, process.getProcess(), "someemail1@gmail.com", "pass1234"); @@ -975,9 +975,9 @@ public void updateEmailFailsIfEmailUsedByOtherPrimaryUserInDifferentTenant() new ThirdPartyConfig(true, new ThirdPartyConfig.Provider[0]), new PasswordlessConfig(true), new JsonObject())); - Storage tenantIdentifierWithStorage = (StorageLayer.getStorage(process.main)); + Storage storage = (StorageLayer.getStorage(process.main)); AuthRecipeUserInfo user0 = EmailPassword.signUp( - new TenantIdentifier(null, null, "t1"), tenantIdentifierWithStorage, process.getProcess(), + new TenantIdentifier(null, null, "t1"), storage, process.getProcess(), "someemail1@gmail.com", "pass1234"); @@ -987,7 +987,7 @@ public void updateEmailFailsIfEmailUsedByOtherPrimaryUserInDifferentTenant() AuthRecipe.createPrimaryUser(process.main, user.getSupertokensUserId()); Multitenancy.addUserIdToTenant(process.main, - new TenantIdentifier(null, null, "t1"), tenantIdentifierWithStorage, user.getSupertokensUserId()); + new TenantIdentifier(null, null, "t1"), storage, user.getSupertokensUserId()); try { EmailPassword.updateUsersEmailOrPassword(process.main, user.getSupertokensUserId(), "someemail1@gmail.com", null); diff --git a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java index 73e016b66..c00baf80f 100644 --- a/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java +++ b/src/test/java/io/supertokens/test/multitenant/AppTenantUserTest.java @@ -117,11 +117,11 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new JsonObject() ), false); - Storage tWithStorage = ( + Storage tStorage = ( StorageLayer.getStorage(t, process.getProcess())); - AuthRecipeUserInfo user = EmailPassword.signUp(t, tWithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo user = EmailPassword.signUp(t, tStorage, process.getProcess(), "test@example.com", "password"); String userId = user.getSupertokensUserId(); @@ -130,7 +130,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { try { UserIdMapping.findNonAuthStoragesWhereUserIdIsUsedOrAssertIfUsed( - t.toAppIdentifier(), tWithStorage, userId, true); + t.toAppIdentifier(), tStorage, userId, true); fail(className); } catch (Exception ignored) { assertTrue(ignored.getMessage().contains("UserId is already in use")); @@ -157,7 +157,7 @@ public void testDeletingAppDeleteNonAuthRecipeData() throws Exception { new JsonObject() ), false); - UserIdMapping.findNonAuthStoragesWhereUserIdIsUsedOrAssertIfUsed(t.toAppIdentifier(), tWithStorage, + UserIdMapping.findNonAuthStoragesWhereUserIdIsUsedOrAssertIfUsed(t.toAppIdentifier(), tStorage, userId, true); } } @@ -214,9 +214,9 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception new JsonObject() ), false); - Storage appWithStorage = ( + Storage appStorage = ( StorageLayer.getStorage(app, process.getProcess())); - Storage tenantWithStorage = ( + Storage tenantStorage = ( StorageLayer.getStorage(tenant, process.getProcess())); for (String className : classNames) { @@ -224,29 +224,29 @@ public void testDisassociationOfUserDeletesNonAuthRecipeData() throws Exception continue; } - AuthRecipeUserInfo user = EmailPassword.signUp(app, appWithStorage, process.getProcess(), "test@example.com", "password"); + AuthRecipeUserInfo user = EmailPassword.signUp(app, appStorage, process.getProcess(), "test@example.com", "password"); String userId = user.getSupertokensUserId(); - Multitenancy.addUserIdToTenant(process.getProcess(), tenant, tenantWithStorage, userId); + Multitenancy.addUserIdToTenant(process.getProcess(), tenant, tenantStorage, userId); // create entry in nonAuth table - tenantWithStorage.addInfoToNonAuthRecipesBasedOnUserId(tenant, className, userId); + tenantStorage.addInfoToNonAuthRecipesBasedOnUserId(tenant, className, userId); try { UserIdMapping.findNonAuthStoragesWhereUserIdIsUsedOrAssertIfUsed( - tenant.toAppIdentifier(), tenantWithStorage, userId, true); + tenant.toAppIdentifier(), tenantStorage, userId, true); fail(className); } catch (Exception ignored) { assertTrue(ignored.getMessage().contains("UserId is already in use")); } // Disassociate user - Multitenancy.removeUserIdFromTenant(process.getProcess(), tenant, tenantWithStorage, userId, null); + Multitenancy.removeUserIdFromTenant(process.getProcess(), tenant, tenantStorage, userId, null); - assertFalse(AuthRecipe.deleteNonAuthRecipeUser(tenant, tenantWithStorage, + assertFalse(AuthRecipe.deleteNonAuthRecipeUser(tenant, tenantStorage, userId)); // Nothing deleted indicates that the non auth recipe user data was deleted already - AuthRecipe.deleteUser(app.toAppIdentifier(), appWithStorage, userId); + AuthRecipe.deleteUser(app.toAppIdentifier(), appStorage, userId); } process.kill(); @@ -287,20 +287,20 @@ public void deletingTenantKeepsTheUserInTheApp() throws Exception { new JsonObject() ), false); - Storage appWithStorage = ( + Storage appStorage = ( StorageLayer.getStorage(app, process.getProcess())); - Storage tenantWithStorage = ( + Storage tenantStorage = ( StorageLayer.getStorage(tenant, process.getProcess())); - AuthRecipeUserInfo user = EmailPassword.signUp(tenant, tenantWithStorage, process.getProcess(), "test@example.com", "password"); + AuthRecipeUserInfo user = EmailPassword.signUp(tenant, tenantStorage, process.getProcess(), "test@example.com", "password"); String userId = user.getSupertokensUserId(); Multitenancy.deleteTenant(tenant, process.getProcess()); - Multitenancy.addUserIdToTenant(process.getProcess(), app, appWithStorage, + Multitenancy.addUserIdToTenant(process.getProcess(), app, appStorage, userId); // user id must be intact to do this - AuthRecipeUserInfo appUser = EmailPassword.getUserUsingId(app.toAppIdentifier(), appWithStorage, userId); + AuthRecipeUserInfo appUser = EmailPassword.getUserUsingId(app.toAppIdentifier(), appStorage, userId); assertNotNull(appUser); assertEquals(userId, appUser.getSupertokensUserId()); diff --git a/src/test/java/io/supertokens/test/multitenant/TestAppData.java b/src/test/java/io/supertokens/test/multitenant/TestAppData.java index 5a30a3dea..73f8b1209 100644 --- a/src/test/java/io/supertokens/test/multitenant/TestAppData.java +++ b/src/test/java/io/supertokens/test/multitenant/TestAppData.java @@ -116,62 +116,62 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { new JsonObject() ), false); - Storage appWithStorage = ( + Storage appStorage = ( StorageLayer.getStorage(app, process.getProcess())); - String[] allTableNames = appWithStorage.getAllTablesInTheDatabase(); + String[] allTableNames = appStorage.getAllTablesInTheDatabase(); allTableNames = removeStrings(allTableNames, tablesToIgnore); Arrays.sort(allTableNames); // Add all recipe data - AuthRecipeUserInfo epUser = EmailPassword.signUp(app, appWithStorage, process.getProcess(), "test@example.com", + AuthRecipeUserInfo epUser = EmailPassword.signUp(app, appStorage, process.getProcess(), "test@example.com", "password"); - EmailPassword.generatePasswordResetTokenBeforeCdi4_0(app, appWithStorage, process.getProcess(), + EmailPassword.generatePasswordResetTokenBeforeCdi4_0(app, appStorage, process.getProcess(), epUser.getSupertokensUserId()); - ThirdParty.SignInUpResponse tpUser = ThirdParty.signInUp(app, appWithStorage, process.getProcess(), "google", + ThirdParty.SignInUpResponse tpUser = ThirdParty.signInUp(app, appStorage, process.getProcess(), "google", "googleid", "test@example.com"); - Passwordless.CreateCodeResponse code = Passwordless.createCode(app, appWithStorage, process.getProcess(), + Passwordless.CreateCodeResponse code = Passwordless.createCode(app, appStorage, process.getProcess(), "test@example.com", null, null, null); - Passwordless.ConsumeCodeResponse plUser = Passwordless.consumeCode(app, appWithStorage, process.getProcess(), + Passwordless.ConsumeCodeResponse plUser = Passwordless.consumeCode(app, appStorage, process.getProcess(), code.deviceId, code.deviceIdHash, code.userInputCode, null); - Passwordless.createCode(app, appWithStorage, process.getProcess(), "test@example.com", null, null, null); + Passwordless.createCode(app, appStorage, process.getProcess(), "test@example.com", null, null, null); - Dashboard.signUpDashboardUser(app.toAppIdentifier(), appWithStorage, process.getProcess(), + Dashboard.signUpDashboardUser(app.toAppIdentifier(), appStorage, process.getProcess(), "user@example.com", "password"); - Dashboard.signInDashboardUser(app.toAppIdentifier(), appWithStorage, process.getProcess(), + Dashboard.signInDashboardUser(app.toAppIdentifier(), appStorage, process.getProcess(), "user@example.com", "password"); - String evToken = EmailVerification.generateEmailVerificationToken(app, appWithStorage, process.getProcess(), + String evToken = EmailVerification.generateEmailVerificationToken(app, appStorage, process.getProcess(), epUser.getSupertokensUserId(), epUser.loginMethods[0].email); - EmailVerification.verifyEmail(app, appWithStorage, evToken); - EmailVerification.generateEmailVerificationToken(app, appWithStorage, process.getProcess(), + EmailVerification.verifyEmail(app, appStorage, evToken); + EmailVerification.generateEmailVerificationToken(app, appStorage, process.getProcess(), tpUser.user.getSupertokensUserId(), tpUser.user.loginMethods[0].email); - Session.createNewSession(app, appWithStorage, process.getProcess(), epUser.getSupertokensUserId(), + Session.createNewSession(app, appStorage, process.getProcess(), epUser.getSupertokensUserId(), new JsonObject(), new JsonObject()); - UserRoles.createNewRoleOrModifyItsPermissions(app.toAppIdentifier(), appWithStorage, "role", + UserRoles.createNewRoleOrModifyItsPermissions(app.toAppIdentifier(), appStorage, "role", new String[]{"permission1", "permission2"}); - UserRoles.addRoleToUser(process.getProcess(), app, appWithStorage, epUser.getSupertokensUserId(), "role"); + UserRoles.addRoleToUser(process.getProcess(), app, appStorage, epUser.getSupertokensUserId(), "role"); - TOTPDevice totpDevice = Totp.registerDevice(app.toAppIdentifier(), appWithStorage, process.getProcess(), + TOTPDevice totpDevice = Totp.registerDevice(app.toAppIdentifier(), appStorage, process.getProcess(), epUser.getSupertokensUserId(), "test", 1, 3); - Totp.verifyCode(app, appWithStorage, process.getProcess(), epUser.getSupertokensUserId(), + Totp.verifyCode(app, appStorage, process.getProcess(), epUser.getSupertokensUserId(), generateTotpCode(process.getProcess(), totpDevice, 0), true); ActiveUsers.updateLastActive(app.toAppIdentifier(), process.getProcess(), epUser.getSupertokensUserId()); - UserMetadata.updateUserMetadata(app.toAppIdentifier(), appWithStorage, + UserMetadata.updateUserMetadata(app.toAppIdentifier(), appStorage, epUser.getSupertokensUserId(), new JsonObject()); - UserIdMapping.createUserIdMapping(process.getProcess(), app.toAppIdentifier(), appWithStorage, + UserIdMapping.createUserIdMapping(process.getProcess(), app.toAppIdentifier(), appStorage, plUser.user.getSupertokensUserId(), "externalid", null, false); - String[] tablesThatHaveData = appWithStorage + String[] tablesThatHaveData = appStorage .getAllTablesInTheDatabaseThatHasDataForAppId(app.getAppId()); tablesThatHaveData = removeStrings(tablesThatHaveData, tablesToIgnore); Arrays.sort(tablesThatHaveData); @@ -182,7 +182,7 @@ public void testThatDeletingAppDeleteDataFromAllTables() throws Exception { Multitenancy.deleteApp(app.toAppIdentifier(), process.getProcess()); // Check no data is remaining in any of the tables - tablesThatHaveData = appWithStorage.getAllTablesInTheDatabaseThatHasDataForAppId(app.getAppId()); + tablesThatHaveData = appStorage.getAllTablesInTheDatabaseThatHasDataForAppId(app.getAppId()); tablesThatHaveData = removeStrings(tablesThatHaveData, tablesToIgnore); assertEquals(0, tablesThatHaveData.length); diff --git a/src/test/java/io/supertokens/test/multitenant/api/TestPermissionChecks.java b/src/test/java/io/supertokens/test/multitenant/api/TestPermissionChecks.java index e2f9e4a32..9a890db27 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestPermissionChecks.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestPermissionChecks.java @@ -218,15 +218,15 @@ public void testPermissionsForListTenants() throws Exception { TestCase[] testCases = new TestCase[]{ new TestCase( new TenantIdentifier("127.0.0.1", "a1", "t1"), null, - "Only the public tenantId is allowed to list all tenants associated with this app" + "Only public tenantId can call this app specific API" ), new TestCase( new TenantIdentifier("127.0.0.1", null, "t1"), null, - "Only the public tenantId is allowed to list all tenants associated with this app" + "Only public tenantId can call this app specific API" ), new TestCase( new TenantIdentifier(null, null, "t1"), null, - "Only the public tenantId is allowed to list all tenants associated with this app" + "Only public tenantId can call this app specific API" ), new TestCase( new TenantIdentifier(null, null, null), null, null 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 5aac955c6..8243b73fe 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenantIdIsNotPresentForOlderCDI.java @@ -282,12 +282,12 @@ private void createUsers(TenantIdentifier tenantIdentifier, int numUsers, String tenantToUsers.put(tenantIdentifier, new ArrayList<>()); } - Storage tenantIdentifierWithStorage = ( + Storage storage = ( StorageLayer.getStorage(tenantIdentifier, process.getProcess())); for (int i = 0; i < numUsers; i++) { { AuthRecipeUserInfo user = EmailPassword.signUp( - tenantIdentifier, tenantIdentifierWithStorage, process.getProcess(), + tenantIdentifier, storage, process.getProcess(), prefix + "epuser" + i + "@example.com", "password" + i); tenantToUsers.get(tenantIdentifier).add(user.getSupertokensUserId()); if (!recipeToUsers.containsKey("emailpassword")) { @@ -298,14 +298,14 @@ private void createUsers(TenantIdentifier tenantIdentifier, int numUsers, String { Passwordless.CreateCodeResponse codeResponse = Passwordless.createCode( tenantIdentifier, - tenantIdentifierWithStorage, + storage, process.getProcess(), prefix + "pluser" + i + "@example.com", null, null, "abcd" ); Passwordless.ConsumeCodeResponse response = Passwordless.consumeCode( - tenantIdentifier, tenantIdentifierWithStorage, + tenantIdentifier, storage, process.getProcess(), codeResponse.deviceId, codeResponse.deviceIdHash, "abcd", null); tenantToUsers.get(tenantIdentifier).add(response.user.getSupertokensUserId()); @@ -317,11 +317,11 @@ private void createUsers(TenantIdentifier tenantIdentifier, int numUsers, String } { ThirdParty.SignInUpResponse user1 = ThirdParty.signInUp( - tenantIdentifier, tenantIdentifierWithStorage, + tenantIdentifier, storage, process.getProcess(), "google", "googleid" + i, prefix + "tpuser" + i + "@example.com"); tenantToUsers.get(tenantIdentifier).add(user1.user.getSupertokensUserId()); ThirdParty.SignInUpResponse user2 = ThirdParty.signInUp( - tenantIdentifier, tenantIdentifierWithStorage, + tenantIdentifier, storage, process.getProcess(), "facebook", "fbid" + i, prefix + "tpuser" + i + "@example.com"); tenantToUsers.get(tenantIdentifier).add(user2.user.getSupertokensUserId()); 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 90ab8acf9..6830d38ae 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestTenantUserAssociation.java @@ -275,24 +275,24 @@ public void testEmailPasswordUsersHaveTenantIds() throws Exception { TenantIdentifier t1 = new TenantIdentifier(null, "a1", "t1"); TenantIdentifier t2 = new TenantIdentifier(null, "a1", "t2"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - AuthRecipeUserInfo user = EmailPassword.signUp(t1, t1WithStorage, + AuthRecipeUserInfo user = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "user@example.com", "password"); assertArrayEquals(new String[]{"t1"}, user.tenantIds.toArray()); - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, user.getSupertokensUserId()); - user = EmailPassword.getUserUsingId(t1.toAppIdentifier(), t1WithStorage, user.getSupertokensUserId()); + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, user.getSupertokensUserId()); + user = EmailPassword.getUserUsingId(t1.toAppIdentifier(), t1Storage, user.getSupertokensUserId()); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - user = EmailPassword.getUserUsingEmail(t1, t1WithStorage, user.loginMethods[0].email); + user = EmailPassword.getUserUsingEmail(t1, t1Storage, user.loginMethods[0].email); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1WithStorage, user.getSupertokensUserId(), + Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1Storage, user.getSupertokensUserId(), null); - user = EmailPassword.getUserUsingId(t1.toAppIdentifier(), t1WithStorage, user.getSupertokensUserId()); + user = EmailPassword.getUserUsingId(t1.toAppIdentifier(), t1Storage, user.getSupertokensUserId()); assertArrayEquals(new String[]{"t2"}, user.tenantIds.toArray()); } @@ -307,29 +307,29 @@ public void testPasswordlessUsersHaveTenantIds1() throws Exception { TenantIdentifier t1 = new TenantIdentifier(null, "a1", "t1"); TenantIdentifier t2 = new TenantIdentifier(null, "a1", "t2"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - Passwordless.CreateCodeResponse createCodeResponse = Passwordless.createCode(t1, t1WithStorage, + Passwordless.CreateCodeResponse createCodeResponse = Passwordless.createCode(t1, t1Storage, process.getProcess(), "user@example.com", null, null, null); - Passwordless.ConsumeCodeResponse consumeCodeResponse = Passwordless.consumeCode(t1, t1WithStorage, + Passwordless.ConsumeCodeResponse consumeCodeResponse = Passwordless.consumeCode(t1, t1Storage, process.getProcess(), createCodeResponse.deviceId, createCodeResponse.deviceIdHash, createCodeResponse.userInputCode, null); assertArrayEquals(new String[]{"t1"}, consumeCodeResponse.user.tenantIds.toArray()); AuthRecipeUserInfo user; - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, consumeCodeResponse.user.getSupertokensUserId()); - user = Passwordless.getUserById(t1.toAppIdentifier(), t1WithStorage, + user = Passwordless.getUserById(t1.toAppIdentifier(), t1Storage, consumeCodeResponse.user.getSupertokensUserId()); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - user = Passwordless.getUserByEmail(t1, t1WithStorage, consumeCodeResponse.user.loginMethods[0].email); + user = Passwordless.getUserByEmail(t1, t1Storage, consumeCodeResponse.user.loginMethods[0].email); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1WithStorage, + Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1Storage, consumeCodeResponse.user.getSupertokensUserId(), null); - user = Passwordless.getUserById(t1.toAppIdentifier(), t1WithStorage, + user = Passwordless.getUserById(t1.toAppIdentifier(), t1Storage, consumeCodeResponse.user.getSupertokensUserId()); assertArrayEquals(new String[]{"t2"}, user.tenantIds.toArray()); } @@ -345,30 +345,30 @@ public void testPasswordlessUsersHaveTenantIds2() throws Exception { TenantIdentifier t1 = new TenantIdentifier(null, "a1", "t1"); TenantIdentifier t2 = new TenantIdentifier(null, "a1", "t2"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - Passwordless.CreateCodeResponse createCodeResponse = Passwordless.createCode(t1, t1WithStorage, + Passwordless.CreateCodeResponse createCodeResponse = Passwordless.createCode(t1, t1Storage, process.getProcess(), null, "+919876543210", null, null); - Passwordless.ConsumeCodeResponse consumeCodeResponse = Passwordless.consumeCode(t1, t1WithStorage, + Passwordless.ConsumeCodeResponse consumeCodeResponse = Passwordless.consumeCode(t1, t1Storage, process.getProcess(), createCodeResponse.deviceId, createCodeResponse.deviceIdHash, createCodeResponse.userInputCode, null); assertArrayEquals(new String[]{"t1"}, consumeCodeResponse.user.tenantIds.toArray()); AuthRecipeUserInfo user; - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, consumeCodeResponse.user.getSupertokensUserId()); - user = Passwordless.getUserById(t1.toAppIdentifier(), t1WithStorage, + user = Passwordless.getUserById(t1.toAppIdentifier(), t1Storage, consumeCodeResponse.user.getSupertokensUserId()); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - user = Passwordless.getUserByPhoneNumber(t1, t1WithStorage, + user = Passwordless.getUserByPhoneNumber(t1, t1Storage, consumeCodeResponse.user.loginMethods[0].phoneNumber); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1WithStorage, + Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1Storage, consumeCodeResponse.user.getSupertokensUserId(), null); - user = Passwordless.getUserById(t1.toAppIdentifier(), t1WithStorage, consumeCodeResponse.user.getSupertokensUserId()); + user = Passwordless.getUserById(t1.toAppIdentifier(), t1Storage, consumeCodeResponse.user.getSupertokensUserId()); assertArrayEquals(new String[]{"t2"}, user.tenantIds.toArray()); } @@ -383,32 +383,32 @@ public void testThirdPartyUsersHaveTenantIds() throws Exception { TenantIdentifier t1 = new TenantIdentifier(null, "a1", "t1"); TenantIdentifier t2 = new TenantIdentifier(null, "a1", "t2"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - ThirdParty.SignInUpResponse signInUpResponse = ThirdParty.signInUp(t1, t1WithStorage, process.getProcess(), + ThirdParty.SignInUpResponse signInUpResponse = ThirdParty.signInUp(t1, t1Storage, process.getProcess(), "google", "googleid", "user@example.com"); assertArrayEquals(new String[]{"t1"}, signInUpResponse.user.tenantIds.toArray()); - Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2WithStorage, + Multitenancy.addUserIdToTenant(process.getProcess(), t2, t2Storage, signInUpResponse.user.getSupertokensUserId()); AuthRecipeUserInfo user = ThirdParty.getUser( - t1.toAppIdentifier(), t1WithStorage, signInUpResponse.user.getSupertokensUserId()); + t1.toAppIdentifier(), t1Storage, signInUpResponse.user.getSupertokensUserId()); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - user = ThirdParty.getUsersByEmail(t1, t1WithStorage, signInUpResponse.user.loginMethods[0].email)[0]; + user = ThirdParty.getUsersByEmail(t1, t1Storage, signInUpResponse.user.loginMethods[0].email)[0]; Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - user = ThirdParty.getUser(t1, t1WithStorage, "google", "googleid"); + user = ThirdParty.getUser(t1, t1Storage, "google", "googleid"); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - user = ThirdParty.getUser(t2, t2WithStorage, "google", "googleid"); + user = ThirdParty.getUser(t2, t2Storage, "google", "googleid"); Utils.assertArrayEqualsIgnoreOrder(new String[]{"t1", "t2"}, user.tenantIds.toArray()); - Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1WithStorage, + Multitenancy.removeUserIdFromTenant(process.getProcess(), t1, t1Storage, signInUpResponse.user.getSupertokensUserId(), null); - user = ThirdParty.getUser(t1.toAppIdentifier(), t1WithStorage, signInUpResponse.user.getSupertokensUserId()); + user = ThirdParty.getUser(t1.toAppIdentifier(), t1Storage, signInUpResponse.user.getSupertokensUserId()); assertArrayEquals(new String[]{"t2"}, user.tenantIds.toArray()); } @@ -495,9 +495,9 @@ public void testDisassociateUserWithUserIdMappingAndSession() throws Exception { assertFalse(response.get("wasAlreadyAssociated").getAsBoolean()); TenantIdentifier t2 = new TenantIdentifier(null, "a1", "t2"); - Storage t2WithStorage = (StorageLayer.getStorage(t2, process.getProcess())); + Storage t2Storage = (StorageLayer.getStorage(t2, process.getProcess())); - SessionInformationHolder session = Session.createNewSession(t2, t2WithStorage, + SessionInformationHolder session = Session.createNewSession(t2, t2Storage, process.getProcess(), "externalid", new JsonObject(), new JsonObject()); response = TestMultitenancyAPIHelper.disassociateUserFromTenant(new TenantIdentifier(null, "a1", "t2"), @@ -506,7 +506,7 @@ public void testDisassociateUserWithUserIdMappingAndSession() throws Exception { assertTrue(response.get("wasAssociated").getAsBoolean()); try { - Session.getSession(t2, t2WithStorage, session.session.handle); + Session.getSession(t2, t2Storage, session.session.handle); fail(); } catch (UnauthorisedException e) { // OK 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 13127ba7b..2904d5247 100644 --- a/src/test/java/io/supertokens/test/multitenant/api/TestWithNonAuthRecipes.java +++ b/src/test/java/io/supertokens/test/multitenant/api/TestWithNonAuthRecipes.java @@ -87,17 +87,17 @@ public void beforeEach() throws InterruptedException, InvalidProviderConfigExcep @Test public void testThatUserMetadataIsSavedInTheStorageWhereUserExists() throws Exception { TenantIdentifier t0 = new TenantIdentifier(null, null, null); - Storage t0WithStorage = (StorageLayer.getStorage(t0, process.getProcess())); + Storage t0Storage = (StorageLayer.getStorage(t0, process.getProcess())); TenantIdentifier t1 = new TenantIdentifier(null, null, "t1"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); // Create users - AuthRecipeUserInfo user1 = EmailPassword.signUp(t0, t0WithStorage, process.getProcess(), "test@example.com", "password123"); - AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", "password123"); + AuthRecipeUserInfo user1 = EmailPassword.signUp(t0, t0Storage, process.getProcess(), "test@example.com", "password123"); + AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password123"); - UserIdMapping.populateExternalUserIdForUsers(t0WithStorage, new AuthRecipeUserInfo[]{user1}); - UserIdMapping.populateExternalUserIdForUsers(t1WithStorage, new AuthRecipeUserInfo[]{user2}); + UserIdMapping.populateExternalUserIdForUsers(t0Storage, new AuthRecipeUserInfo[]{user1}); + UserIdMapping.populateExternalUserIdForUsers(t1Storage, new AuthRecipeUserInfo[]{user2}); // Check that get user by ID works fine JsonObject jsonUser1 = TestMultitenancyAPIHelper.getUserById(t0, user1.getSupertokensUserId(), process.getProcess()); @@ -149,8 +149,8 @@ public void testThatUserMetadataIsSavedInTheStorageWhereUserExists() throws Exce } } - UserMetadataSQLStorage t0UserMetadataStorage = StorageUtils.getUserMetadataStorage(t0WithStorage); - UserMetadataSQLStorage t1UserMetadataStorage = StorageUtils.getUserMetadataStorage(t1WithStorage); + UserMetadataSQLStorage t0UserMetadataStorage = StorageUtils.getUserMetadataStorage(t0Storage); + UserMetadataSQLStorage t1UserMetadataStorage = StorageUtils.getUserMetadataStorage(t1Storage); // Ensure that the metadata is saved in the correct storage assertNotNull(t0UserMetadataStorage.getUserMetadata(t0.toAppIdentifier(), user1.getSupertokensUserId())); // ensure t0 storage does not have user2's metadata @@ -176,17 +176,17 @@ public void testThatUserMetadataIsSavedInTheStorageWhereUserExists() throws Exce @Test public void testThatUserRolesWorkWithDifferentTenantsOnDifferentStorages() throws Exception { TenantIdentifier t0 = new TenantIdentifier(null, null, null); - Storage t0WithStorage = (StorageLayer.getStorage(t0, process.getProcess())); + Storage t0Storage = (StorageLayer.getStorage(t0, process.getProcess())); TenantIdentifier t1 = new TenantIdentifier(null, null, "t1"); - Storage t1WithStorage = (StorageLayer.getStorage(t1, process.getProcess())); + Storage t1Storage = (StorageLayer.getStorage(t1, process.getProcess())); // Create users - AuthRecipeUserInfo user1 = EmailPassword.signUp(t0, t0WithStorage, process.getProcess(), "test@example.com", "password123"); - AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1WithStorage, process.getProcess(), "test@example.com", "password123"); + AuthRecipeUserInfo user1 = EmailPassword.signUp(t0, t0Storage, process.getProcess(), "test@example.com", "password123"); + AuthRecipeUserInfo user2 = EmailPassword.signUp(t1, t1Storage, process.getProcess(), "test@example.com", "password123"); - UserIdMapping.populateExternalUserIdForUsers(t0WithStorage, new AuthRecipeUserInfo[]{user1}); - UserIdMapping.populateExternalUserIdForUsers(t1WithStorage, new AuthRecipeUserInfo[]{user2}); + UserIdMapping.populateExternalUserIdForUsers(t0Storage, new AuthRecipeUserInfo[]{user1}); + UserIdMapping.populateExternalUserIdForUsers(t1Storage, new AuthRecipeUserInfo[]{user2}); } 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 7e135958c..43c9f74d5 100644 --- a/src/test/java/io/supertokens/test/totp/api/TotpUserIdMappingTest.java +++ b/src/test/java/io/supertokens/test/totp/api/TotpUserIdMappingTest.java @@ -77,7 +77,7 @@ public void testExternalUserIdTranslation() throws Exception { "totp"); assert res1.get("status").getAsString().equals("OK"); String d1Secret = res1.get("secret").getAsString(); - TOTPDevice device1 = new TOTPDevice(externalUserId, "deviceName", d1Secret, 30, 0, false); + TOTPDevice device1 = new TOTPDevice(externalUserId, "d1", d1Secret, 30, 0, false); body.addProperty("deviceName", "d2"); @@ -93,7 +93,7 @@ public void testExternalUserIdTranslation() throws Exception { "totp"); assert res2.get("status").getAsString().equals("OK"); String d2Secret = res2.get("secret").getAsString(); - TOTPDevice device2 = new TOTPDevice(externalUserId, "deviceName", d2Secret, 30, 0, false); + TOTPDevice device2 = new TOTPDevice(externalUserId, "d2", d2Secret, 30, 0, false); // Verify d1 but not d2: JsonObject verifyD1Input = new JsonObject(); diff --git a/src/test/java/io/supertokens/test/userRoles/UserRolesStorageTest.java b/src/test/java/io/supertokens/test/userRoles/UserRolesStorageTest.java index cefb5a08c..cf4c5dbde 100644 --- a/src/test/java/io/supertokens/test/userRoles/UserRolesStorageTest.java +++ b/src/test/java/io/supertokens/test/userRoles/UserRolesStorageTest.java @@ -470,8 +470,9 @@ public void testAssociatingAnUnknownRoleWithUser() throws Exception { Exception error = null; try { - - storage.addRoleToUser(new TenantIdentifier(null, null, null), "userId", "unknownRole"); + UserRoles.addRoleToUser( + process.getProcess(), new TenantIdentifier(null, null, null), + StorageLayer.getBaseStorage(process.getProcess()), "userId", "unknownRole"); } catch (Exception e) { error = e; }