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 (#2163) (#2165)

(cherry picked from commit bc2c444)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 2f7d744 commit 1668137
Show file tree
Hide file tree
Showing 2 changed files with 75 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
74 changes: 74 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,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('');
});
});

0 comments on commit 1668137

Please sign in to comment.