Skip to content

Commit 02fcbaa

Browse files
Fixed bug where list index privileges was returned twice instead of list item index (#75256)
## Summary Fixes a bug where the list privileges was returning the `.list` privileges twice instead of returning it once and returning the `.items` privileges second with the call. No UI has to change as the way it was written was dynamic to grab the first key found. This also adds the functional tests to `x-pack/scripts/functional_tests.js` which was not there originally so the end to tend tests should actually run on the CI machine where it was not running on CI before. Adds the functional tests to the code owners file as well. Ensure that you go to the test results page from the Jenkins build: <img width="901" alt="Screen Shot 2020-08-18 at 1 13 18 AM" src="https://user-images.githubusercontent.com/1151048/90482180-13f7c800-e0f0-11ea-92f2-b30a8fffe84e.png"> And ensure you see the tests under: ``` X-Pack Lists Integration Tests ``` Then click through it and ensure they are shown as running and passing ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 7ac929b commit 02fcbaa

File tree

6 files changed

+270
-1
lines changed

6 files changed

+270
-1
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib
267267
/x-pack/plugins/security_solution/ @elastic/siem @elastic/endpoint-app-team
268268
/x-pack/plugins/security_solution/**/*.scss @elastic/security-design
269269
/x-pack/test/detection_engine_api_integration @elastic/siem @elastic/endpoint-app-team
270+
/x-pack/test/lists_api_integration @elastic/siem @elastic/endpoint-app-team
270271
/x-pack/test/api_integration/apis/security_solution @elastic/siem @elastic/endpoint-app-team
271272
/x-pack/plugins/case @elastic/siem @elastic/endpoint-app-team
272273
/x-pack/plugins/lists @elastic/siem @elastic/endpoint-app-team
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
interface Cluster {
8+
monitor_ml: boolean;
9+
manage_ccr: boolean;
10+
manage_index_templates: boolean;
11+
monitor_watcher: boolean;
12+
monitor_transform: boolean;
13+
read_ilm: boolean;
14+
manage_security: boolean;
15+
manage_own_api_key: boolean;
16+
manage_saml: boolean;
17+
all: boolean;
18+
manage_ilm: boolean;
19+
manage_ingest_pipelines: boolean;
20+
read_ccr: boolean;
21+
manage_rollup: boolean;
22+
monitor: boolean;
23+
manage_watcher: boolean;
24+
manage: boolean;
25+
manage_transform: boolean;
26+
manage_api_key: boolean;
27+
manage_token: boolean;
28+
manage_ml: boolean;
29+
manage_pipeline: boolean;
30+
monitor_rollup: boolean;
31+
transport_client: boolean;
32+
create_snapshot: boolean;
33+
}
34+
35+
interface Index {
36+
[indexName: string]: {
37+
all: boolean;
38+
manage_ilm: boolean;
39+
read: boolean;
40+
create_index: boolean;
41+
read_cross_cluster: boolean;
42+
index: boolean;
43+
monitor: boolean;
44+
delete: boolean;
45+
manage: boolean;
46+
delete_index: boolean;
47+
create_doc: boolean;
48+
view_index_metadata: boolean;
49+
create: boolean;
50+
manage_follow_index: boolean;
51+
manage_leader_index: boolean;
52+
write: boolean;
53+
};
54+
}
55+
56+
interface IndexPrivilege {
57+
application: {};
58+
cluster: Cluster;
59+
has_all_requested: boolean;
60+
index: Index;
61+
username: string;
62+
}
63+
64+
export interface Privilege {
65+
listItems: IndexPrivilege;
66+
lists: IndexPrivilege;
67+
is_authenticated: boolean;
68+
}
69+
70+
export const getReadPrivilegeMock = (
71+
listIndex: string = '.lists-default',
72+
listItemsIndex: string = '.items-default',
73+
username = 'elastic',
74+
booleanValues: boolean = true
75+
): Privilege => ({
76+
is_authenticated: true,
77+
listItems: {
78+
application: {},
79+
cluster: {
80+
all: booleanValues,
81+
create_snapshot: booleanValues,
82+
manage: booleanValues,
83+
manage_api_key: booleanValues,
84+
manage_ccr: booleanValues,
85+
manage_ilm: booleanValues,
86+
manage_index_templates: booleanValues,
87+
manage_ingest_pipelines: booleanValues,
88+
manage_ml: booleanValues,
89+
manage_own_api_key: false,
90+
manage_pipeline: booleanValues,
91+
manage_rollup: booleanValues,
92+
manage_saml: booleanValues,
93+
manage_security: booleanValues,
94+
manage_token: booleanValues,
95+
manage_transform: booleanValues,
96+
manage_watcher: booleanValues,
97+
monitor: booleanValues,
98+
monitor_ml: booleanValues,
99+
monitor_rollup: booleanValues,
100+
monitor_transform: booleanValues,
101+
monitor_watcher: booleanValues,
102+
read_ccr: booleanValues,
103+
read_ilm: booleanValues,
104+
transport_client: booleanValues,
105+
},
106+
has_all_requested: false,
107+
index: {
108+
[listItemsIndex]: {
109+
all: booleanValues,
110+
create: booleanValues,
111+
create_doc: booleanValues,
112+
create_index: booleanValues,
113+
delete: booleanValues,
114+
delete_index: booleanValues,
115+
index: booleanValues,
116+
manage: booleanValues,
117+
manage_follow_index: booleanValues,
118+
manage_ilm: booleanValues,
119+
manage_leader_index: booleanValues,
120+
monitor: booleanValues,
121+
read: booleanValues,
122+
read_cross_cluster: booleanValues,
123+
view_index_metadata: booleanValues,
124+
write: booleanValues,
125+
},
126+
},
127+
username,
128+
},
129+
lists: {
130+
application: {},
131+
cluster: {
132+
all: booleanValues,
133+
create_snapshot: booleanValues,
134+
manage: booleanValues,
135+
manage_api_key: booleanValues,
136+
manage_ccr: booleanValues,
137+
manage_ilm: booleanValues,
138+
manage_index_templates: booleanValues,
139+
manage_ingest_pipelines: booleanValues,
140+
manage_ml: booleanValues,
141+
manage_own_api_key: false,
142+
manage_pipeline: booleanValues,
143+
manage_rollup: booleanValues,
144+
manage_saml: booleanValues,
145+
manage_security: booleanValues,
146+
manage_token: booleanValues,
147+
manage_transform: booleanValues,
148+
manage_watcher: booleanValues,
149+
monitor: booleanValues,
150+
monitor_ml: booleanValues,
151+
monitor_rollup: booleanValues,
152+
monitor_transform: booleanValues,
153+
monitor_watcher: booleanValues,
154+
read_ccr: booleanValues,
155+
read_ilm: booleanValues,
156+
transport_client: booleanValues,
157+
},
158+
has_all_requested: false,
159+
index: {
160+
[listIndex]: {
161+
all: booleanValues,
162+
create: booleanValues,
163+
create_doc: booleanValues,
164+
create_index: booleanValues,
165+
delete: booleanValues,
166+
delete_index: booleanValues,
167+
index: booleanValues,
168+
manage: booleanValues,
169+
manage_follow_index: booleanValues,
170+
manage_ilm: booleanValues,
171+
manage_leader_index: booleanValues,
172+
monitor: booleanValues,
173+
read: booleanValues,
174+
read_cross_cluster: booleanValues,
175+
view_index_metadata: booleanValues,
176+
write: booleanValues,
177+
},
178+
},
179+
username,
180+
},
181+
});

x-pack/plugins/lists/server/routes/read_privileges_route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const readPrivilegesRoute = (
3636
);
3737
const clusterPrivilegesListItems = await readPrivileges(
3838
clusterClient.callAsCurrentUser,
39-
lists.getListIndex()
39+
lists.getListItemIndex()
4040
);
4141
const privileges = merge(
4242
{

x-pack/scripts/functional_tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const onlyNotInCoverageTests = [
2626
require.resolve('../test/apm_api_integration/trial/config.ts'),
2727
require.resolve('../test/detection_engine_api_integration/security_and_spaces/config.ts'),
2828
require.resolve('../test/detection_engine_api_integration/basic/config.ts'),
29+
require.resolve('../test/lists_api_integration/security_and_spaces/config.ts'),
2930
require.resolve('../test/plugin_api_integration/config.ts'),
3031
require.resolve('../test/kerberos_api_integration/config.ts'),
3132
require.resolve('../test/kerberos_api_integration/anonymous_access.config.ts'),

x-pack/test/lists_api_integration/security_and_spaces/tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
3333
loadTestFile(require.resolve('./delete_exception_list_items'));
3434
loadTestFile(require.resolve('./find_exception_lists'));
3535
loadTestFile(require.resolve('./find_exception_list_items'));
36+
loadTestFile(require.resolve('./read_list_privileges'));
3637
});
3738
};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import expect from '@kbn/expect';
8+
9+
import { getReadPrivilegeMock } from '../../../../plugins/lists/server/routes/read_privileges_route.mock';
10+
import { FtrProviderContext } from '../../common/ftr_provider_context';
11+
import { LIST_PRIVILEGES_URL } from '../../../../plugins/lists/common/constants';
12+
13+
// eslint-disable-next-line import/no-default-export
14+
export default ({ getService }: FtrProviderContext) => {
15+
const supertest = getService('supertest');
16+
const security = getService('security');
17+
const spacesService = getService('spaces');
18+
const supertestWithoutAuth = getService('supertestWithoutAuth');
19+
20+
describe('read_list_privileges', () => {
21+
const space1Id = 'space_1';
22+
23+
const user1 = {
24+
username: 'user_1',
25+
roleName: 'user_1',
26+
password: 'user_1-password',
27+
};
28+
29+
beforeEach(async () => {
30+
await spacesService.create({
31+
id: space1Id,
32+
name: space1Id,
33+
disabledFeatures: [],
34+
});
35+
36+
await security.role.create(user1.roleName, {
37+
kibana: [
38+
{
39+
feature: {
40+
dashboard: ['all'],
41+
siem: ['all', 'read'],
42+
},
43+
spaces: [space1Id],
44+
},
45+
],
46+
});
47+
48+
await security.user.create(user1.username, {
49+
password: user1.password,
50+
roles: [user1.roleName],
51+
});
52+
});
53+
54+
afterEach(async () => {
55+
await spacesService.delete(space1Id);
56+
});
57+
58+
it('should return true for all privileges when its the system user of "elastic" in space of "default"', async () => {
59+
const { body } = await supertest.get(LIST_PRIVILEGES_URL).set('kbn-xsrf', 'true').expect(200);
60+
expect(body).to.eql(getReadPrivilegeMock());
61+
});
62+
63+
it('should return true for all privileges when its the system user of "elastic" in space of "space_1"', async () => {
64+
const { body } = await supertest.get(LIST_PRIVILEGES_URL).set('kbn-xsrf', 'true').expect(200);
65+
expect(body).to.eql(getReadPrivilegeMock());
66+
});
67+
68+
it('should return false for all privileges when its the system user of "user_1" in a space of "space_1"', async () => {
69+
const { body } = await supertestWithoutAuth
70+
.get(`/s/${space1Id}${LIST_PRIVILEGES_URL}`)
71+
.auth(user1.username, user1.password)
72+
.send()
73+
.expect(200);
74+
75+
const privilege = getReadPrivilegeMock(
76+
`.lists-${space1Id}`,
77+
`.items-${space1Id}`,
78+
user1.username,
79+
false
80+
);
81+
82+
expect(body).to.eql(privilege);
83+
});
84+
});
85+
};

0 commit comments

Comments
 (0)