diff --git a/server/multitenancy/tenant_resolver.ts b/server/multitenancy/tenant_resolver.ts index 883ab3deb..26f5cb68f 100755 --- a/server/multitenancy/tenant_resolver.ts +++ b/server/multitenancy/tenant_resolver.ts @@ -23,7 +23,7 @@ import { GLOBAL_TENANT_SYMBOL, globalTenantName, PRIVATE_TENANT_SYMBOL } from '. import { ensureRawRequest } from '../../../../src/core/server/http/router'; import { GOTO_PREFIX } from '../../../../src/plugins/share/common/short_url_routes'; -export const PRIVATE_TENANTS: string[] = [PRIVATE_TENANT_SYMBOL, 'private']; +export const PRIVATE_TENANTS: string[] = [PRIVATE_TENANT_SYMBOL, 'private', 'Private']; export const GLOBAL_TENANTS: string[] = ['global', GLOBAL_TENANT_SYMBOL, 'Global']; /** * Resovles the tenant the user is using. diff --git a/server/multitenancy/test/tenant_resolver.test.ts b/server/multitenancy/test/tenant_resolver.test.ts index 6cb735f80..a0dcccb87 100644 --- a/server/multitenancy/test/tenant_resolver.test.ts +++ b/server/multitenancy/test/tenant_resolver.test.ts @@ -73,3 +73,77 @@ describe("Resolve tenants when multitenancy is enabled and both 'Global' and 'Pr expect(adminResult).toEqual(''); }); }); + +describe("Resolve tenants when multitenancy is enabled and both 'Global' and 'Private' tenants are enabled", () => { + function resolveWithConfig(config: any) { + return resolve( + config.username, + config.requestedTenant, + config.preferredTenants, + config.availableTenants, + config.globalTenantEnabled, + config.multitenancy_enabled, + config.privateTenantEnabled + ); + } + + it('Resolve tenant when requested tenant is Private but preferred tenant is Global', () => { + const nonadminConfig = { + username: 'testuser', + requestedTenant: 'Private', + preferredTenants: ['Global', 'Private'], + availableTenants: { global_tenant: true, testuser: true }, + globalTenantEnabled: true, + multitenancy_enabled: true, + privateTenantEnabled: true, + }; + + const nonadminResult = resolveWithConfig(nonadminConfig); + expect(nonadminResult).toEqual('__user__'); + }); + + it('Resolve tenant when requested tenant is Global but preferred tenant is Private', () => { + const nonadminConfig = { + username: 'testuser', + requestedTenant: 'Global', + preferredTenants: ['Private', 'Global'], + availableTenants: { global_tenant: true, testuser: true }, + globalTenantEnabled: true, + multitenancy_enabled: true, + privateTenantEnabled: true, + }; + + const nonadminResult = resolveWithConfig(nonadminConfig); + expect(nonadminResult).toEqual(''); + }); + + it('Resolve tenant when requested tenant is undefined but preferred tenant is Private', () => { + const nonadminConfig = { + username: 'testuser', + requestedTenant: undefined, + preferredTenants: ['Private', 'Global'], + availableTenants: { global_tenant: true, testuser: true }, + globalTenantEnabled: true, + multitenancy_enabled: true, + privateTenantEnabled: true, + }; + + const nonadminResult = resolveWithConfig(nonadminConfig); + expect(nonadminResult).toEqual('__user__'); + }); + + it('Resolve tenant when requested tenant is undefined but preferred tenant is Global', () => { + const nonadminConfig = { + username: 'testuser', + requestedTenant: undefined, + preferredTenants: ['Global', 'Private'], + availableTenants: { global_tenant: true, testuser: true }, + globalTenantEnabled: true, + multitenancy_enabled: true, + privateTenantEnabled: true, + }; + + const nonadminResult = resolveWithConfig(nonadminConfig); + expect(nonadminResult).toEqual(''); + }); +});