Skip to content

Commit

Permalink
Fix issue: tenant is defaulting incorrectly based on the ordering of:…
Browse files Browse the repository at this point in the history
… opensearch_security.multitenancy.tenants.preferred

Signed-off-by: Rajat Gupta <[email protected]>
  • Loading branch information
Rajat Gupta committed Jan 7, 2025
1 parent ded4012 commit 0bac77b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/multitenancy/tenant_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 44 additions & 0 deletions server/multitenancy/test/tenant_resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,47 @@ 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"],

Check failure on line 94 in server/multitenancy/test/tenant_resolver.test.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Replace `"Global",·"Private"` with `'Global',·'Private'`

Check failure on line 94 in server/multitenancy/test/tenant_resolver.test.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Replace `"Global",·"Private"` with `'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"],

Check failure on line 109 in server/multitenancy/test/tenant_resolver.test.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Replace `"Private",·"Global"` with `'Private',·'Global'`

Check failure on line 109 in server/multitenancy/test/tenant_resolver.test.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Replace `"Private",·"Global"` with `'Private',·'Global'`
availableTenants: { global_tenant: true, testuser: true },
globalTenantEnabled: true,
multitenancy_enabled: true,
privateTenantEnabled: true,
};

const nonadminResult = resolveWithConfig(nonadminConfig);
expect(nonadminResult).toEqual('');
});
});

Check failure on line 119 in server/multitenancy/test/tenant_resolver.test.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Insert `⏎`

Check failure on line 119 in server/multitenancy/test/tenant_resolver.test.ts

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Insert `␍⏎`

0 comments on commit 0bac77b

Please sign in to comment.