From dd4708414a67a28c9bc81c1a1b6ba37837efa0f1 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Tue, 19 Sep 2023 19:15:53 +0200 Subject: [PATCH] Upgrading cypress to 12.17.4 (#165869) Co-authored-by: Yuliia Naumenko Co-authored-by: Thomas Watson Co-authored-by: Kyle Pollich Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../pipelines/pull_request/fleet_cypress.yml | 3 +- .../scripts/steps/functional/fleet_cypress.sh | 12 +- .../steps/functional/profiling_cypress.sh | 2 +- package.json | 2 +- test/scripts/jenkins_fleet_cypress.sh | 6 +- x-pack/plugins/apm/scripts/test/e2e.js | 6 +- x-pack/plugins/fleet/cypress.config.ts | 18 ++- x-pack/plugins/fleet/cypress/README.md | 21 +--- .../fleet/cypress/e2e/a11y/home_page.cy.ts | 11 +- .../e2e/agent_binary_download_source.cy.ts | 14 ++- .../fleet/cypress/e2e/agent_policy.cy.ts | 6 +- .../fleet/cypress/e2e/agents/agent_list.cy.ts | 11 +- .../fleet/cypress/e2e/enrollment_token.cy.ts | 8 +- .../cypress/e2e/fleet_agent_flyout.cy.ts | 6 +- .../fleet/cypress/e2e/fleet_settings.cy.ts | 6 +- .../fleet/cypress/e2e/fleet_startup.cy.ts | 24 ++-- .../fleet/cypress/e2e/install_assets.cy.ts | 3 + .../fleet/cypress/e2e/integrations_mock.cy.ts | 8 +- .../fleet/cypress/e2e/integrations_real.cy.ts | 45 +++---- .../fleet/cypress/e2e/package_policy.cy.ts | 5 +- ...e_policy_pipelines_and_mappings_real.cy.ts | 57 +++++---- .../cypress/e2e/privileges_editor_role.cy.ts | 6 +- ...ivileges_fleet_all_integrations_none.cy.ts | 6 +- ...ivileges_fleet_all_integrations_read.cy.ts | 3 +- .../cypress/e2e/privileges_viewer_role.cy.ts | 6 +- .../fleet/cypress/e2e/uninstall_token.cy.ts | 6 +- x-pack/plugins/fleet/cypress/plugins/index.ts | 1 + .../fleet/cypress/screens/fleet_outputs.ts | 8 +- x-pack/plugins/fleet/cypress/support/e2e.ts | 3 +- x-pack/plugins/fleet/cypress/tasks/cleanup.ts | 34 +++--- x-pack/plugins/fleet/cypress/tasks/common.ts | 26 ++++ .../fleet/cypress/tasks/fleet_server.ts | 9 +- .../fleet/cypress/tasks/integrations.ts | 43 ++++--- x-pack/plugins/fleet/cypress/tasks/login.ts | 15 +-- .../plugins/fleet/cypress/tasks/privileges.ts | 9 +- .../fleet/cypress/tasks/ui_settings.ts | 4 +- x-pack/plugins/fleet/cypress/tsconfig.json | 1 - x-pack/plugins/fleet/package.json | 10 +- .../scripts/test/e2e.js | 6 +- x-pack/plugins/osquery/package.json | 4 +- x-pack/plugins/security_solution/package.json | 6 +- .../plugins/threat_intelligence/package.json | 4 +- x-pack/test/fleet_cypress/config.ts | 1 + x-pack/test/fleet_cypress/runner.ts | 114 ++++-------------- .../security_solution_cypress/package.json | 8 +- .../observability/cypress/package.json | 8 +- .../test_suites/security/cypress/package.json | 6 +- yarn.lock | 19 +-- 48 files changed, 326 insertions(+), 314 deletions(-) diff --git a/.buildkite/pipelines/pull_request/fleet_cypress.yml b/.buildkite/pipelines/pull_request/fleet_cypress.yml index fab4f90c5bfe..fcccdfe7a679 100644 --- a/.buildkite/pipelines/pull_request/fleet_cypress.yml +++ b/.buildkite/pipelines/pull_request/fleet_cypress.yml @@ -4,7 +4,8 @@ steps: agents: queue: n2-4-spot depends_on: build - timeout_in_minutes: 120 + timeout_in_minutes: 50 + parallelism: 6 retry: automatic: - exit_status: '-1' diff --git a/.buildkite/scripts/steps/functional/fleet_cypress.sh b/.buildkite/scripts/steps/functional/fleet_cypress.sh index a77d912a59ff..d6554b7198b8 100755 --- a/.buildkite/scripts/steps/functional/fleet_cypress.sh +++ b/.buildkite/scripts/steps/functional/fleet_cypress.sh @@ -3,12 +3,14 @@ set -euo pipefail source .buildkite/scripts/steps/functional/common.sh +source .buildkite/scripts/steps/functional/common_cypress.sh export JOB=kibana-fleet-cypress +export KIBANA_INSTALL_DIR=${KIBANA_BUILD_LOCATION} -echo "--- Fleet Cypress tests" +echo "--- Fleet Cypress tests (Chrome)" -node scripts/functional_tests \ - --debug --bail \ - --kibana-install-dir "$KIBANA_BUILD_LOCATION" \ - --config x-pack/test/fleet_cypress/cli_config.ts +cd x-pack/plugins/fleet + +set +e +yarn cypress:run:reporter; status=$?; yarn junit:merge || :; exit $status diff --git a/.buildkite/scripts/steps/functional/profiling_cypress.sh b/.buildkite/scripts/steps/functional/profiling_cypress.sh index 38799acc9077..1f6fb316b77a 100644 --- a/.buildkite/scripts/steps/functional/profiling_cypress.sh +++ b/.buildkite/scripts/steps/functional/profiling_cypress.sh @@ -13,5 +13,5 @@ echo "--- Profiling Cypress Tests" cd "$XPACK_DIR" -node plugins/profiling/scripts/test/e2e.js \ +NODE_OPTIONS=--openssl-legacy-provider node plugins/profiling/scripts/test/e2e.js \ --kibana-install-dir "$KIBANA_BUILD_LOCATION" \ \ No newline at end of file diff --git a/package.json b/package.json index 6ebe1726de72..2d4809d185c6 100644 --- a/package.json +++ b/package.json @@ -1446,7 +1446,7 @@ "cssnano": "^5.1.12", "cssnano-preset-default": "^5.2.12", "csstype": "^3.0.2", - "cypress": "^12.13.0", + "cypress": "^12.17.4", "cypress-axe": "^1.4.0", "cypress-file-upload": "^5.0.8", "cypress-multi-reporters": "^1.6.3", diff --git a/test/scripts/jenkins_fleet_cypress.sh b/test/scripts/jenkins_fleet_cypress.sh index a6d955781237..e43259c1c1c3 100755 --- a/test/scripts/jenkins_fleet_cypress.sh +++ b/test/scripts/jenkins_fleet_cypress.sh @@ -5,10 +5,8 @@ source test/scripts/jenkins_test_setup_xpack.sh echo " -> Running fleet cypress tests" cd "$XPACK_DIR" -node scripts/functional_tests \ - --debug --bail \ - --kibana-install-dir "$KIBANA_INSTALL_DIR" \ - --config test/fleet_cypress/cli_config.ts +cd x-pack/plugins/fleet +yarn --cwd x-pack/plugins/fleet cypress:run echo "" echo "" diff --git a/x-pack/plugins/apm/scripts/test/e2e.js b/x-pack/plugins/apm/scripts/test/e2e.js index 5be124dbab08..ae0c8c8e1027 100644 --- a/x-pack/plugins/apm/scripts/test/e2e.js +++ b/x-pack/plugins/apm/scripts/test/e2e.js @@ -69,7 +69,11 @@ function runTests() { return childProcess.spawnSync('node', spawnArgs, { cwd: e2eDir, - env: { ...process.env, CYPRESS_CLI_ARGS: JSON.stringify(cypressCliArgs) }, + env: { + ...process.env, + CYPRESS_CLI_ARGS: JSON.stringify(cypressCliArgs), + NODE_OPTIONS: '--openssl-legacy-provider', + }, encoding: 'utf8', stdio: 'inherit', }); diff --git a/x-pack/plugins/fleet/cypress.config.ts b/x-pack/plugins/fleet/cypress.config.ts index f4002d16c741..e4a5ad96938d 100644 --- a/x-pack/plugins/fleet/cypress.config.ts +++ b/x-pack/plugins/fleet/cypress.config.ts @@ -18,6 +18,10 @@ export default defineCypressConfig({ runMode: 2, }, + env: { + grepFilterSpecs: false, + }, + screenshotsFolder: '../../../target/kibana-fleet/cypress/screenshots', trashAssetsBeforeRuns: false, video: false, @@ -26,14 +30,16 @@ export default defineCypressConfig({ viewportWidth: 1440, screenshotOnRunFailure: true, - env: { - protocol: 'http', - hostname: 'localhost', - configport: '5601', - }, - e2e: { baseUrl: 'http://localhost:5601', + + experimentalRunAllSpecs: true, + experimentalMemoryManagement: true, + numTestsKeptInMemory: 3, + + specPattern: './cypress/e2e/**/*.cy.ts', + supportFile: './cypress/support/e2e.ts', + setupNodeEvents(on, config) { // eslint-disable-next-line @typescript-eslint/no-var-requires, @kbn/imports/no_boundary_crossing return require('./cypress/plugins')(on, config); diff --git a/x-pack/plugins/fleet/cypress/README.md b/x-pack/plugins/fleet/cypress/README.md index f18bce6eaa83..8300ec26ede3 100644 --- a/x-pack/plugins/fleet/cypress/README.md +++ b/x-pack/plugins/fleet/cypress/README.md @@ -52,8 +52,9 @@ node scripts/build_kibana_platform_plugins # launch the cypress test runner cd x-pack/plugins/fleet -yarn cypress:run-as-ci +yarn cypress:run ``` + #### FTR + Interactive This is the preferred mode for developing new tests. @@ -67,17 +68,7 @@ node scripts/build_kibana_platform_plugins # launch the cypress test runner cd x-pack/plugins/fleet -yarn cypress:open-as-ci -``` - -Alternatively, kibana test server can be started separately, to pick up changes in UI (e.g. change in data-test-subj selector) - -``` -# launch kibana test server -node scripts/functional_tests_server --config x-pack/test/fleet_cypress/config.ts - -# launch cypress runner -node scripts/functional_test_runner --config x-pack/test/fleet_cypress/visual_config.ts +yarn cypress:open ``` Note that you can select the browser you want to use on the top right side of the interactive runner. @@ -108,7 +99,7 @@ Each file inside the screens folder represents a screen in our application. _Tasks_ are functions that may be reused across tests. -Each file inside the tasks folder represents a screen of our application. +Each file inside the tasks folder represents a screen of our application. ## Test data @@ -141,7 +132,7 @@ Note that the command will create the folder if it does not exist. ## Development Best Practices -### Clean up the state +### Clean up the state Remember to clean up the state of the test after its execution, typically with the `cleanKibana` function. Be mindful of failure scenarios, as well: if your test fails, will it leave the environment in a recoverable state? @@ -164,7 +155,7 @@ Remember that minimizing the number of times the web page is loaded, we minimize The `checkA11y({ skipFailures: false });` call uses [axe-core](https://github.com/dequelabs/axe-core) to perform a full page check for accessibility violations. -See [axe-core](https://github.com/dequelabs/axe-core)'s documentation for details on what is checked for. +See [axe-core](https://github.com/dequelabs/axe-core)'s documentation for details on what is checked for. ## Linting diff --git a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts index 7af771d60f9e..a6ec3b26c923 100644 --- a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts @@ -34,12 +34,18 @@ import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup'; import { setFleetServerHost } from '../../tasks/fleet_server'; import { API_VERSIONS } from '../../../common/constants'; +import { login } from '../../tasks/login'; +import { request } from '../../tasks/common'; describe('Home page', () => { before(() => { setFleetServerHost('https://fleetserver:8220'); }); + beforeEach(() => { + login(); + }); + describe('Agents', () => { beforeEach(() => { navigateTo(FLEET); @@ -150,7 +156,7 @@ describe('Home page', () => { describe('Uninstall Tokens', () => { before(() => { - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies', body: { name: 'Agent policy for A11y test', namespace: 'default', id: 'agent-policy-a11y' }, @@ -162,7 +168,7 @@ describe('Home page', () => { cy.getBySel(UNINSTALL_TOKENS_TAB).click(); }); after(() => { - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: 'agent-policy-a11y' }, @@ -182,6 +188,7 @@ describe('Home page', () => { describe('Data Streams', () => { before(() => { + login(); navigateTo(FLEET); cy.getBySel(DATA_STREAMS_TAB, { timeout: 15000 }).should('be.visible'); cy.getBySel(DATA_STREAMS_TAB).click(); diff --git a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts index 3d5fa3f98fe2..54fbbefe99e6 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts @@ -11,15 +11,19 @@ import { AGENT_BINARY_SOURCES_FLYOUT, AGENT_POLICY_FORM, } from '../screens/fleet'; -import { cleanupDownloadSources } from '../tasks/cleanup'; +import { cleanupAgentPolicies, cleanupDownloadSources } from '../tasks/cleanup'; import { FLEET, navigateTo } from '../tasks/navigation'; import { CONFIRM_MODAL } from '../screens/navigation'; -import { API_VERSIONS } from '../../common/constants'; +import { request } from '../tasks/common'; +import { login } from '../tasks/login'; describe('Agent binary download source section', () => { beforeEach(() => { cleanupDownloadSources(); + cleanupAgentPolicies(); + + login(); navigateTo(FLEET); }); @@ -74,7 +78,7 @@ describe('Agent binary download source section', () => { }); it('the download source is displayed in agent policy settings', () => { - cy.request({ + request({ method: 'POST', url: `api/fleet/agent_download_sources`, body: { @@ -82,9 +86,8 @@ describe('Agent binary download source section', () => { id: 'fleet-local-registry', host: 'https://new-custom-host.co', }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies', body: { @@ -95,7 +98,6 @@ describe('Agent binary download source section', () => { id: 'new-agent-policy', download_source_id: 'fleet-local-registry', }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }).then((response: any) => { navigateTo('app/fleet/policies/new-agent-policy/settings'); cy.getBySel(AGENT_POLICY_FORM.DOWNLOAD_SOURCE_SELECT).contains('Custom Host'); diff --git a/x-pack/plugins/fleet/cypress/e2e/agent_policy.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agent_policy.cy.ts index 916590c05c0b..8d9604318e12 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agent_policy.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agent_policy.cy.ts @@ -4,11 +4,14 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { TOAST_CLOSE_BTN } from '../screens/navigation'; import { setupFleetServer } from '../tasks/fleet_server'; import { AGENT_FLYOUT, AGENT_POLICY_DETAILS_PAGE } from '../screens/fleet'; +import { login } from '../tasks/login'; + describe('Edit agent policy', () => { beforeEach(() => { + login(); + cy.intercept('/api/fleet/agent_policies/policy-1', { item: { id: 'policy-1', @@ -35,7 +38,6 @@ describe('Edit agent policy', () => { it('should edit agent policy', () => { cy.visit('/app/fleet/policies/policy-1/settings'); - cy.getBySel(TOAST_CLOSE_BTN).click(); cy.get('[placeholder="Optional description"').clear().type('desc'); cy.intercept('/api/fleet/agent_policies/policy-1', { diff --git a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts index 1e3bf95bb235..a82c362a8ea4 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts @@ -14,6 +14,8 @@ import type { CreateAgentPolicyRequest } from '../../../common/types'; import { setUISettings } from '../../tasks/ui_settings'; import { API_VERSIONS } from '../../../common/constants'; +import { request } from '../../tasks/common'; +import { login } from '../../tasks/login'; const createAgentDocs = (kibanaVersion: string) => [ createAgentDoc('agent-1', 'policy-1'), // this agent will have upgrade available @@ -65,7 +67,7 @@ const POLICIES: Array = [ ]; function createAgentPolicy(body: CreateAgentPolicyRequest['body']) { - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies', headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, @@ -101,11 +103,13 @@ describe('View agents list', () => { } }); after(() => { - deleteFleetServerDocs(); - deleteAgentDocs(); + deleteFleetServerDocs(true); + deleteAgentDocs(true); cleanupAgentPolicies(); }); beforeEach(() => { + login(); + cy.intercept('/api/fleet/agents/setup', { isReady: true, missing_optional_features: [], @@ -369,7 +373,6 @@ describe('View agents list', () => { cy.get('.euiModalFooter button:enabled').contains('Assign policy').click(); cy.wait('@getAgents'); assertTableIsEmpty(); - cy.pause(); // Select new policy is filters cy.getBySel(FLEET_AGENT_LIST_PAGE.POLICY_FILTER).click(); cy.get('button').contains('Agent policy 4').click(); diff --git a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts index 57149b435e43..30f688792f0c 100644 --- a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts @@ -9,10 +9,12 @@ import { cleanupAgentPolicies } from '../tasks/cleanup'; import { ENROLLMENT_TOKENS } from '../screens/fleet'; import { API_VERSIONS } from '../../common/constants'; +import { request } from '../tasks/common'; +import { login } from '../tasks/login'; describe('Enrollment token page', () => { before(() => { - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies', body: { @@ -30,6 +32,10 @@ describe('Enrollment token page', () => { cleanupAgentPolicies(); }); + beforeEach(() => { + login(); + }); + it('Create new Token', () => { cy.visit('app/fleet/enrollment-tokens'); cy.getBySel(ENROLLMENT_TOKENS.CREATE_TOKEN_BUTTON).click(); diff --git a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts index 6ca1eb669da1..5c653ea3fcf2 100644 --- a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts @@ -10,8 +10,10 @@ import { cleanupAgentPolicies, deleteFleetServerDocs, deleteAgentDocs } from '.. import { createAgentDoc } from '../tasks/agents'; import { setFleetServerHost } from '../tasks/fleet_server'; import { FLEET, navigateTo } from '../tasks/navigation'; +import { request } from '../tasks/common'; import { API_VERSIONS } from '../../common/constants'; +import { login } from '../tasks/login'; const FLEET_SERVER_POLICY_ID = 'fleet-server-policy'; @@ -27,7 +29,7 @@ describe('Fleet add agent flyout', () => { cleanUp(); let policyId: string; // Create a Fleet server policy - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies', headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, @@ -61,6 +63,8 @@ describe('Fleet add agent flyout', () => { }); setFleetServerHost(); }); + + login(); }); afterEach(() => { diff --git a/x-pack/plugins/fleet/cypress/e2e/fleet_settings.cy.ts b/x-pack/plugins/fleet/cypress/e2e/fleet_settings.cy.ts index f37a4180877e..34bf23739495 100644 --- a/x-pack/plugins/fleet/cypress/e2e/fleet_settings.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/fleet_settings.cy.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { TOAST_CLOSE_BTN, CONFIRM_MODAL } from '../screens/navigation'; +import { CONFIRM_MODAL } from '../screens/navigation'; import { SETTINGS_SAVE_BTN, SETTINGS_OUTPUTS, @@ -14,9 +14,12 @@ import { FLEET_SERVER_SETUP, GENERATE_FLEET_SERVER_POLICY_BUTTON, } from '../screens/fleet'; +import { login } from '../tasks/login'; describe('Edit settings', () => { beforeEach(() => { + login(); + cy.intercept('/api/fleet/fleet_server_hosts', { items: [ { @@ -43,7 +46,6 @@ describe('Edit settings', () => { }); cy.visit('/app/fleet/settings'); - cy.getBySel(TOAST_CLOSE_BTN).click(); }); it('should allow to update Fleet server hosts', () => { diff --git a/x-pack/plugins/fleet/cypress/e2e/fleet_startup.cy.ts b/x-pack/plugins/fleet/cypress/e2e/fleet_startup.cy.ts index 2c90e930fcb1..21eefd56eede 100644 --- a/x-pack/plugins/fleet/cypress/e2e/fleet_startup.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/fleet_startup.cy.ts @@ -17,31 +17,20 @@ import { LANDING_PAGE_ADD_FLEET_SERVER_BUTTON, } from '../screens/fleet'; import { cleanupAgentPolicies, unenrollAgent } from '../tasks/cleanup'; +import { request } from '../tasks/common'; import { verifyPolicy, verifyAgentPackage, navigateToTab } from '../tasks/fleet'; -import { deleteFleetServer } from '../tasks/fleet_server'; +import { deleteFleetServer, setFleetServerHost } from '../tasks/fleet_server'; +import { login } from '../tasks/login'; import { FLEET, navigateTo } from '../tasks/navigation'; describe('Fleet startup', () => { - // skipping Fleet Server enroll, to enable, comment out runner.ts line 23 - describe.skip('Fleet Server', () => { - it('should display Add agent button and Healthy agent once Fleet Agent page loaded', () => { - navigateTo(FLEET); - cy.get('.euiBadge').contains('Healthy'); - - verifyPolicy('Fleet Server policy', ['Fleet Server']); - }); - - after(() => { - unenrollAgent(); - cleanupAgentPolicies(); - }); - }); - describe('Create policies', () => { before(() => { unenrollAgent(); cleanupAgentPolicies(); deleteFleetServer(); + + setFleetServerHost(); }); after(() => { @@ -49,11 +38,12 @@ describe('Fleet startup', () => { }); beforeEach(() => { + login(); navigateTo(FLEET); }); it('should have no agent policy by default', () => { - cy.request('/api/fleet/agent_policies?full=true').then((response: any) => { + request({ url: '/api/fleet/agent_policies?full=true' }).then((response: any) => { expect(response.body.items.length).to.equal(0); }); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/install_assets.cy.ts b/x-pack/plugins/fleet/cypress/e2e/install_assets.cy.ts index 886f439a1a2e..e22d601d06c3 100644 --- a/x-pack/plugins/fleet/cypress/e2e/install_assets.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/install_assets.cy.ts @@ -9,9 +9,12 @@ import type { Interception } from 'cypress/types/net-stubbing'; import { CONFIRM_MODAL } from '../screens/navigation'; import { SETTINGS } from '../screens/integrations'; +import { login } from '../tasks/login'; describe('Install unverified package assets', () => { beforeEach(() => { + login(); + cy.intercept('POST', '/api/fleet/epm/packages/fleet_server/*', (req) => { if (!req.body.force) { return req.reply({ diff --git a/x-pack/plugins/fleet/cypress/e2e/integrations_mock.cy.ts b/x-pack/plugins/fleet/cypress/e2e/integrations_mock.cy.ts index d40cae5b5897..0e519dc48389 100644 --- a/x-pack/plugins/fleet/cypress/e2e/integrations_mock.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/integrations_mock.cy.ts @@ -7,11 +7,16 @@ import { navigateTo } from '../tasks/navigation'; import { UPDATE_PACKAGE_BTN } from '../screens/integrations'; -import { LOADING_SPINNER, TOAST_CLOSE_BTN } from '../screens/navigation'; +import { LOADING_SPINNER } from '../screens/navigation'; import { AGENT_POLICY_SAVE_INTEGRATION } from '../screens/fleet'; import { INSTALLED_VERSION, INTEGRATION_POLICIES_UPGRADE_CHECKBOX } from '../screens/integrations'; +import { login } from '../tasks/login'; describe('Add Integration - Mock API', () => { + beforeEach(() => { + login(); + }); + describe('upgrade package and upgrade package policy', () => { const oldVersion = '0.3.3'; const newVersion = '1.3.4'; @@ -143,7 +148,6 @@ describe('Add Integration - Mock API', () => { '/app/fleet/policies/package-1/upgrade-package-policy/apache-2?from=integrations-policy-list' ); - cy.getBySel(TOAST_CLOSE_BTN).click(); cy.getBySel(AGENT_POLICY_SAVE_INTEGRATION).click(); cy.wait('@updateApachePolicy').then((interception) => { diff --git a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts index 1ce6636198fe..e60f6e073e06 100644 --- a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts @@ -31,7 +31,8 @@ import { import { LOADING_SPINNER, CONFIRM_MODAL } from '../screens/navigation'; import { ADD_PACKAGE_POLICY_BTN } from '../screens/fleet'; import { cleanupAgentPolicies } from '../tasks/cleanup'; -import { API_VERSIONS } from '../../common/constants'; +import { request } from '../tasks/common'; +import { login } from '../tasks/login'; function setupIntegrations() { cy.intercept( @@ -73,30 +74,31 @@ function getAllIntegrations() { }); } -it('should install integration without policy', () => { - cy.visit('/app/integrations/detail/tomcat/settings'); - - cy.getBySel(SETTINGS.INSTALL_ASSETS_BTN).click(); - cy.get('.euiCallOut').contains('This action will install 1 assets'); - cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click(); - - cy.getBySel(LOADING_SPINNER).should('not.exist'); - - cy.getBySel(SETTINGS.UNINSTALL_ASSETS_BTN).click(); - cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click(); - cy.getBySel(LOADING_SPINNER).should('not.exist'); - cy.getBySel(SETTINGS.INSTALL_ASSETS_BTN).should('exist'); -}); - describe('Add Integration - Real API', () => { const integration = 'apache'; - after(() => { + beforeEach(() => { + login(); + + cleanupAgentPolicies(); deleteIntegrations(); }); - afterEach(() => { - cleanupAgentPolicies(); + afterEach(() => {}); + + it('should install integration without policy', () => { + cy.visit('/app/integrations/detail/tomcat/settings'); + + cy.getBySel(SETTINGS.INSTALL_ASSETS_BTN).click(); + cy.get('.euiCallOut').contains('This action will install 1 assets'); + cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click(); + + cy.getBySel(LOADING_SPINNER).should('not.exist'); + + cy.getBySel(SETTINGS.UNINSTALL_ASSETS_BTN).click(); + cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click(); + cy.getBySel(LOADING_SPINNER).should('not.exist'); + cy.getBySel(SETTINGS.INSTALL_ASSETS_BTN).should('exist'); }); it('should install integration without policy', () => { @@ -126,7 +128,7 @@ describe('Add Integration - Real API', () => { it('should add integration to policy', () => { const agentPolicyId = 'policy_1'; - cy.request({ + request({ method: 'POST', url: `/api/fleet/agent_policies`, body: { @@ -136,10 +138,9 @@ describe('Add Integration - Real API', () => { namespace: 'default', monitoring_enabled: ['logs', 'metrics'], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); - cy.request('/api/fleet/agent_policies').then((response: any) => { + request({ url: '/api/fleet/agent_policies' }).then((response: any) => { cy.visit(`/app/fleet/policies/${agentPolicyId}`); cy.intercept( diff --git a/x-pack/plugins/fleet/cypress/e2e/package_policy.cy.ts b/x-pack/plugins/fleet/cypress/e2e/package_policy.cy.ts index 8b1569574c4e..0802f5e985dd 100644 --- a/x-pack/plugins/fleet/cypress/e2e/package_policy.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/package_policy.cy.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { TOAST_CLOSE_BTN } from '../screens/navigation'; +import { login } from '../tasks/login'; describe('Edit package policy', () => { const policyConfig = { @@ -32,6 +32,8 @@ describe('Edit package policy', () => { ], }; beforeEach(() => { + login(); + cy.intercept('/api/fleet/package_policies/policy-1', { item: policyConfig, }); @@ -110,7 +112,6 @@ describe('Edit package policy', () => { it('should edit package policy', () => { cy.visit('/app/fleet/policies/fleet-server-policy/edit-integration/policy-1'); - cy.getBySel(TOAST_CLOSE_BTN).click(); cy.getBySel('packagePolicyDescriptionInput').clear().type('desc'); cy.intercept('PUT', '/api/fleet/package_policies/policy-1', { diff --git a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts index 60c75327f06a..c1cf0ef4e0b0 100644 --- a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts @@ -18,8 +18,15 @@ const INTEGRATION_TEST_PACKAGE = 'logs_integration-1.0.0'; const INTEGRATION_TEST_PACKAGE_NO_DATASET = 'logs_int_no_dataset-1.0.0'; import { API_VERSIONS } from '../../common/constants'; +import { request } from '../tasks/common'; +import { login } from '../tasks/login'; +import { cleanupAgentPolicies } from '../tasks/cleanup'; describe('Input package create and edit package policy', () => { + beforeEach(() => { + login(); + }); + const agentPolicyId = 'test-input-package-policy'; const agentPolicyName = 'Test input package policy'; const packagePolicyName = 'input-package-policy'; @@ -37,7 +44,7 @@ describe('Input package create and edit package policy', () => { before(() => { cy.task('installTestPackage', INPUT_TEST_PACKAGE); - cy.request({ + request({ method: 'POST', url: `/api/fleet/agent_policies`, body: { @@ -50,18 +57,12 @@ describe('Input package create and edit package policy', () => { headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); + after(() => { - // delete agent policy - cy.request({ - method: 'POST', - url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, - body: JSON.stringify({ - agentPolicyId, - }), - }); + cleanupAgentPolicies(); cy.task('uninstallTestPackage', INPUT_TEST_PACKAGE); }); + it('should successfully create a package policy', () => { cy.visit(`/app/integrations/detail/${INPUT_TEST_PACKAGE}/overview`); cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click(); @@ -104,6 +105,10 @@ describe('Input package create and edit package policy', () => { }); describe('Integration package with custom dataset create and edit package policy', () => { + beforeEach(() => { + login(); + }); + const agentPolicyId = 'test-logs-integration-package-policy'; const agentPolicyName = 'Test integration with custom dataset package policy'; const packagePolicyName = 'logs-integration-package-policy'; @@ -112,7 +117,7 @@ describe('Integration package with custom dataset create and edit package policy before(() => { cy.task('installTestPackage', INTEGRATION_TEST_PACKAGE); - cy.request({ + request({ method: 'POST', url: `/api/fleet/agent_policies`, body: { @@ -125,18 +130,12 @@ describe('Integration package with custom dataset create and edit package policy headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); + after(() => { - // delete agent policy - cy.request({ - method: 'POST', - url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, - body: JSON.stringify({ - agentPolicyId, - }), - }); + cleanupAgentPolicies(); cy.task('uninstallTestPackage', INTEGRATION_TEST_PACKAGE); }); + it('should successfully create a package policy', () => { cy.visit(`/app/integrations/detail/${INTEGRATION_TEST_PACKAGE}/overview`); cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click(); @@ -169,6 +168,10 @@ describe('Integration package with custom dataset create and edit package policy }); describe('Integration package with fixed dataset create and edit package policy', () => { + beforeEach(() => { + login(); + }); + const agentPolicyId = 'test-integration-package-policy'; const agentPolicyName = 'Test integration package policy'; const packagePolicyName = 'integration-package-policy'; @@ -176,7 +179,7 @@ describe('Integration package with fixed dataset create and edit package policy' before(() => { cy.task('installTestPackage', INTEGRATION_TEST_PACKAGE_NO_DATASET); - cy.request({ + request({ method: 'POST', url: `/api/fleet/agent_policies`, body: { @@ -189,18 +192,12 @@ describe('Integration package with fixed dataset create and edit package policy' headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); + after(() => { - // delete agent policy - cy.request({ - method: 'POST', - url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, - body: JSON.stringify({ - agentPolicyId, - }), - }); + cleanupAgentPolicies(); cy.task('uninstallTestPackage', INTEGRATION_TEST_PACKAGE_NO_DATASET); }); + it('should successfully create a package policy', () => { cy.visit(`/app/integrations/detail/${INTEGRATION_TEST_PACKAGE_NO_DATASET}/overview`); cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click(); diff --git a/x-pack/plugins/fleet/cypress/e2e/privileges_editor_role.cy.ts b/x-pack/plugins/fleet/cypress/e2e/privileges_editor_role.cy.ts index 9923b4888b5e..0a06d42ab5c9 100644 --- a/x-pack/plugins/fleet/cypress/e2e/privileges_editor_role.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/privileges_editor_role.cy.ts @@ -7,7 +7,7 @@ import { FLEET, INTEGRATIONS, navigateTo } from '../tasks/navigation'; import { createUsers, BuiltInEditorUser, deleteUsers } from '../tasks/privileges'; -import { loginWithUserAndWaitForPage, logout } from '../tasks/login'; +import { login, loginWithUserAndWaitForPage, logout } from '../tasks/login'; import { getIntegrationCard } from '../screens/integrations'; @@ -27,6 +27,10 @@ describe('When the user has Editor built-in role', () => { createUsers(usersToCreate); }); + beforeEach(() => { + login(); + }); + afterEach(() => { logout(); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_none.cy.ts b/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_none.cy.ts index 53e6122d75a0..eaae2c3a7e01 100644 --- a/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_none.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_none.cy.ts @@ -12,7 +12,7 @@ import { FleetAllIntegrNoneUser, deleteUsersAndRoles, } from '../tasks/privileges'; -import { loginWithUserAndWaitForPage, logout } from '../tasks/login'; +import { login, loginWithUserAndWaitForPage, logout } from '../tasks/login'; import { MISSING_PRIVILEGES } from '../screens/fleet'; const rolesToCreate = [FleetAllIntegrNoneRole]; @@ -23,6 +23,10 @@ describe('When the user has All privilege for Fleet but None for integrations', createUsersAndRoles(usersToCreate, rolesToCreate); }); + beforeEach(() => { + login(); + }); + afterEach(() => { logout(); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_read.cy.ts b/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_read.cy.ts index ae727dbcf791..91b675c527a9 100644 --- a/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_read.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/privileges_fleet_all_integrations_read.cy.ts @@ -12,7 +12,7 @@ import { FleetAllIntegrReadUser, deleteUsersAndRoles, } from '../tasks/privileges'; -import { loginWithUserAndWaitForPage, logout } from '../tasks/login'; +import { login, loginWithUserAndWaitForPage, logout } from '../tasks/login'; import { navigateToTab, createAgentPolicy } from '../tasks/fleet'; import { cleanupAgentPolicies, unenrollAgent } from '../tasks/cleanup'; import { getIntegrationCard } from '../screens/integrations'; @@ -32,6 +32,7 @@ const usersToCreate = [FleetAllIntegrReadUser]; describe('When the user has All privilege for Fleet but Read for integrations', () => { before(() => { + login(); createUsersAndRoles(usersToCreate, rolesToCreate); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/privileges_viewer_role.cy.ts b/x-pack/plugins/fleet/cypress/e2e/privileges_viewer_role.cy.ts index 89eed6dcb207..11fe9b905ea1 100644 --- a/x-pack/plugins/fleet/cypress/e2e/privileges_viewer_role.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/privileges_viewer_role.cy.ts @@ -7,7 +7,7 @@ import { FLEET, INTEGRATIONS } from '../tasks/navigation'; import { createUsers, BuiltInViewerUser, deleteUsers } from '../tasks/privileges'; -import { loginWithUserAndWaitForPage, logout } from '../tasks/login'; +import { login, loginWithUserAndWaitForPage, logout } from '../tasks/login'; import { getIntegrationCard } from '../screens/integrations'; @@ -23,6 +23,10 @@ describe('When the user has Viewer built-in role', () => { createUsers(usersToCreate); }); + beforeEach(() => { + login(); + }); + afterEach(() => { logout(); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts index 3832feefe10e..f2c08bd1ffa1 100644 --- a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts @@ -12,6 +12,8 @@ import { UNINSTALL_TOKENS } from '../screens/fleet'; import type { GetUninstallTokenResponse } from '../../common/types/rest_spec/uninstall_token'; import { API_VERSIONS } from '../../common/constants'; +import { request } from '../tasks/common'; +import { login } from '../tasks/login'; describe('Uninstall token page', () => { before(() => { @@ -20,6 +22,8 @@ describe('Uninstall token page', () => { }); beforeEach(() => { + login(); + cy.visit('app/fleet/uninstall-tokens'); cy.intercept('GET', 'api/fleet/uninstall_tokens/*').as('getTokenRequest'); @@ -76,7 +80,7 @@ describe('Uninstall token page', () => { const generatePolicies = () => { for (let i = 1; i <= 3; i++) { - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies', body: { name: `Agent policy ${i}00`, namespace: 'default', id: `agent-policy-${i}00` }, diff --git a/x-pack/plugins/fleet/cypress/plugins/index.ts b/x-pack/plugins/fleet/cypress/plugins/index.ts index 23f50d0e2319..0a341858b122 100644 --- a/x-pack/plugins/fleet/cypress/plugins/index.ts +++ b/x-pack/plugins/fleet/cypress/plugins/index.ts @@ -67,6 +67,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { index, query, ignore_unavailable: ignoreUnavailable, + allow_no_indices: true, refresh: true, conflicts: 'proceed', }); diff --git a/x-pack/plugins/fleet/cypress/screens/fleet_outputs.ts b/x-pack/plugins/fleet/cypress/screens/fleet_outputs.ts index 0e018cd301d1..8e7121877b8b 100644 --- a/x-pack/plugins/fleet/cypress/screens/fleet_outputs.ts +++ b/x-pack/plugins/fleet/cypress/screens/fleet_outputs.ts @@ -5,9 +5,7 @@ * 2.0. */ -import { request } from '@kbn/osquery-plugin/cypress/tasks/common'; - -import { visit } from '../tasks/common'; +import { request, visit } from '../tasks/common'; import { getSpecificSelectorId, @@ -39,10 +37,9 @@ export const interceptOutputId = (cb: (caseId: string) => void) => { }; export const cleanupOutput = (outputId: string) => { - cy.request({ + request({ method: 'DELETE', url: `/api/fleet/outputs/${outputId}`, - headers: { 'kbn-xsrf': 'xx' }, }); }; @@ -51,7 +48,6 @@ const loadOutput = (body: Record) => method: 'POST', body, url: `/api/fleet/outputs`, - headers: { 'kbn-xsrf': 'xx' }, }).then((response) => response.body); export const kafkaOutputBody = { diff --git a/x-pack/plugins/fleet/cypress/support/e2e.ts b/x-pack/plugins/fleet/cypress/support/e2e.ts index 9e570cbe0c93..f7a0d664bddf 100644 --- a/x-pack/plugins/fleet/cypress/support/e2e.ts +++ b/x-pack/plugins/fleet/cypress/support/e2e.ts @@ -23,6 +23,7 @@ // *********************************************************** // Import commands.js using ES2015 syntax: +import { request } from '../tasks/common'; import './commands'; declare global { @@ -40,7 +41,7 @@ function getBySel(selector: string, ...args: any[]) { } function getKibanaVersion() { - return cy.request('/api/status').then(({ body }) => { + return request<{ version: { number: string } }>({ url: '/api/status' }).then(({ body }) => { return body.version.number; }); } diff --git a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts index 8ca9a1cb32d2..c2d873d9b8de 100644 --- a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts +++ b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts @@ -4,47 +4,45 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { API_VERSIONS } from '../../common/constants'; + +import { request } from './common'; export function cleanupAgentPolicies() { - cy.request('/api/fleet/agent_policies').then((response: any) => { + request({ url: '/api/fleet/agent_policies' }).then((response: any) => { response.body.items .filter((policy: any) => policy.agents === 0) .forEach((policy: any) => { - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: policy.id }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); }); } export function unenrollAgent() { - cy.request('/api/fleet/agents?page=1&perPage=20&showInactive=false&showUpgradeable=false').then( - (response: any) => { - response.body.items.forEach((agent: any) => { - cy.request({ - method: 'POST', - url: `api/fleet/agents/${agent.id}/unenroll`, - body: { revoke: true }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, - }); + request({ + url: '/api/fleet/agents?page=1&perPage=20&showInactive=false&showUpgradeable=false', + }).then((response: any) => { + response.body.items.forEach((agent: any) => { + request({ + method: 'POST', + url: `api/fleet/agents/${agent.id}/unenroll`, + body: { revoke: true }, }); - } - ); + }); + }); } export function cleanupDownloadSources() { - cy.request('/api/fleet/agent_download_sources').then((response: any) => { + request({ url: '/api/fleet/agent_download_sources' }).then((response: any) => { response.body.items .filter((ds: any) => !ds.is_default) .forEach((ds: any) => { - cy.request({ + request({ method: 'DELETE', url: `/api/fleet/agent_download_sources/${ds.id}`, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); }); diff --git a/x-pack/plugins/fleet/cypress/tasks/common.ts b/x-pack/plugins/fleet/cypress/tasks/common.ts index dffeb93fd914..ebb631b310b1 100644 --- a/x-pack/plugins/fleet/cypress/tasks/common.ts +++ b/x-pack/plugins/fleet/cypress/tasks/common.ts @@ -7,6 +7,8 @@ import { encode } from '@kbn/rison'; +import { API_VERSIONS } from '../../common'; + import type { ROLES } from './privileges'; import { getUrlWithRoute } from './login'; @@ -14,6 +16,30 @@ import { getUrlWithRoute } from './login'; const LOADING_INDICATOR = '[data-test-subj="globalLoadingIndicator"]'; const LOADING_INDICATOR_HIDDEN = '[data-test-subj="globalLoadingIndicator-hidden"]'; +// Grab username + password from environment variables +export const API_AUTH = Object.freeze({ + user: Cypress.env('KIBANA_USERNAME') ?? Cypress.env('ELASTICSEARCH_USERNAME'), + pass: Cypress.env('KIBANA_PASSWORD') ?? Cypress.env('ELASTICSEARCH_PASSWORD'), +}); + +export const COMMON_API_HEADERS = Object.freeze({ + 'kbn-xsrf': 'cypress', + 'x-elastic-internal-origin': 'fleet', + 'Elastic-Api-Version': API_VERSIONS.public.v1, +}); + +// Replaces request - adds baseline authentication + global headers +export const request = ({ + headers, + ...options +}: Partial): Cypress.Chainable> => { + return cy.request({ + auth: API_AUTH, + headers: { ...COMMON_API_HEADERS, ...headers }, + ...options, + }); +}; + /** * For all the new features tours we show in the app, this method disables them * by setting their configs in the local storage. It prevents the tours from appearing diff --git a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts index 4f9df31eeba6..e6bb58d7c2b9 100644 --- a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts +++ b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts @@ -4,9 +4,9 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { API_VERSIONS } from '../../common/constants'; import { createAgentDoc } from './agents'; +import { request } from './common'; const FLEET_SERVER_POLICY_ID = 'fleet-server-policy'; @@ -15,7 +15,7 @@ export async function setupFleetServer() { const policyId: string = FLEET_SERVER_POLICY_ID; let kibanaVersion: string; - cy.request({ + request({ method: 'POST', url: '/api/fleet/agent_policies', headers: { 'kbn-xsrf': 'xx' }, @@ -30,7 +30,7 @@ export async function setupFleetServer() { // 409 is expected if the policy already exists // this allows the test to be run repeatedly in dev if (response.status > 299 && response.status !== 409) { - throw new Error(`Failed to create Fleet Server policy: ${response.body.message}`); + throw new Error(`Failed to create Fleet Server policy: ${JSON.stringify(response.body)}`); } }); @@ -65,10 +65,9 @@ export function deleteFleetServer() { } export function setFleetServerHost(host = 'https://fleetserver:8220') { - cy.request({ + request({ method: 'POST', url: '/api/fleet/fleet_server_hosts', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: { name: 'Default host', host_urls: [host], diff --git a/x-pack/plugins/fleet/cypress/tasks/integrations.ts b/x-pack/plugins/fleet/cypress/tasks/integrations.ts index 538f28c759d8..ab640d8f26a0 100644 --- a/x-pack/plugins/fleet/cypress/tasks/integrations.ts +++ b/x-pack/plugins/fleet/cypress/tasks/integrations.ts @@ -13,9 +13,9 @@ import { } from '../screens/integrations'; import { AGENT_POLICY_SYSTEM_MONITORING_CHECKBOX, EXISTING_HOSTS_TAB } from '../screens/fleet'; -import { TOAST_CLOSE_BTN, CONFIRM_MODAL } from '../screens/navigation'; +import { CONFIRM_MODAL } from '../screens/navigation'; -import { API_VERSIONS } from '../../common/constants'; +import { request } from './common'; export const addIntegration = ({ useExistingPolicy } = { useExistingPolicy: false }) => { cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click(); @@ -33,7 +33,6 @@ export const addIntegration = ({ useExistingPolicy } = { useExistingPolicy: fals force: true, }); } - cy.getBySel(TOAST_CLOSE_BTN).click(); cy.getBySel(CREATE_PACKAGE_POLICY_SAVE_BTN).click(); // sometimes agent is assigned to default policy, sometimes not cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click(); @@ -50,23 +49,37 @@ export function clickIfVisible(selector: string) { }); } -export const deleteIntegrations = async () => { - const ids: string[] = []; - cy.request('/api/fleet/package_policies').then((response: any) => { - response.body.items.forEach((policy: any) => ids.push(policy.id)); - cy.request({ - url: `/api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, - body: `{ "packagePolicyIds": ${JSON.stringify(ids)}, "force": true }`, - method: 'POST', +export const deleteIntegrations = () => { + request({ url: '/api/fleet/package_policies' }) + .then((packagePoliciesResponse: any) => { + const packagePolicyIds = packagePoliciesResponse.body.items.map((policy: any) => policy.id); + + request({ + url: `/api/fleet/package_policies/delete`, + body: `{ "packagePolicyIds": ${JSON.stringify(packagePolicyIds)}, "force": true }`, + method: 'POST', + }); + }) + .then(() => { + request({ url: '/api/fleet/epm/packages' }).then((packagesResponse: any) => { + for (const pkg of packagesResponse.body.items.filter( + (item: any) => item.status === 'installed' + )) { + request({ + url: `/api/fleet/epm/packages/${pkg.name}/${pkg.version}`, + method: 'DELETE', + body: { + force: true, + }, + }); + } + }); }); - }); }; export const installPackageWithVersion = (integration: string, version: string) => { - cy.request({ + request({ url: `/api/fleet/epm/packages/${integration}/${version}`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: '{ "force": true }', method: 'POST', }); diff --git a/x-pack/plugins/fleet/cypress/tasks/login.ts b/x-pack/plugins/fleet/cypress/tasks/login.ts index 2df7b88f1607..1e50fff48bb9 100644 --- a/x-pack/plugins/fleet/cypress/tasks/login.ts +++ b/x-pack/plugins/fleet/cypress/tasks/login.ts @@ -12,6 +12,7 @@ import * as yaml from 'js-yaml'; import type { ROLES } from './privileges'; import { hostDetailsUrl, LOGOUT_URL } from './navigation'; +import { request } from './common'; /** * Credentials in the `kibana.dev.yml` config file will be used to authenticate @@ -135,7 +136,7 @@ export const deleteRoleAndUser = (role: ROLES) => { }; export const loginWithUser = (user: User) => { - cy.request({ + request({ body: { providerType: 'basic', providerName: 'basic', @@ -145,7 +146,6 @@ export const loginWithUser = (user: User) => { password: user.password, }, }, - headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, method: 'POST', url: constructUrlWithUser(user, LOGIN_API_ENDPOINT), }); @@ -162,7 +162,7 @@ export const loginWithRole = async (role: ROLES) => { port: Cypress.env('configport'), } as UrlObject); cy.log(`origin: ${theUrl}`); - cy.request({ + request({ body: { providerType: 'basic', providerName: 'basic', @@ -200,8 +200,9 @@ export const login = (role?: ROLES) => { * Returns `true` if the credentials used to login to Kibana are provided * via environment variables */ -const credentialsProvidedByEnvironment = (): boolean => - Cypress.env(ELASTICSEARCH_USERNAME) != null && Cypress.env(ELASTICSEARCH_PASSWORD) != null; +const credentialsProvidedByEnvironment = (): boolean => { + return Cypress.env(ELASTICSEARCH_USERNAME) != null && Cypress.env(ELASTICSEARCH_PASSWORD) != null; +}; /** * Authenticates with Kibana by reading credentials from the @@ -215,7 +216,7 @@ const loginViaEnvironmentCredentials = () => { ); // programmatically authenticate without interacting with the Kibana login page - cy.request({ + request({ body: { providerType: 'basic', providerName: 'basic', @@ -246,7 +247,7 @@ const loginViaConfig = () => { const config = yaml.safeLoad(kibanaDevYml); // programmatically authenticate without interacting with the Kibana login page - cy.request({ + request({ body: { providerType: 'basic', providerName: 'basic', diff --git a/x-pack/plugins/fleet/cypress/tasks/privileges.ts b/x-pack/plugins/fleet/cypress/tasks/privileges.ts index 06dcf4018d1a..da73f27e459b 100644 --- a/x-pack/plugins/fleet/cypress/tasks/privileges.ts +++ b/x-pack/plugins/fleet/cypress/tasks/privileges.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { request } from './common'; import { constructUrlWithUser, getEnvAuth } from './login'; interface User { @@ -186,7 +187,7 @@ export const createRoles = (roles: Role[]) => { const envUser = getEnvAuth(); for (const role of roles) { cy.log(`Creating role: ${JSON.stringify(role)}`); - cy.request({ + request({ body: role.privileges, headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, method: 'PUT', @@ -202,7 +203,7 @@ export const deleteRoles = (roles: Role[]) => { for (const role of roles) { cy.log(`Deleting role: ${JSON.stringify(role)}`); - cy.request({ + request({ headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, method: 'DELETE', url: constructUrlWithUser(envUser, `/api/security/role/${role.name}`), @@ -221,7 +222,7 @@ export const createUsers = (users: User[]) => { for (const user of users) { const userInfo = getUserInfo(user); cy.log(`Creating user: ${JSON.stringify(user)}`); - cy.request({ + request({ body: { username: user.username, password: user.password, @@ -242,7 +243,7 @@ export const deleteUsers = (users: User[]) => { const envUser = getEnvAuth(); for (const user of users) { cy.log(`Deleting user: ${JSON.stringify(user)}`); - cy.request({ + request({ headers: { 'kbn-xsrf': 'cypress-creds-via-config' }, method: 'DELETE', url: constructUrlWithUser(envUser, `/internal/security/users/${user.username}`), diff --git a/x-pack/plugins/fleet/cypress/tasks/ui_settings.ts b/x-pack/plugins/fleet/cypress/tasks/ui_settings.ts index fceffad66c41..e0d28a025650 100644 --- a/x-pack/plugins/fleet/cypress/tasks/ui_settings.ts +++ b/x-pack/plugins/fleet/cypress/tasks/ui_settings.ts @@ -5,9 +5,11 @@ * 2.0. */ +import { request } from './common'; + // Create a Fleet server policy export function setUISettings(settingsKey: string, settingsValue: any) { - cy.request({ + request({ method: 'POST', url: '/internal/kibana/settings', headers: { 'kbn-xsrf': 'xx' }, diff --git a/x-pack/plugins/fleet/cypress/tsconfig.json b/x-pack/plugins/fleet/cypress/tsconfig.json index c1aa789f67c5..28fe4b511424 100644 --- a/x-pack/plugins/fleet/cypress/tsconfig.json +++ b/x-pack/plugins/fleet/cypress/tsconfig.json @@ -28,6 +28,5 @@ "force": true }, "@kbn/rison", - "@kbn/osquery-plugin/cypress" ] } diff --git a/x-pack/plugins/fleet/package.json b/x-pack/plugins/fleet/package.json index d7687fbac90d..3e20162ab1d9 100644 --- a/x-pack/plugins/fleet/package.json +++ b/x-pack/plugins/fleet/package.json @@ -5,12 +5,10 @@ "private": true, "license": "Elastic License 2.0", "scripts": { - "cypress": "../../../node_modules/.bin/cypress", - "cypress:open": "yarn cypress open --config-file ./cypress.config.ts", - "cypress:open-as-ci": "node ../../../scripts/functional_tests --config ../../test/fleet_cypress/visual_config.ts", - "cypress:run": "yarn cypress:run:reporter --browser chrome --spec './cypress/e2e/**/*.cy.ts'; status=$?; yarn junit:merge && exit $status", - "cypress:run-as-ci": "node ../../../scripts/functional_tests --config ../../test/fleet_cypress/cli_config.ts", - "cypress:run:reporter": "yarn cypress run --config-file ./cypress.config.ts --reporter ../../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json", + "cypress": "NODE_OPTIONS=--openssl-legacy-provider node ../security_solution/scripts/start_cypress_parallel --config-file ../fleet/cypress.config.ts --ftr-config-file ../../../x-pack/test/fleet_cypress/cli_config", + "cypress:open": "yarn cypress open", + "cypress:run": "yarn cypress run", + "cypress:run:reporter": "yarn cypress run --reporter ../../../node_modules/cypress-multi-reporters --reporter-options configFile=../fleet/cypress/reporter_config.json", "junit:merge": "../../../node_modules/.bin/mochawesome-merge ../../../target/kibana-fleet/cypress/results/mochawesome*.json > ../../../target/kibana-fleet/cypress/results/output.json && ../../../node_modules/.bin/marge ../../../target/kibana-fleet/cypress/results/output.json --reportDir ../../../target/kibana-fleet/cypress/results && mkdir -p ../../../target/junit && cp ../../../target/kibana-fleet/cypress/results/*.xml ../../../target/junit/", "openapi:build": "npx @redocly/openapi-cli bundle --ext yaml --output ./common/openapi/bundled.yaml ./common/openapi/entrypoint.yaml && npx @redocly/openapi-cli bundle --ext json --output ./common/openapi/bundled.json ./common/openapi/entrypoint.yaml", "openapi:lint": "npx @redocly/cli lint ./common/openapi/bundled.yaml", diff --git a/x-pack/plugins/observability_onboarding/scripts/test/e2e.js b/x-pack/plugins/observability_onboarding/scripts/test/e2e.js index d5cd56175d22..8a584a84bdc8 100644 --- a/x-pack/plugins/observability_onboarding/scripts/test/e2e.js +++ b/x-pack/plugins/observability_onboarding/scripts/test/e2e.js @@ -76,7 +76,11 @@ function runTests() { return childProcess.spawnSync('node', spawnArgs, { cwd: e2eDir, - env: { ...process.env, CYPRESS_CLI_ARGS: JSON.stringify(cypressCliArgs) }, + env: { + ...process.env, + CYPRESS_CLI_ARGS: JSON.stringify(cypressCliArgs), + NODE_OPTIONS: '--openssl-legacy-provider', + }, encoding: 'utf8', stdio: 'inherit', }); diff --git a/x-pack/plugins/osquery/package.json b/x-pack/plugins/osquery/package.json index bd21bb192545..32db6010c657 100644 --- a/x-pack/plugins/osquery/package.json +++ b/x-pack/plugins/osquery/package.json @@ -7,10 +7,10 @@ "scripts": { "cypress:burn": "yarn cypress:run --env burn=2 --headed", "cypress:changed-specs-only": "yarn cypress:run --changed-specs-only --env burn=2", - "cypress": "node ../security_solution/scripts/start_cypress_parallel --config-file ../osquery/cypress.config.ts --ftr-config-file ../../../x-pack/test/osquery_cypress/cli_config", + "cypress": "NODE_OPTIONS=--openssl-legacy-provider node ../security_solution/scripts/start_cypress_parallel --config-file ../osquery/cypress.config.ts --ftr-config-file ../../../x-pack/test/osquery_cypress/cli_config", "cypress:open": "yarn cypress open", "cypress:run": "yarn cypress run", - "cypress:serverless": "node ../security_solution/scripts/start_cypress_parallel --config-file ../osquery/serverless_cypress.config.ts --ftr-config-file ../../../x-pack/test/osquery_cypress/serverless_cli_config", + "cypress:serverless": "NODE_OPTIONS=--openssl-legacy-provider node ../security_solution/scripts/start_cypress_parallel --config-file ../osquery/serverless_cypress.config.ts --ftr-config-file ../../../x-pack/test/osquery_cypress/serverless_cli_config", "cypress:serverless:open": "yarn cypress:serverless open", "cypress:serverless:run": "yarn cypress:serverless run", "nyc": "../../../node_modules/.bin/nyc report --reporter=text-summary", diff --git a/x-pack/plugins/security_solution/package.json b/x-pack/plugins/security_solution/package.json index d29baae15d47..1c473d628ff2 100644 --- a/x-pack/plugins/security_solution/package.json +++ b/x-pack/plugins/security_solution/package.json @@ -7,13 +7,13 @@ "scripts": { "extract-mitre-attacks": "node scripts/extract_tactics_techniques_mitre.js && node ../../../scripts/eslint ./public/detections/mitre/mitre_tactics_techniques.ts --fix", "build-beat-doc": "node scripts/beat_docs/build.js && node ../../../scripts/eslint ../timelines/server/utils/beat_schema/fields.ts --fix", - "cypress": "../../../node_modules/.bin/cypress", + "cypress": "NODE_OPTIONS=--openssl-legacy-provider ../../../node_modules/.bin/cypress", "cypress:burn": "yarn cypress:dw run --env burn=2 --headed", "cypress:changed-specs-only": "yarn cypress:dw run --changed-specs-only --env burn=2", - "cypress:dw": "node ./scripts/start_cypress_parallel --config-file ./public/management/cypress.config.ts ts --ftr-config-file ../../test/defend_workflows_cypress/cli_config", + "cypress:dw": "NODE_OPTIONS=--openssl-legacy-provider node ./scripts/start_cypress_parallel --config-file ./public/management/cypress.config.ts ts --ftr-config-file ../../test/defend_workflows_cypress/cli_config", "cypress:dw:open": "yarn cypress:dw open", "cypress:dw:run": "yarn cypress:dw run", - "cypress:dw:endpoint": "node ./scripts/start_cypress_parallel --config-file ./public/management/cypress_endpoint.config.ts --ftr-config-file ../../test/defend_workflows_cypress/endpoint_config", + "cypress:dw:endpoint": "NODE_OPTIONS=--openssl-legacy-provider node ./scripts/start_cypress_parallel --config-file ./public/management/cypress_endpoint.config.ts --ftr-config-file ../../test/defend_workflows_cypress/endpoint_config", "cypress:dw:endpoint:run": "yarn cypress:dw:endpoint run", "cypress:dw:endpoint:open": "yarn cypress:dw:endpoint open ", "junit:merge": "../../../node_modules/.bin/mochawesome-merge ../../../target/kibana-security-solution/cypress/results/mochawesome*.json > ../../../target/kibana-security-solution/cypress/results/output.json && ../../../node_modules/.bin/marge ../../../target/kibana-security-solution/cypress/results/output.json --reportDir ../../../target/kibana-security-solution/cypress/results && yarn junit:transform && mkdir -p ../../../target/junit && cp ../../../target/kibana-security-solution/cypress/results/*.xml ../../../target/junit/", diff --git a/x-pack/plugins/threat_intelligence/package.json b/x-pack/plugins/threat_intelligence/package.json index a887c13c3ba4..1e934863b52f 100644 --- a/x-pack/plugins/threat_intelligence/package.json +++ b/x-pack/plugins/threat_intelligence/package.json @@ -5,11 +5,11 @@ "license": "Elastic License 2.0", "scripts": { "cypress": "../../../node_modules/.bin/cypress", - "cypress:open": "TZ=UTC node ../security_solution/scripts/start_cypress_parallel open --spec './cypress/e2e/**/*.cy.ts' --config-file ../../plugins/threat_intelligence/cypress/cypress.config.ts --ftr-config-file ../../test/threat_intelligence_cypress/cli_config_parallel", + "cypress:open": "TZ=UTC NODE_OPTIONS=--openssl-legacy-provider node ../security_solution/scripts/start_cypress_parallel open --spec './cypress/e2e/**/*.cy.ts' --config-file ../../plugins/threat_intelligence/cypress/cypress.config.ts --ftr-config-file ../../test/threat_intelligence_cypress/cli_config_parallel", "cypress:run": "yarn cypress:run:reporter --browser chrome --spec './cypress/e2e/**/*.cy.ts'; status=$?; yarn junit:merge && exit $status", "cypress:run:spec": "yarn cypress:run:reporter --browser chrome --spec ${SPEC_LIST:-'./cypress/e2e/**/*.cy.ts'}; status=$?; yarn junit:merge && exit $status", "cypress:run:cases": "yarn cypress:run:reporter --browser chrome --spec './cypress/e2e/cases/*.cy.ts' --ftr-config-file ../../test/security_solution_cypress/cli_config; status=$?; yarn junit:merge && exit $status", - "cypress:run:reporter": "TZ=UTC node ../security_solution/scripts/start_cypress_parallel run --config-file ../../plugins/threat_intelligence/cypress/cypress.config.ts --ftr-config-file ../../test/threat_intelligence_cypress/cli_config_parallel --reporter ../../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json", + "cypress:run:reporter": "TZ=UTC NODE_OPTIONS=--openssl-legacy-provider node ../security_solution/scripts/start_cypress_parallel run --config-file ../../plugins/threat_intelligence/cypress/cypress.config.ts --ftr-config-file ../../test/threat_intelligence_cypress/cli_config_parallel --reporter ../../../node_modules/cypress-multi-reporters --reporter-options configFile=./cypress/reporter_config.json", "cypress:run:respops": "yarn cypress:run:reporter --browser chrome --spec ./cypress/e2e/detection_alerts/*.cy.ts,./cypress/e2e/detection_rules/*.cy.ts,./cypress/e2e/exceptions/*.cy.ts --ftr-config-file ../../x-pack/test/security_solution_cypress/cli_config; status=$?; yarn junit:merge && exit $status", "junit:merge": "../../../node_modules/.bin/mochawesome-merge ../../../target/kibana-threat-intelligence/cypress/results/mochawesome*.json > ../../../target/kibana-threat-intelligence/cypress/results/output.json && ../../../node_modules/.bin/marge ../../../target/kibana-threat-intelligence/cypress/results/output.json --reportDir ../../../target/kibana-threat-intelligence/cypress/results && mkdir -p ../../../target/junit && cp ../../../target/kibana-threat-intelligence/cypress/results/*.xml ../../../target/junit/" } diff --git a/x-pack/test/fleet_cypress/config.ts b/x-pack/test/fleet_cypress/config.ts index 25f44880adf8..af6e2e20342e 100644 --- a/x-pack/test/fleet_cypress/config.ts +++ b/x-pack/test/fleet_cypress/config.ts @@ -35,6 +35,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { ...xpackFunctionalTestsConfig.get('kbnTestServer'), serverArgs: [ ...xpackFunctionalTestsConfig.get('kbnTestServer.serverArgs'), + '--csp.warnLegacyBrowsers=false', '--csp.strict=false', // define custom kibana server args here `--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`, diff --git a/x-pack/test/fleet_cypress/runner.ts b/x-pack/test/fleet_cypress/runner.ts index 87278cca019a..fcead46bdbc0 100644 --- a/x-pack/test/fleet_cypress/runner.ts +++ b/x-pack/test/fleet_cypress/runner.ts @@ -5,108 +5,38 @@ * 2.0. */ -import { resolve } from 'path'; import Url from 'url'; -import { withProcRunner } from '@kbn/dev-proc-runner'; - import { FtrProviderContext } from './ftr_provider_context'; -import { AgentManager, AgentManagerParams } from './agent'; -import { FleetManager } from './fleet_server'; +export async function FleetCypressCliTestRunner(context: FtrProviderContext) { + await startFleetCypress(context, 'run'); +} -async function withFleetAgent( - { getService }: FtrProviderContext, - runner: (runnerEnv: Record) => Promise -) { - // skipping fleet server enroll for now, as it is not a functionality of Fleet UI itself. are there any existing e2e tests for enroll? - return await runner({}); +export async function FleetCypressVisualTestRunner(context: FtrProviderContext) { + await startFleetCypress(context, 'open'); +} - const log = getService('log'); - const config = getService('config'); +function startFleetCypress(context: FtrProviderContext, cypressCommand: string) { + const config = context.getService('config'); - const esHost = Url.format(config.get('servers.elasticsearch')); - const params: AgentManagerParams = { - user: config.get('servers.elasticsearch.username'), - password: config.get('servers.elasticsearch.password'), - esHost, - esPort: config.get('servers.elasticsearch.port'), - kibanaUrl: Url.format({ + return { + FORCE_COLOR: '1', + baseUrl: Url.format({ + protocol: config.get('servers.kibana.protocol'), + hostname: config.get('servers.kibana.hostname'), + port: config.get('servers.kibana.port'), + }), + protocol: config.get('servers.kibana.protocol'), + hostname: config.get('servers.kibana.hostname'), + configport: config.get('servers.kibana.port'), + ELASTICSEARCH_URL: Url.format(config.get('servers.elasticsearch')), + ELASTICSEARCH_USERNAME: config.get('servers.kibana.username'), + ELASTICSEARCH_PASSWORD: config.get('servers.kibana.password'), + KIBANA_URL: Url.format({ protocol: config.get('servers.kibana.protocol'), hostname: config.get('servers.kibana.hostname'), port: config.get('servers.kibana.port'), }), }; - const requestOptions = { - headers: { - 'kbn-xsrf': 'kibana', - }, - auth: { - username: params.user, - password: params.password, - }, - }; - const fleetManager = new FleetManager(params, log, requestOptions); - - const agentManager = new AgentManager(params, log, requestOptions); - - // Since the managers will create uncaughtException event handlers we need to exit manually - process.on('uncaughtException', (err) => { - // eslint-disable-next-line no-console - console.error('Encountered error; exiting after cleanup.', err); - process.exit(1); - }); - - await agentManager.setup(); - await fleetManager.setup(); - try { - await runner({}); - } finally { - fleetManager.cleanup(); - agentManager.cleanup(); - } -} - -export async function FleetCypressCliTestRunner(context: FtrProviderContext) { - await startFleetAgent(context, 'run'); -} - -export async function FleetCypressVisualTestRunner(context: FtrProviderContext) { - await startFleetAgent(context, 'open'); -} - -function startFleetAgent(context: FtrProviderContext, cypressCommand: string) { - const log = context.getService('log'); - const config = context.getService('config'); - return withFleetAgent(context, (runnerEnv) => - withProcRunner(log, async (procs) => { - await procs.run('cypress', { - cmd: 'yarn', - args: [`cypress:${cypressCommand}`], - cwd: resolve(__dirname, '../../plugins/fleet'), - env: { - FORCE_COLOR: '1', - // eslint-disable-next-line @typescript-eslint/naming-convention - CYPRESS_baseUrl: Url.format(config.get('servers.kibana')), - // eslint-disable-next-line @typescript-eslint/naming-convention - CYPRESS_protocol: config.get('servers.kibana.protocol'), - // eslint-disable-next-line @typescript-eslint/naming-convention - CYPRESS_hostname: config.get('servers.kibana.hostname'), - // eslint-disable-next-line @typescript-eslint/naming-convention - CYPRESS_configport: config.get('servers.kibana.port'), - CYPRESS_ELASTICSEARCH_URL: Url.format(config.get('servers.elasticsearch')), - CYPRESS_ELASTICSEARCH_USERNAME: config.get('servers.elasticsearch.username'), - CYPRESS_ELASTICSEARCH_PASSWORD: config.get('servers.elasticsearch.password'), - CYPRESS_KIBANA_URL: Url.format({ - protocol: config.get('servers.kibana.protocol'), - hostname: config.get('servers.kibana.hostname'), - port: config.get('servers.kibana.port'), - }), - ...runnerEnv, - ...process.env, - }, - wait: true, - }); - }) - ); } diff --git a/x-pack/test/security_solution_cypress/package.json b/x-pack/test/security_solution_cypress/package.json index ba28de108ccf..f4be9a442b3e 100644 --- a/x-pack/test/security_solution_cypress/package.json +++ b/x-pack/test/security_solution_cypress/package.json @@ -5,11 +5,11 @@ "private": true, "license": "Elastic License 2.0", "scripts": { - "cypress": "../../../node_modules/.bin/cypress", - "cypress:open:ess": "TZ=UTC node ../../plugins/security_solution/scripts/start_cypress_parallel open --spec './cypress/e2e/**/*.cy.ts' --config-file ../../test/security_solution_cypress/cypress/cypress.config.ts --ftr-config-file ../../test/security_solution_cypress/cli_config", + "cypress": "NODE_OPTIONS=--openssl-legacy-provider ../../../node_modules/.bin/cypress", + "cypress:open:ess": "TZ=UTC NODE_OPTIONS=--openssl-legacy-provider node ../../plugins/security_solution/scripts/start_cypress_parallel open --spec './cypress/e2e/**/*.cy.ts' --config-file ../../test/security_solution_cypress/cypress/cypress.config.ts --ftr-config-file ../../test/security_solution_cypress/cli_config", "cypress:run:ess": "yarn cypress:ess --spec './cypress/e2e/!(investigations|explore)/**/*.cy.ts'", "cypress:run:cases:ess": "yarn cypress:ess --spec './cypress/e2e/explore/cases/*.cy.ts'", - "cypress:ess": "TZ=UTC node ../../plugins/security_solution/scripts/start_cypress_parallel run --config-file ../../test/security_solution_cypress/cypress/cypress_ci.config.ts --ftr-config-file ../../test/security_solution_cypress/cli_config", + "cypress:ess": "TZ=UTC NODE_OPTIONS=--openssl-legacy-provider node ../../plugins/security_solution/scripts/start_cypress_parallel run --config-file ../../test/security_solution_cypress/cypress/cypress_ci.config.ts --ftr-config-file ../../test/security_solution_cypress/cli_config", "cypress:run:respops:ess": "yarn cypress:ess --spec './cypress/e2e/(detection_alerts|detection_rules|exceptions)/*.cy.ts'", "cypress:investigations:run:ess": "yarn cypress:ess --spec './cypress/e2e/investigations/**/*.cy.ts'", "cypress:explore:run:ess": "yarn cypress:ess --spec './cypress/e2e/explore/**/*.cy.ts'", @@ -17,7 +17,7 @@ "cypress:burn:ess": "yarn cypress:ess --env burn=2", "junit:merge": "../../../node_modules/.bin/mochawesome-merge ../../../target/kibana-security-solution/cypress/results/mochawesome*.json > ../../../target/kibana-security-solution/cypress/results/output.json && ../../../node_modules/.bin/marge ../../../target/kibana-security-solution/cypress/results/output.json --reportDir ../../../target/kibana-security-solution/cypress/results && yarn junit:transform && mkdir -p ../../../target/junit && cp ../../../target/kibana-security-solution/cypress/results/*.xml ../../../target/junit/", "junit:transform": "node ../../plugins/security_solution/scripts/junit_transformer --pathPattern '../../../target/kibana-security-solution/cypress/results/*.xml' --rootDirectory ../../../ --reportName 'Security Solution Cypress' --writeInPlace", - "cypress:serverless": "TZ=UTC node ../../plugins/security_solution/scripts/start_cypress_parallel --config-file ../../test/security_solution_cypress/cypress/cypress_ci_serverless.config.ts --ftr-config-file ../../test/security_solution_cypress/serverless_config", + "cypress:serverless": "TZ=UTC NODE_OPTIONS=--openssl-legacy-provider node ../../plugins/security_solution/scripts/start_cypress_parallel --config-file ../../test/security_solution_cypress/cypress/cypress_ci_serverless.config.ts --ftr-config-file ../../test/security_solution_cypress/serverless_config", "cypress:open:serverless": "yarn cypress:serverless open --config-file ../../test/security_solution_cypress/cypress/cypress_serverless.config.ts --spec './cypress/e2e/**/*.cy.ts'", "cypress:run:serverless": "yarn cypress:serverless --spec './cypress/e2e/!(investigations|explore)/**/*.cy.ts'", "cypress:investigations:run:serverless": "yarn cypress:serverless --spec './cypress/e2e/investigations/**/*.cy.ts'", diff --git a/x-pack/test_serverless/functional/test_suites/observability/cypress/package.json b/x-pack/test_serverless/functional/test_suites/observability/cypress/package.json index 3c2d296e313e..bf0dad8dd01e 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/cypress/package.json +++ b/x-pack/test_serverless/functional/test_suites/observability/cypress/package.json @@ -5,9 +5,9 @@ "private": true, "license": "Elastic License 2.0", "scripts": { - "cypress:open": "../../../../../../node_modules/.bin/cypress open --config-file ./cypress.config.ts", - "cypress:run": "../../../../../../node_modules/.bin/cypress run --browser chrome --config-file ./cypress.config.ts", - "cypress:serverless:open": "node ../../../../../../scripts/functional_tests --config ./config_runner.ts", - "cypress:serverless:run": "node ../../../../../../scripts/functional_tests --config ./config_server.ts" + "cypress:open": "NODE_OPTIONS=--openssl-legacy-provider node ../../../../../../node_modules/.bin/cypress open --config-file ./cypress.config.ts", + "cypress:run": "NODE_OPTIONS=--openssl-legacy-provider node ../../../../../../node_modules/.bin/cypress run --browser chrome --config-file ./cypress.config.ts", + "cypress:serverless:open": "NODE_OPTIONS=--openssl-legacy-provider node ../../../../../../scripts/functional_tests --config ./config_runner.ts", + "cypress:serverless:run": "NODE_OPTIONS=--openssl-legacy-provider node ../../../../../../scripts/functional_tests --config ./config_server.ts" } } \ No newline at end of file diff --git a/x-pack/test_serverless/functional/test_suites/security/cypress/package.json b/x-pack/test_serverless/functional/test_suites/security/cypress/package.json index fd3033c84be3..ef8534585d4d 100644 --- a/x-pack/test_serverless/functional/test_suites/security/cypress/package.json +++ b/x-pack/test_serverless/functional/test_suites/security/cypress/package.json @@ -5,9 +5,9 @@ "private": true, "license": "Elastic License 2.0", "scripts": { - "cypress": "../../../../../../node_modules/.bin/cypress", - "cypress:open": "node ../../../../../plugins/security_solution/scripts/start_cypress_parallel open --config-file ../../../x-pack/test_serverless/functional/test_suites/security/cypress/cypress.config.ts --ftr-config-file ../../../../../../x-pack/test_serverless/functional/test_suites/security/cypress/security_config", - "cypress:run": "node ../../../../../plugins/security_solution/scripts/start_cypress_parallel run --browser chrome --config-file ../../../x-pack/test_serverless/functional/test_suites/security/cypress/cypress.config.ts --ftr-config-file ../../../../../../x-pack/test_serverless/functional/test_suites/security/cypress/security_config --reporter ../../../../../../node_modules/cypress-multi-reporters --reporter-options configFile=./reporter_config.json; status=$?; yarn junit:merge && exit $status", + "cypress": "NODE_OPTIONS=--openssl-legacy-provider node ../../../../../../node_modules/.bin/cypress", + "cypress:open": "NODE_OPTIONS=--openssl-legacy-provider node ../../../../../plugins/security_solution/scripts/start_cypress_parallel open --config-file ../../../x-pack/test_serverless/functional/test_suites/security/cypress/cypress.config.ts --ftr-config-file ../../../../../../x-pack/test_serverless/functional/test_suites/security/cypress/security_config", + "cypress:run": "NODE_OPTIONS=--openssl-legacy-provider node ../../../../../plugins/security_solution/scripts/start_cypress_parallel run --browser chrome --config-file ../../../x-pack/test_serverless/functional/test_suites/security/cypress/cypress.config.ts --ftr-config-file ../../../../../../x-pack/test_serverless/functional/test_suites/security/cypress/security_config --reporter ../../../../../../node_modules/cypress-multi-reporters --reporter-options configFile=./reporter_config.json; status=$?; yarn junit:merge && exit $status", "junit:merge": "../../../../../../node_modules/.bin/mochawesome-merge ../../../../../../target/kibana-security-serverless/cypress/results/mochawesome*.json > ../../../../../../target/kibana-security-serverless/cypress/results/output.json && ../../../../../../node_modules/.bin/marge ../../../../../../target/kibana-security-serverless/cypress/results/output.json --reportDir ../../../../../../target/kibana-security-serverless/cypress/results && mkdir -p ../../../../../../target/junit && cp ../../../../../../target/kibana-security-serverless/cypress/results/*.xml ../../../../../../target/junit/" } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index a743d2ee4a6e..ed2d78a55364 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1374,7 +1374,7 @@ find-test-names "^1.19.0" globby "^11.0.4" -"@cypress/request@^2.88.10": +"@cypress/request@2.88.12": version "2.88.12" resolved "https://registry.yarnpkg.com/@cypress/request/-/request-2.88.12.tgz#ba4911431738494a85e93fb04498cb38bc55d590" integrity sha512-tOn+0mDZxASFM+cuAP9szGUGPI1HwWVSvdzm7V4cCsPdFTx6qMj29CwaQmRAMIEhORIUBFBsYROYJcveK4uOjA== @@ -9414,7 +9414,7 @@ dependencies: "@types/node" "*" -"@types/node@*", "@types/node@18.17.1", "@types/node@>= 8", "@types/node@>=12.12.47", "@types/node@>=13.7.0", "@types/node@>=8.9.0", "@types/node@^10.1.0", "@types/node@^14.0.10 || ^16.0.0", "@types/node@^14.14.20 || ^16.0.0", "@types/node@^14.14.31", "@types/node@^18.11.18": +"@types/node@*", "@types/node@18.17.1", "@types/node@>= 8", "@types/node@>=12.12.47", "@types/node@>=13.7.0", "@types/node@>=8.9.0", "@types/node@^10.1.0", "@types/node@^14.0.10 || ^16.0.0", "@types/node@^14.14.20 || ^16.0.0", "@types/node@^16.18.39", "@types/node@^18.11.18": version "18.17.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.17.1.tgz#84c32903bf3a09f7878c391d31ff08f6fe7d8335" integrity sha512-xlR1jahfizdplZYRU59JlUx9uzF1ARa8jbhM11ccpCJya8kvos5jwdm2ZAgxSCwOl0fq21svP18EVwPBXMQudw== @@ -13868,14 +13868,14 @@ cypress-recurse@^1.35.1: dependencies: humanize-duration "^3.27.3" -cypress@^12.13.0: - version "12.13.0" - resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.13.0.tgz#725b6617ea19e41e5c59cc509fc3e08097142b01" - integrity sha512-QJlSmdPk+53Zhy69woJMySZQJoWfEWun3X5OOenGsXjRPVfByVTHorxNehbzhZrEzH9RDUDqVcck0ahtlS+N/Q== +cypress@^12.17.4: + version "12.17.4" + resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.17.4.tgz#b4dadf41673058493fa0d2362faa3da1f6ae2e6c" + integrity sha512-gAN8Pmns9MA5eCDFSDJXWKUpaL3IDd89N9TtIupjYnzLSmlpVr+ZR+vb4U/qaMp+lB6tBvAmt7504c3Z4RU5KQ== dependencies: - "@cypress/request" "^2.88.10" + "@cypress/request" "2.88.12" "@cypress/xvfb" "^1.2.4" - "@types/node" "^14.14.31" + "@types/node" "^16.18.39" "@types/sinonjs__fake-timers" "8.1.1" "@types/sizzle" "^2.3.2" arch "^2.2.0" @@ -13908,9 +13908,10 @@ cypress@^12.13.0: minimist "^1.2.8" ospath "^1.2.2" pretty-bytes "^5.6.0" + process "^0.11.10" proxy-from-env "1.0.0" request-progress "^3.0.0" - semver "^7.3.2" + semver "^7.5.3" supports-color "^8.1.1" tmp "~0.2.1" untildify "^4.0.0"