Skip to content

Commit 145f174

Browse files
Adding basic feature test
1 parent 34e8c96 commit 145f174

5 files changed

Lines changed: 200 additions & 33 deletions

File tree

x-pack/test/api_integration_basic/apis/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
1313

1414
loadTestFile(require.resolve('./ml'));
1515
loadTestFile(require.resolve('./transform'));
16+
loadTestFile(require.resolve('./security_solution'));
1617
});
1718
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import expect from '@kbn/expect';
9+
10+
import { FtrProviderContext } from '../../ftr_provider_context';
11+
import {
12+
createUsersAndRoles,
13+
deleteUsersAndRoles,
14+
} from '../../../case_api_integration/common/lib/authentication';
15+
16+
import { Role, User } from '../../../case_api_integration/common/lib/authentication/types';
17+
import {
18+
createCase,
19+
deleteAllCaseItems,
20+
getCase,
21+
} from '../../../case_api_integration/common/lib/utils';
22+
import { getPostCaseRequest } from '../../../case_api_integration/common/lib/mock';
23+
import { APP_ID } from '../../../../plugins/security_solution/common/constants';
24+
25+
const secAll: Role = {
26+
name: 'sec_all_role',
27+
privileges: {
28+
elasticsearch: {
29+
indices: [
30+
{
31+
names: ['*'],
32+
privileges: ['all'],
33+
},
34+
],
35+
},
36+
kibana: [
37+
{
38+
feature: {
39+
siem: ['all'],
40+
actions: ['all'],
41+
actionsSimulators: ['all'],
42+
},
43+
spaces: ['*'],
44+
},
45+
],
46+
},
47+
};
48+
49+
const secAllUser: User = {
50+
username: 'sec_all_user',
51+
password: 'password',
52+
roles: [secAll.name],
53+
};
54+
55+
const secRead: Role = {
56+
name: 'sec_read_role',
57+
privileges: {
58+
elasticsearch: {
59+
indices: [
60+
{
61+
names: ['*'],
62+
privileges: ['all'],
63+
},
64+
],
65+
},
66+
kibana: [
67+
{
68+
feature: {
69+
siem: ['read'],
70+
actions: ['all'],
71+
actionsSimulators: ['all'],
72+
},
73+
spaces: ['*'],
74+
},
75+
],
76+
},
77+
};
78+
79+
const secReadUser: User = {
80+
username: 'sec_read_user',
81+
password: 'password',
82+
roles: [secRead.name],
83+
};
84+
85+
const secNone: Role = {
86+
name: 'sec_none_role',
87+
privileges: {
88+
elasticsearch: {
89+
indices: [
90+
{
91+
names: ['*'],
92+
privileges: ['all'],
93+
},
94+
],
95+
},
96+
kibana: [
97+
{
98+
feature: {
99+
actions: ['all'],
100+
actionsSimulators: ['all'],
101+
},
102+
spaces: ['*'],
103+
},
104+
],
105+
},
106+
};
107+
108+
const secNoneUser: User = {
109+
username: 'sec_none_user',
110+
password: 'password',
111+
roles: [secNone.name],
112+
};
113+
114+
const roles = [secAll, secRead, secNone];
115+
116+
const users = [secAllUser, secReadUser, secNoneUser];
117+
118+
export default ({ getService }: FtrProviderContext): void => {
119+
describe('cases feature privilege', () => {
120+
const es = getService('es');
121+
const supertestWithoutAuth = getService('supertestWithoutAuth');
122+
const supertest = getService('supertest');
123+
124+
before(async () => {
125+
await createUsersAndRoles(getService, users, roles);
126+
});
127+
128+
after(async () => {
129+
await deleteUsersAndRoles(getService, users, roles);
130+
});
131+
132+
afterEach(async () => {
133+
await deleteAllCaseItems(es);
134+
});
135+
136+
it(`User ${
137+
secAllUser.username
138+
} with role(s) ${secAllUser.roles.join()} can create a case`, async () => {
139+
await createCase(supertestWithoutAuth, getPostCaseRequest({ owner: APP_ID }), 200, {
140+
user: secAllUser,
141+
space: null,
142+
});
143+
});
144+
145+
it(`User ${
146+
secReadUser.username
147+
} with role(s) ${secReadUser.roles.join()} can get a case`, async () => {
148+
const caseInfo = await createCase(supertest, getPostCaseRequest({ owner: APP_ID }));
149+
const retrievedCase = await getCase({
150+
supertest: supertestWithoutAuth,
151+
caseId: caseInfo.id,
152+
expectedHttpCode: 200,
153+
auth: { user: secReadUser, space: null },
154+
});
155+
156+
expect(caseInfo.owner).to.eql(retrievedCase.owner);
157+
});
158+
159+
for (const user of [secReadUser, secNoneUser]) {
160+
it(`User ${
161+
user.username
162+
} with role(s) ${user.roles.join()} cannot create a case`, async () => {
163+
await createCase(supertestWithoutAuth, getPostCaseRequest({ owner: APP_ID }), 403, {
164+
user,
165+
space: null,
166+
});
167+
});
168+
}
169+
170+
it(`User ${
171+
secNoneUser.username
172+
} with role(s) ${secNoneUser.roles.join()} cannot get a case`, async () => {
173+
const caseInfo = await createCase(supertest, getPostCaseRequest({ owner: APP_ID }));
174+
175+
await getCase({
176+
supertest: supertestWithoutAuth,
177+
caseId: caseInfo.id,
178+
expectedHttpCode: 403,
179+
auth: { user: secNoneUser, space: null },
180+
});
181+
});
182+
});
183+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { FtrProviderContext } from '../../ftr_provider_context';
9+
10+
export default function ({ loadTestFile }: FtrProviderContext) {
11+
describe('SecuritySolution Endpoints basic licsense', () => {
12+
loadTestFile(require.resolve('./cases_privileges'));
13+
});
14+
}

x-pack/test/case_api_integration/security_only/tests/common/comments/delete_comment.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export default ({ getService }: FtrProviderContext): void => {
135135
secOnlyReadSpacesAll,
136136
obsOnlyReadSpacesAll,
137137
obsSecReadSpacesAll,
138+
noKibanaPrivileges,
138139
]) {
139140
it(`User ${
140141
user.username
@@ -170,38 +171,6 @@ export default ({ getService }: FtrProviderContext): void => {
170171
});
171172
}
172173

173-
it('should not delete a comment with no kibana privileges', async () => {
174-
const postedCase = await createCase(
175-
supertestWithoutAuth,
176-
getPostCaseRequest(),
177-
200,
178-
superUserNoSpaceAuth
179-
);
180-
181-
const commentResp = await createComment({
182-
supertest: supertestWithoutAuth,
183-
caseId: postedCase.id,
184-
params: postCommentUserReq,
185-
auth: superUserNoSpaceAuth,
186-
});
187-
188-
await deleteComment({
189-
supertest: supertestWithoutAuth,
190-
caseId: postedCase.id,
191-
commentId: commentResp.comments![0].id,
192-
auth: { user: noKibanaPrivileges, space: null },
193-
expectedHttpCode: 403,
194-
});
195-
196-
await deleteAllComments({
197-
supertest: supertestWithoutAuth,
198-
caseId: postedCase.id,
199-
auth: { user: noKibanaPrivileges, space: null },
200-
// the find in the delete all will return no results
201-
expectedHttpCode: 404,
202-
});
203-
});
204-
205174
it('should return a 404 when attempting to access a space', async () => {
206175
const postedCase = await createCase(
207176
supertestWithoutAuth,

x-pack/test/case_api_integration/security_only/tests/trial/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { createUsersAndRoles, deleteUsersAndRoles } from '../../../common/lib/au
1212

1313
// eslint-disable-next-line import/no-default-export
1414
export default ({ loadTestFile, getService }: FtrProviderContext): void => {
15-
describe('cases security and spaces enabled: trial', function () {
15+
describe('cases security only enabled: trial', function () {
1616
// Fastest ciGroup for the moment.
1717
this.tags('ciGroup5');
1818

0 commit comments

Comments
 (0)