Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue: tenant is defaulting incorrectly based on the ordering of: opensearch_security.multitenancy.tenants.preferred #2019 #2163

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];
RajatGupta02 marked this conversation as resolved.
Show resolved Hide resolved
RajatGupta02 marked this conversation as resolved.
Show resolved Hide resolved
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', () => {
RajatGupta02 marked this conversation as resolved.
Show resolved Hide resolved
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('');
});
});
Loading