-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Cases] Fixing UI feature permissions and adding UI tests #100074
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
Merged
jonathan-buttner
merged 5 commits into
elastic:cases-rbac-poc
from
jonathan-buttner:sec-sol-ui-permissions
May 14, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0e077c
Integration tests for cases privs and fixes
jonathan-buttner 1b62c14
Fixing ui cases permissions and adding tests
jonathan-buttner 094d0ee
Adding test for collection failure and fixing jest
jonathan-buttner 75d4771
Merge branch 'cases-rbac-poc' of github.com:elastic/kibana into sec-s…
jonathan-buttner 15d8c55
Renaming variables
jonathan-buttner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
234 changes: 234 additions & 0 deletions
234
x-pack/plugins/security_solution/cypress/integration/cases/privileges.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * 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. | ||
| */ | ||
|
|
||
| import { TestCaseWithoutTimeline } from '../../objects/case'; | ||
| import { ALL_CASES_NAME } from '../../screens/all_cases'; | ||
|
|
||
| import { goToCreateNewCase } from '../../tasks/all_cases'; | ||
| import { cleanKibana, deleteCases } from '../../tasks/common'; | ||
|
|
||
| import { | ||
| backToCases, | ||
| createCase, | ||
| fillCasesMandatoryfields, | ||
| filterStatusOpen, | ||
| } from '../../tasks/create_new_case'; | ||
| import { | ||
| constructUrlWithUser, | ||
| getEnvAuth, | ||
| loginWithUserAndWaitForPageWithoutDateRange, | ||
| } from '../../tasks/login'; | ||
|
|
||
| import { CASES_URL } from '../../urls/navigation'; | ||
|
|
||
| interface User { | ||
| username: string; | ||
| password: string; | ||
| description?: string; | ||
| roles: string[]; | ||
| } | ||
|
|
||
| interface UserInfo { | ||
| username: string; | ||
| full_name: string; | ||
| email: string; | ||
| } | ||
|
|
||
| interface FeaturesPrivileges { | ||
| [featureId: string]: string[]; | ||
| } | ||
|
|
||
| interface ElasticsearchIndices { | ||
| names: string[]; | ||
| privileges: string[]; | ||
| } | ||
|
|
||
| interface ElasticSearchPrivilege { | ||
| cluster?: string[]; | ||
| indices?: ElasticsearchIndices[]; | ||
| } | ||
|
|
||
| interface KibanaPrivilege { | ||
| spaces: string[]; | ||
| base?: string[]; | ||
| feature?: FeaturesPrivileges; | ||
| } | ||
|
|
||
| interface Role { | ||
| name: string; | ||
| privileges: { | ||
| elasticsearch?: ElasticSearchPrivilege; | ||
| kibana?: KibanaPrivilege[]; | ||
| }; | ||
| } | ||
|
|
||
| const secAll: Role = { | ||
| name: 'sec_all_role', | ||
| privileges: { | ||
| elasticsearch: { | ||
| indices: [ | ||
| { | ||
| names: ['*'], | ||
| privileges: ['all'], | ||
| }, | ||
| ], | ||
| }, | ||
| kibana: [ | ||
| { | ||
| feature: { | ||
| siem: ['all'], | ||
| actions: ['all'], | ||
| actionsSimulators: ['all'], | ||
| }, | ||
| spaces: ['*'], | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| const secAllUser: User = { | ||
| username: 'sec_all_user', | ||
| password: 'password', | ||
| roles: [secAll.name], | ||
| }; | ||
|
|
||
| const secReadCasesAll: Role = { | ||
| name: 'sec_read_cases_all_role', | ||
| privileges: { | ||
| elasticsearch: { | ||
| indices: [ | ||
| { | ||
| names: ['*'], | ||
| privileges: ['all'], | ||
| }, | ||
| ], | ||
| }, | ||
| kibana: [ | ||
| { | ||
| feature: { | ||
| siem: ['minimal_read', 'cases_all'], | ||
| actions: ['all'], | ||
| actionsSimulators: ['all'], | ||
| }, | ||
| spaces: ['*'], | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| const secReadCasesAllUser: User = { | ||
| username: 'sec_read_cases_all_user', | ||
| password: 'password', | ||
| roles: [secReadCasesAll.name], | ||
| }; | ||
|
|
||
| const usersToCreate = [secAllUser, secReadCasesAllUser]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const rolesToCreate = [secAll, secReadCasesAll]; | ||
|
|
||
| const getUserInfo = (user: User): UserInfo => ({ | ||
| username: user.username, | ||
| full_name: user.username.replace('_', ' '), | ||
| email: `${user.username}@elastic.co`, | ||
| }); | ||
|
|
||
| const createUsersAndRoles = (users: User[], roles: Role[]) => { | ||
| const envUser = getEnvAuth(); | ||
| for (const role of roles) { | ||
| cy.log(`Creating role: ${JSON.stringify(role)}`); | ||
| cy.request({ | ||
| body: role.privileges, | ||
| headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, | ||
| method: 'PUT', | ||
| url: constructUrlWithUser(envUser, `/api/security/role/${role.name}`), | ||
| }) | ||
| .its('status') | ||
| .should('eql', 204); | ||
| } | ||
|
|
||
| for (const user of users) { | ||
| const userInfo = getUserInfo(user); | ||
| cy.log(`Creating user: ${JSON.stringify(user)}`); | ||
| cy.request({ | ||
| body: { | ||
| username: user.username, | ||
| password: user.password, | ||
| roles: user.roles, | ||
| full_name: userInfo.full_name, | ||
| email: userInfo.email, | ||
| }, | ||
| headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, | ||
| method: 'POST', | ||
| url: constructUrlWithUser(envUser, `/internal/security/users/${user.username}`), | ||
| }) | ||
| .its('status') | ||
| .should('eql', 200); | ||
| } | ||
| }; | ||
|
|
||
| const deleteUsersAndRoles = (users: User[], roles: Role[]) => { | ||
| const envUser = getEnvAuth(); | ||
| for (const user of users) { | ||
| cy.log(`Deleting user: ${JSON.stringify(user)}`); | ||
| cy.request({ | ||
| headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, | ||
| method: 'DELETE', | ||
| url: constructUrlWithUser(envUser, `/internal/security/users/${user.username}`), | ||
| failOnStatusCode: false, | ||
| }) | ||
| .its('status') | ||
| .should('oneOf', [204, 404]); | ||
| } | ||
|
|
||
| for (const role of roles) { | ||
| cy.log(`Deleting role: ${JSON.stringify(role)}`); | ||
| cy.request({ | ||
| headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, | ||
| method: 'DELETE', | ||
| url: constructUrlWithUser(envUser, `/api/security/role/${role.name}`), | ||
| failOnStatusCode: false, | ||
| }) | ||
| .its('status') | ||
| .should('oneOf', [204, 404]); | ||
| } | ||
| }; | ||
|
|
||
| const testCase: TestCaseWithoutTimeline = { | ||
| name: 'This is the title of the case', | ||
| tags: ['Tag1', 'Tag2'], | ||
| description: 'This is the case description', | ||
| reporter: 'elastic', | ||
| owner: 'securitySolution', | ||
| }; | ||
|
|
||
| describe('Cases privileges', () => { | ||
| before(() => { | ||
| cleanKibana(); | ||
| createUsersAndRoles(usersToCreate, rolesToCreate); | ||
| }); | ||
|
|
||
| after(() => { | ||
| deleteUsersAndRoles(usersToCreate, rolesToCreate); | ||
| cleanKibana(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| deleteCases(); | ||
| }); | ||
|
|
||
| for (const user of [secAllUser, secReadCasesAllUser]) { | ||
| it(`User ${user.username} with role(s) ${user.roles.join()} can create a case`, () => { | ||
| loginWithUserAndWaitForPageWithoutDateRange(CASES_URL, user); | ||
| goToCreateNewCase(); | ||
| fillCasesMandatoryfields(testCase); | ||
| createCase(); | ||
| backToCases(); | ||
| filterStatusOpen(); | ||
|
|
||
| cy.get(ALL_CASES_NAME).should('have.text', testCase.name); | ||
| }); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is unused and shouldn't live in the cases plugin since each individual plugin that leverages cases will need to manage it's permissions separately.