2019-09-09 19:15:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
2021-02-04 03:12:39 +01:00
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
* 2.0.
|
2019-09-09 19:15:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { uiCapabilitiesForFeatures } from './ui_capabilities_for_features';
|
2020-09-14 15:30:47 +02:00
|
|
|
import { KibanaFeature } from '.';
|
|
|
|
import { SubFeaturePrivilegeGroupConfig, ElasticsearchFeature } from '../common';
|
2019-09-09 19:15:58 +02:00
|
|
|
|
2020-09-14 15:30:47 +02:00
|
|
|
function createKibanaFeaturePrivilege(capabilities: string[] = []) {
|
2019-09-09 19:15:58 +02:00
|
|
|
return {
|
2020-03-24 16:12:49 +01:00
|
|
|
savedObject: {
|
|
|
|
all: [],
|
|
|
|
read: [],
|
|
|
|
},
|
|
|
|
app: [],
|
|
|
|
ui: [...capabilities],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-14 15:30:47 +02:00
|
|
|
function createKibanaSubFeaturePrivilege(privilegeId: string, capabilities: string[] = []) {
|
2020-03-24 16:12:49 +01:00
|
|
|
return {
|
|
|
|
id: privilegeId,
|
|
|
|
name: `sub-feature privilege ${privilegeId}`,
|
|
|
|
includeIn: 'none',
|
|
|
|
savedObject: {
|
|
|
|
all: [],
|
|
|
|
read: [],
|
2019-09-09 19:15:58 +02:00
|
|
|
},
|
2020-03-24 16:12:49 +01:00
|
|
|
app: [],
|
|
|
|
ui: [...capabilities],
|
2019-09-09 19:15:58 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('populateUICapabilities', () => {
|
|
|
|
it('handles no original uiCapabilities and no registered features gracefully', () => {
|
2020-09-14 15:30:47 +02:00
|
|
|
expect(uiCapabilitiesForFeatures([], [])).toEqual({});
|
2019-09-09 19:15:58 +02:00
|
|
|
});
|
|
|
|
|
2020-09-14 15:30:47 +02:00
|
|
|
it('handles kibana features with no registered capabilities', () => {
|
2019-09-09 19:15:58 +02:00
|
|
|
expect(
|
2020-09-14 15:30:47 +02:00
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
name: 'my new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(),
|
|
|
|
read: createKibanaFeaturePrivilege(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
).toEqual({
|
|
|
|
catalogue: {},
|
|
|
|
management: {},
|
|
|
|
newFeature: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles elasticsearch features with no registered capabilities', () => {
|
|
|
|
expect(
|
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
new ElasticsearchFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
privileges: [
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
)
|
2019-09-09 19:15:58 +02:00
|
|
|
).toEqual({
|
|
|
|
catalogue: {},
|
2020-09-14 15:30:47 +02:00
|
|
|
management: {},
|
2019-09-09 19:15:58 +02:00
|
|
|
newFeature: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-14 15:30:47 +02:00
|
|
|
it('augments the original uiCapabilities with registered kibana feature capabilities', () => {
|
|
|
|
expect(
|
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
name: 'my new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
read: createKibanaFeaturePrivilege(),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
).toEqual({
|
|
|
|
catalogue: {},
|
|
|
|
management: {},
|
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('augments the original uiCapabilities with registered elasticsearch feature capabilities', () => {
|
2019-09-09 19:15:58 +02:00
|
|
|
expect(
|
2020-09-14 15:30:47 +02:00
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
new ElasticsearchFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
privileges: [
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability1', 'capability2'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
)
|
2019-09-09 19:15:58 +02:00
|
|
|
).toEqual({
|
|
|
|
catalogue: {},
|
2020-09-14 15:30:47 +02:00
|
|
|
management: {},
|
2019-09-09 19:15:58 +02:00
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-14 15:30:47 +02:00
|
|
|
it('combines catalogue entries from multiple kibana features', () => {
|
2019-09-09 19:15:58 +02:00
|
|
|
expect(
|
2020-09-14 15:30:47 +02:00
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
name: 'my new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
catalogue: ['anotherFooEntry', 'anotherBarEntry'],
|
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
read: createKibanaFeaturePrivilege(['capability3', 'capability4']),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
)
|
2019-09-09 19:15:58 +02:00
|
|
|
).toEqual({
|
|
|
|
catalogue: {
|
|
|
|
anotherFooEntry: true,
|
|
|
|
anotherBarEntry: true,
|
|
|
|
},
|
2020-09-14 15:30:47 +02:00
|
|
|
management: {},
|
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('combines catalogue entries from multiple elasticsearch privileges', () => {
|
|
|
|
expect(
|
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
new ElasticsearchFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
catalogue: ['anotherFooEntry', 'anotherBarEntry'],
|
|
|
|
privileges: [
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability1', 'capability2'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability3', 'capability4'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
).toEqual({
|
|
|
|
catalogue: {
|
|
|
|
anotherFooEntry: true,
|
|
|
|
anotherBarEntry: true,
|
|
|
|
},
|
|
|
|
management: {},
|
2019-09-09 19:15:58 +02:00
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`merges capabilities from all feature privileges`, () => {
|
|
|
|
expect(
|
2020-09-14 15:30:47 +02:00
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
name: 'my new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
read: createKibanaFeaturePrivilege(['capability3', 'capability4', 'capability5']),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
)
|
2020-03-24 16:12:49 +01:00
|
|
|
).toEqual({
|
|
|
|
catalogue: {},
|
2020-09-14 15:30:47 +02:00
|
|
|
management: {},
|
2020-03-24 16:12:49 +01:00
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
capability5: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-16 18:29:31 +02:00
|
|
|
it(`supports capabilities from reserved privileges`, () => {
|
|
|
|
expect(
|
2020-09-14 15:30:47 +02:00
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
name: 'my new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: null,
|
|
|
|
reserved: {
|
|
|
|
description: '',
|
|
|
|
privileges: [
|
|
|
|
{
|
|
|
|
id: 'rp_1',
|
|
|
|
privilege: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'rp_2',
|
|
|
|
privilege: createKibanaFeaturePrivilege([
|
|
|
|
'capability3',
|
|
|
|
'capability4',
|
|
|
|
'capability5',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
)
|
2020-04-16 18:29:31 +02:00
|
|
|
).toEqual({
|
|
|
|
catalogue: {},
|
2020-09-14 15:30:47 +02:00
|
|
|
management: {},
|
2020-04-16 18:29:31 +02:00
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
capability5: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-24 16:12:49 +01:00
|
|
|
it(`supports merging features with sub privileges`, () => {
|
|
|
|
expect(
|
2020-09-14 15:30:47 +02:00
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
name: 'my new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
read: createKibanaFeaturePrivilege(['capability3', 'capability4']),
|
2020-03-24 16:12:49 +01:00
|
|
|
},
|
2020-09-14 15:30:47 +02:00
|
|
|
subFeatures: [
|
|
|
|
{
|
|
|
|
name: 'sub-feature-1',
|
|
|
|
privilegeGroups: [
|
|
|
|
{
|
|
|
|
groupType: 'independent',
|
|
|
|
privileges: [
|
|
|
|
createKibanaSubFeaturePrivilege('privilege-1', ['capability5']),
|
|
|
|
createKibanaSubFeaturePrivilege('privilege-2', ['capability6']),
|
|
|
|
],
|
|
|
|
} as SubFeaturePrivilegeGroupConfig,
|
|
|
|
{
|
|
|
|
groupType: 'mutually_exclusive',
|
|
|
|
privileges: [
|
|
|
|
createKibanaSubFeaturePrivilege('privilege-3', ['capability7']),
|
|
|
|
createKibanaSubFeaturePrivilege('privilege-4', ['capability8']),
|
|
|
|
],
|
|
|
|
} as SubFeaturePrivilegeGroupConfig,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'sub-feature-2',
|
|
|
|
privilegeGroups: [
|
|
|
|
{
|
|
|
|
name: 'Group Name',
|
|
|
|
groupType: 'independent',
|
|
|
|
privileges: [
|
|
|
|
createKibanaSubFeaturePrivilege('privilege-5', [
|
|
|
|
'capability9',
|
|
|
|
'capability10',
|
|
|
|
]),
|
|
|
|
],
|
|
|
|
} as SubFeaturePrivilegeGroupConfig,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
)
|
2019-09-09 19:15:58 +02:00
|
|
|
).toEqual({
|
|
|
|
catalogue: {},
|
2020-09-14 15:30:47 +02:00
|
|
|
management: {},
|
2019-09-09 19:15:58 +02:00
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
capability5: true,
|
2020-03-24 16:12:49 +01:00
|
|
|
capability6: true,
|
|
|
|
capability7: true,
|
|
|
|
capability8: true,
|
|
|
|
capability9: true,
|
|
|
|
capability10: true,
|
2019-09-09 19:15:58 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-14 15:30:47 +02:00
|
|
|
it('supports merging multiple kibana features with multiple privileges each', () => {
|
2019-09-09 19:15:58 +02:00
|
|
|
expect(
|
2020-09-14 15:30:47 +02:00
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
name: 'my new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
read: createKibanaFeaturePrivilege(['capability3', 'capability4']),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'anotherNewFeature',
|
|
|
|
name: 'another new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
read: createKibanaFeaturePrivilege(['capability3', 'capability4']),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
new KibanaFeature({
|
|
|
|
id: 'yetAnotherNewFeature',
|
|
|
|
name: 'yet another new feature',
|
|
|
|
app: ['bar-app'],
|
2020-09-18 18:30:59 +02:00
|
|
|
category: { id: 'foo', label: 'foo' },
|
2020-09-14 15:30:47 +02:00
|
|
|
privileges: {
|
|
|
|
all: createKibanaFeaturePrivilege(['capability1', 'capability2']),
|
|
|
|
read: createKibanaFeaturePrivilege(['something1', 'something2', 'something3']),
|
2020-03-24 16:12:49 +01:00
|
|
|
},
|
2020-09-14 15:30:47 +02:00
|
|
|
subFeatures: [
|
|
|
|
{
|
|
|
|
name: 'sub-feature-1',
|
|
|
|
privilegeGroups: [
|
|
|
|
{
|
|
|
|
groupType: 'independent',
|
|
|
|
privileges: [
|
|
|
|
createKibanaSubFeaturePrivilege('privilege-1', ['capability3']),
|
|
|
|
createKibanaSubFeaturePrivilege('privilege-2', ['capability4']),
|
|
|
|
],
|
|
|
|
} as SubFeaturePrivilegeGroupConfig,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
).toEqual({
|
|
|
|
anotherNewFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
},
|
|
|
|
catalogue: {},
|
|
|
|
management: {},
|
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
},
|
|
|
|
yetAnotherNewFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
something1: true,
|
|
|
|
something2: true,
|
|
|
|
something3: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('supports merging multiple elasticsearch features with multiple privileges each', () => {
|
|
|
|
expect(
|
|
|
|
uiCapabilitiesForFeatures(
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
new ElasticsearchFeature({
|
|
|
|
id: 'newFeature',
|
|
|
|
|
|
|
|
privileges: [
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability1', 'capability2'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability3', 'capability4'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new ElasticsearchFeature({
|
|
|
|
id: 'anotherNewFeature',
|
|
|
|
|
|
|
|
privileges: [
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability1', 'capability2'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability3', 'capability4'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new ElasticsearchFeature({
|
|
|
|
id: 'yetAnotherNewFeature',
|
|
|
|
|
|
|
|
privileges: [
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['capability1', 'capability2', 'capability3', 'capability4'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
requiredClusterPrivileges: [],
|
|
|
|
ui: ['something1', 'something2', 'something3'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
)
|
2019-09-09 19:15:58 +02:00
|
|
|
).toEqual({
|
|
|
|
anotherNewFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
},
|
|
|
|
catalogue: {},
|
2020-09-14 15:30:47 +02:00
|
|
|
management: {},
|
2019-09-09 19:15:58 +02:00
|
|
|
newFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
|
|
|
},
|
|
|
|
yetAnotherNewFeature: {
|
|
|
|
capability1: true,
|
|
|
|
capability2: true,
|
2020-03-24 16:12:49 +01:00
|
|
|
capability3: true,
|
|
|
|
capability4: true,
|
2019-09-09 19:15:58 +02:00
|
|
|
something1: true,
|
|
|
|
something2: true,
|
|
|
|
something3: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|