-
Notifications
You must be signed in to change notification settings - Fork 8.6k
initial @kbn/scout-security plugin #210433
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
Merged
Changes from all commits
Commits
Show all changes
87 commits
Select commit
Hold shift + click to select a range
f9b828a
initial @kbn/scout-security plugin
MadameSheema 15d4e62
preparing the structure for the first security solution scout test - WIP
MadameSheema 5840b7f
Merge branch 'main' into scout/security
MadameSheema 68d6621
Merge branch 'main' into scout/security
MadameSheema 32c4559
experimenting and playing
MadameSheema c877e1d
Merge branch 'main' into scout/security
MadameSheema 851bd42
adds missing file deleted by mistake
MadameSheema dd02310
adds global setup to add auditbeat data
MadameSheema fc06785
refactor
MadameSheema ef8176c
Merge branch 'main' into scout/security
MadameSheema 749ad2a
Merge branch 'main' into scout/security
MadameSheema e6b290c
adds detection rule fixture
MadameSheema 33a6655
detection engine fixture refactor
MadameSheema 287a90b
wip adds functional test
MadameSheema 98e3fc5
expands test
MadameSheema cbd26cb
Merge branch 'main' into scout/security
MadameSheema 33675c7
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine 39eba55
fixes circular graph issue
MadameSheema 472b697
Merge branch 'main' into scout/security
MadameSheema a52bbe2
Merge branch 'main' into scout/security
MadameSheema 112369d
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 6dd4e72
Merge branch 'main' into scout/security
MadameSheema 06f3205
tsconfig adjustment
MadameSheema e5eaefc
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine ea726e4
adjustments
MadameSheema e2d1b87
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine f297942
removes circular reference
MadameSheema 21bf861
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine 49f51aa
final fix on circular issue
MadameSheema a0d6392
updates on jestconfig
MadameSheema d21bb4f
fixtures refactor
MadameSheema 9a4daef
test data refactor
MadameSheema 943da12
provides the test the capabilities to be executed in ess as well
MadameSheema 84d9a6f
adds scout security file pattern to ESLint configuration
MadameSheema 68b1c5e
removes nth
MadameSheema 84a272c
removes unnecessary wait
MadameSheema bbe9738
Merge branch 'main' into scout/security
MadameSheema 4e09e37
Merge branch 'main' into scout/security
MadameSheema d2d6d3f
wraps API calls with measurePerformanceAsync method
MadameSheema b6471f4
alerts table page object refactor
MadameSheema 4d0503f
Merge branch 'main' into scout/security
MadameSheema 4c4d2f1
pageObjects usage refactor
MadameSheema aaec8a4
wip-readme
MadameSheema e636e09
Merge branch 'main' into scout/security
MadameSheema 52bbcd9
global setup hook + parallel execution
MadameSheema 483ac94
fixes global.setup file
MadameSheema a2439a8
using spaceTest
MadameSheema 94af6b8
detection rule refactor
MadameSheema a06d32e
completes initial README
MadameSheema bb38752
adds test to CI
MadameSheema 8c070b7
refactor
MadameSheema 581a8ed
refactor to remove waitForSelector linting issue
MadameSheema e9e68f7
changes codeowners
MadameSheema d9f3642
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine 3f7bfb4
Merge branch 'main' into scout/security
MadameSheema 6aacb5a
Merge branch 'main' into scout/security
MadameSheema b7d0953
updates ownership
MadameSheema 5a67e45
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine 709b96d
Merge branch 'main' into scout/security
MadameSheema be45f8c
Merge branch 'main' into scout/security
MadameSheema 41a1487
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine a2c04dd
moves tests to parallel folder
MadameSheema 8b12d9b
addresses apiServices nit comments
MadameSheema 138369f
fix apiServices extension
dmlemeshko 8583101
implements setCustomRole to create the platform_engineer role when th…
MadameSheema f36032b
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine 0b0f888
extend browserAuth
dmlemeshko 2fd63a1
Merge branch 'scout/security' of github.com:MadameSheema/kibana into …
dmlemeshko d4370be
improve imports/fixture
dmlemeshko 63f5b81
updates comment
MadameSheema 9704af6
fixes typo
MadameSheema 2e7303a
adds missing dependency in the pipeline file
MadameSheema 63b5965
please comments
MadameSheema 23693ec
Merge branch 'main' into scout/security
MadameSheema 38dd820
please comments
MadameSheema b07f668
Merge branch 'main' into scout/security
MadameSheema 5533da3
[CI] Auto-commit changed files from 'node scripts/telemetry_check'
kibanamachine 1109ff5
updates readme
MadameSheema 681c6be
adds security solution to scout ci config
MadameSheema dc72565
Merge branch 'main' into scout/security
MadameSheema 8b70edb
enables security solution plugin in scout ci config
MadameSheema d06164e
Update scout_ci_config.yml
dmlemeshko 6094f3e
fix imports/export, update tsconfig
dmlemeshko 2b15ef1
Merge branch 'main' into scout/security
dmlemeshko de8801e
Merge branch 'scout/security' of github.com:MadameSheema/kibana into …
dmlemeshko de6a7ba
Merge branch 'main' into scout/security
MadameSheema e7a587f
Merge branch 'main' into scout/security
dmlemeshko 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ ui_tests: | |
| - discover_enhanced | ||
| - maps | ||
| - observability_onboarding | ||
| - security_solution | ||
| disabled: | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,5 +127,4 @@ system_indices_superuser: | |
| - application: '*' | ||
| privileges: ['*'] | ||
| resources: ['*'] | ||
| run_as: ['*'] | ||
|
|
||
| run_as: ['*'] | ||
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
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
201 changes: 201 additions & 0 deletions
201
x-pack/solutions/security/packages/kbn-scout-security/README.md
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,201 @@ | ||
| # ⚠️ @kbn/scout-security IS NOT PRODUCTION READY, SO PLEASE DON'T USE YET | ||
|
|
||
| `kbn/scout-security` is a test library that extends [`kbn/scout`](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-scout/README.md) with test helpers specifically designed for `Security Solution` features in Kibana. | ||
|
|
||
| Its primary goal is to simplify the test development experience for teams working on `Security Solution` plugins by providing custom Playwright fixtures, page objects, and utilities tailored for Security Solution related testing scenarios. | ||
|
|
||
| ### Table of Contents | ||
| 1. Overview | ||
| 2. Folder Structure | ||
| 3. Config | ||
| 4. Fixtures | ||
| 5. Page Objects | ||
| 6. Starting Servers Onlu | ||
| 7. Running Servers and Tests | ||
| 8. Running Tests Separately | ||
| 9. Adding A New Test | ||
| 10. Adding Page Objects | ||
| 11. Adding Fixtures | ||
| 12. Best Practices | ||
|
|
||
|
|
||
| ### Overview | ||
|
|
||
| `kbn-scout-security` extends from `kbn-scout` framework providing the same advantages: | ||
|
|
||
| - **Ease of integration:** a simplified mechanism to write and run tests closer to plugins. | ||
| - **Deployment-agnostic tests:** enables the testing of Kibana features across different environments (e.g., Stateful, Serverless). | ||
| - **Fixture-based design:** built on Playwright's fixture model to modularize and standardize test setup. | ||
| - **Focus on Developer Productivity:** faster test execution and minimal boilerplate for writing tests. | ||
|
|
||
| ### Folder Structure | ||
|
|
||
| The `@kbn/scout-security` structure includes the following key directories and files: | ||
|
|
||
| ``` | ||
| x-pack/solutions/security/packages/kbn-scout-security/ | ||
| ├── src/ | ||
| │ ├── playwright/ | ||
| │ │ └── constants/ | ||
| │ │ └── fixtures/ | ||
| │ │ │ └── test/ | ||
| │ │ │ │ └── // Security Solution test-scope fixtures | ||
| | | | | └── page_objects/ | ||
| | | | | └── // Security Solution pages that can be reused through the different plugins | ||
| │ │ │ └── worker/ | ||
| │ │ │ │ └── // Security Solution worker-scope fixtures | ||
| │ │ │ └── single_thread_fixtures.ts | ||
| │ │ │ └── parallel_run_fixtures.ts | ||
| │ │ │ └── index.ts | ||
| | | | └── types.ts | ||
| │ └── index.ts | ||
| ├── README.mk | ||
| ├── index.ts | ||
| ├── jest.config.js | ||
| ├── kibana.jsonc | ||
| ├── package.json | ||
| ├── tsconfig.json | ||
| ``` | ||
|
|
||
| ### Config | ||
|
|
||
| `playwright` directory manages the default Playwright configuration. It exports the `createPlaywrightConfig` function, which is used by Kibana plugins to define Scout playwright configurations and serves as the entry point to run tests. | ||
|
|
||
| ```ts | ||
| import { createPlaywrightConfig } from '@kbn/scout'; | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export default createPlaywrightConfig({ | ||
| testDir: './tests', | ||
| workers: 2, | ||
| }); | ||
| ``` | ||
|
|
||
| Scout relies on configuration to determine the test files and opt-in [parallel test execution](https://playwright.dev/docs/test-parallel) against the single Elastic cluster. | ||
|
|
||
| The Playwright configuration should only be created this way to ensure compatibility with Scout functionality. Note that config files should be used inside the plugin we want to test. | ||
|
|
||
| ### Fixtures | ||
|
|
||
| The `fixtures` directory contains core Security Scout capabilities required for testing the majority of Security Solution functionalities. [Fixtures](https://playwright.dev/docs/test-fixtures) can be scoped to either `test` or `worker`. Scope decides when to init a new fixture instance: once per worker or for every test function. It is important to choose the correct scope to keep test execution optimally fast: if **a new instance is not needed for every test**, the fixture should be scoped to **worker**. Otherwise, it should be scoped to **test**. | ||
|
|
||
| **Security Solution `worker` scoped fixtures:** | ||
| - `detectionRuleApi` | ||
|
|
||
| ```ts | ||
| test.beforeAll(async ({ detectionRuleApi }) => { | ||
| await detectionRuleApi.createCustomQueryRule(CUSTOM_QUERY_RULE); | ||
| }); | ||
| ``` | ||
|
|
||
| **Security Solution `test` scoped fixtures:** | ||
| - `browserAuth` | ||
| - `pageObjects` | ||
|
|
||
| ```ts | ||
| test.beforeEach(async ({ browserAuth }) => { | ||
| await browserAuth.loginAsPlatformEngineer(); | ||
| }); | ||
| ``` | ||
|
|
||
| If a new fixture depends on a fixture with a `test` scope, it must also be `test` scoped. | ||
|
|
||
| ### Page Objects | ||
|
|
||
| The `page_objects` directory contains all the Page Objects that represent Security Solution core functionality that can be reused through different Security Solution plugins. | ||
|
|
||
| If a Page Object is likely to be used in more than one plugin, it should be added here. This allows other teams to reuse it, improving collaboration across teams, reducing code duplication, and simplifying support and adoption. | ||
|
|
||
| If a Page Object can be used outside Security Solution, it should be created in `@kbn-scout`. | ||
|
|
||
| Page Objects must be registered with the `createLazyPageObject` function, which guarantees its instance is lazy-initialized. This way, we can have all the page objects available in the test context, but only the ones that are called will be actually initialized: | ||
|
|
||
| ```ts | ||
| export function extendPageObjects(pageObjects: PageObjects, page: ScoutPage): SecurityPageObjects { | ||
| return { | ||
| ...pageObjects, | ||
| alertsTablePage: createLazyPageObject(AlertsTablePage, page), | ||
| alertDetailsRightPanelPage: createLazyPageObject(AlertDetailsRightPanelPage, page), | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| All registered Page Objects are available via the `pageObjects` fixture: | ||
|
|
||
| ```ts | ||
| test.beforeEach(async ({ pageObjects }) => { | ||
| await pageObjects.alertsTablePage.navigate(); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Starting Servers Only | ||
|
|
||
| To start the servers without running tests, use the following command: | ||
|
|
||
| ```bash | ||
| node scripts/scout.js start-server [--stateful|--serverless=security] | ||
| ``` | ||
|
|
||
| This is useful for manual testing or running tests via an IDE. | ||
|
|
||
| ### Running Servers and Tests | ||
|
|
||
| To start the servers and run tests, use: | ||
|
|
||
| ```bash | ||
| node scripts/scout.js run-tests [--stateful|--serverless=security] --config <plugin-path>/ui_tests/[playwright.config.ts|parallel.playwright.config.ts] | ||
| ``` | ||
|
|
||
| This command starts the required servers and then automatically executes the tests using Playwright. | ||
|
|
||
| ### Running Tests Separately | ||
|
|
||
| If the servers are already running, you can execute tests independently using either: | ||
|
|
||
| - Playwright Plugin in IDE: Run tests directly within your IDE using Playwright's integration. | ||
| - Command Line: Use the following command to run tests: | ||
|
|
||
| ```bash | ||
| npx playwright test --config <plugin-path>/ui_tests/[playwright.config.ts|parallel.playwright.config.ts] --project local | ||
| ``` | ||
|
|
||
| We use `project` flag to define test target, where tests to be run: local servers or Elastic Cloud. Currently we only support local servers. | ||
|
|
||
| ### Adding A New Test | ||
| Any new test should be added in the `x-pack/solutions/security/plugins/security_solution/ui_tests` folder. | ||
|
|
||
| You have an example in: `x-pack/solutions/security/plugins/security_solution/ui_tests/parallel_tests/flyout/alert_details_url_sync.spec.ts` | ||
|
|
||
| ### Adding Page Objects | ||
| 1. **Create a New Page Object:** Add your Page Object to the src/playwright/fixtures/test/page_objects directory. For instance: | ||
|
|
||
| ```ts | ||
| export class NewPage { | ||
| constructor(private readonly page: ScoutPage) {} | ||
|
|
||
| // implementation | ||
| } | ||
| ``` | ||
| 2. **Register the Page Object:** Update the index file to include the new Page Object: | ||
| ```ts | ||
| export function createCorePageObjects(page: ScoutPage): PageObjects { | ||
| return { | ||
| ... | ||
| newPage: createLazyPageObject(NewPage, page), | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| ### Adding Fixtures | ||
| 1. **Determine Fixture Scope:** Decide if your fixture should apply to the `test` (per-test) or `worker` (per-worker) scope. | ||
|
|
||
| 2. **Implement the Fixture:** Add the implementation to `src/playwright/fixtures/test` or `src/playwright/fixtures/worker`. | ||
|
|
||
| You can use the existing fixtures as a guide. | ||
|
|
||
| 3. **Register the Fixture:** Add the fixture to the appropriate scope in `src/playwright/fixtures/parallel_run_fixtures.ts` and/or ``src/playwright/fixtures/single_thread_fixture.ts`` | ||
|
|
||
| ### Best Practices | ||
| - **Reusable Code:** When creating Page Objects or Fixtures that apply to more than one plugin, ensure they are added to the kbn-scout package. | ||
| - **Adhere to Existing Structure:** Maintain consistency with the project's architecture. | ||
| - **Playwright documentation:** [Official best practices](https://playwright.dev/docs/best-practices) |
31 changes: 31 additions & 0 deletions
31
x-pack/solutions/security/packages/kbn-scout-security/index.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,31 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| export { test, spaceTest } from './src/playwright'; | ||
|
|
||
| // re-export from @kbn/scout | ||
| export { | ||
| expect, | ||
| tags, | ||
| createPlaywrightConfig, | ||
| createLazyPageObject, | ||
| globalSetupHook, | ||
| } from '@kbn/scout'; | ||
|
|
||
| export type { | ||
| EsClient, | ||
| KbnClient, | ||
| KibanaUrl, | ||
| ScoutLogger, | ||
| ScoutPage, | ||
| PageObjects, | ||
| ScoutServerConfig, | ||
| ScoutTestConfig, | ||
| ScoutPlaywrightOptions, | ||
| ScoutTestOptions, | ||
| Locator, | ||
| } from '@kbn/scout'; |
12 changes: 12 additions & 0 deletions
12
x-pack/solutions/security/packages/kbn-scout-security/jest.config.js
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,12 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| module.exports = { | ||
| preset: '@kbn/test/jest_node', | ||
| rootDir: '../../../../..', | ||
| roots: ['<rootDir>/x-pack/solutions/security/packages/kbn-scout-security'], | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.