diff --git a/x-pack/plugins/fleet/cypress/integration/agent_binary_download_source.spec.ts b/x-pack/plugins/fleet/cypress/integration/agent_binary_download_source.spec.ts new file mode 100644 index 0000000000000..a6fa1c82a29a4 --- /dev/null +++ b/x-pack/plugins/fleet/cypress/integration/agent_binary_download_source.spec.ts @@ -0,0 +1,102 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { + SETTINGS_TAB, + AGENT_BINARY_SOURCES_TABLE, + AGENT_BINARY_SOURCES_TABLE_ACTIONS, + AGENT_BINARY_SOURCES_FLYOUT, + AGENT_POLICY_FORM, + CONFIRM_MODAL_CONFIRM_BUTTON, +} from '../screens/fleet'; +import { cleanupDownloadSources } from '../tasks/cleanup'; +import { FLEET, navigateTo } from '../tasks/navigation'; + +describe('Agent binary download source section', () => { + beforeEach(() => { + cleanupDownloadSources(); + navigateTo(FLEET); + }); + + it('has a default value and allows to edit an existing object', () => { + cy.getBySel(SETTINGS_TAB).click(); + + cy.getBySel(AGENT_BINARY_SOURCES_TABLE).find('tr').should('have.length', '2'); + cy.getBySel(AGENT_BINARY_SOURCES_TABLE_ACTIONS.HOST).contains( + 'https://artifacts.elastic.co/downloads/beats/elastic-agent' + ); + cy.getBySel(AGENT_BINARY_SOURCES_TABLE_ACTIONS.DEFAULT_VALUE).should('exist'); + cy.getBySel(AGENT_BINARY_SOURCES_TABLE_ACTIONS.EDIT).click(); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.NAME_INPUT).clear().type('New Name'); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.HOST_INPUT) + .clear() + .type('https://edited-default-host.co'); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.SUBMIT_BUTTON).click(); + cy.getBySel(CONFIRM_MODAL_CONFIRM_BUTTON).click(); + + cy.intercept('api/fleet/agent_download_sources/fleet-default-download-source', { + host: 'https://edited-default-host.co', + is_default: true, + name: 'New Name', + }); + }); + + it('allows to create new download source objects', () => { + cy.getBySel(SETTINGS_TAB).click(); + + cy.getBySel(AGENT_BINARY_SOURCES_TABLE_ACTIONS.ADD).click(); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.NAME_INPUT).clear().type('New Host'); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.HOST_INPUT).clear().type('https://new-test-host.co'); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.SUBMIT_BUTTON).click(); + cy.getBySel(AGENT_BINARY_SOURCES_TABLE).find('tr').should('have.length', '3'); + cy.intercept('api/fleet/agent_download_sources', { + name: 'New Host', + is_default: false, + host: 'https://new-test-host.co', + }); + + cy.getBySel(AGENT_BINARY_SOURCES_TABLE_ACTIONS.ADD).click(); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.NAME_INPUT).clear().type('New Default Host'); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.HOST_INPUT).clear().type('https://new-default-host.co'); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.IS_DEFAULT_SWITCH).click(); + cy.getBySel(AGENT_BINARY_SOURCES_FLYOUT.SUBMIT_BUTTON).click(); + + cy.intercept('api/fleet/agent_download_sources', { + name: 'New Default Host', + is_default: true, + host: 'https://new-default-host.co', + }); + }); + + it('the download source is displayed in agent policy settings', () => { + cy.request({ + method: 'POST', + url: `api/fleet/agent_download_sources`, + body: { + name: 'Custom Host', + id: 'fleet-local-registry', + host: 'https://new-custom-host.co', + }, + headers: { 'kbn-xsrf': 'kibana' }, + }); + cy.request({ + method: 'POST', + url: '/api/fleet/agent_policies', + body: { + name: 'Test Agent policy', + namespace: 'default', + description: '', + monitoring_enabled: ['logs', 'metrics'], + id: 'new-agent-policy', + download_source_id: 'fleet-local-registry', + }, + headers: { 'kbn-xsrf': 'kibana' }, + }).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/integration/integrations_real.spec.ts b/x-pack/plugins/fleet/cypress/integration/integrations_real.spec.ts index 9bfd725497ffc..cbd08b6e8f5d6 100644 --- a/x-pack/plugins/fleet/cypress/integration/integrations_real.spec.ts +++ b/x-pack/plugins/fleet/cypress/integration/integrations_real.spec.ts @@ -27,7 +27,7 @@ import { import { ADD_PACKAGE_POLICY_BTN } from '../screens/fleet'; import { cleanupAgentPolicies } from '../tasks/cleanup'; -describe('Add Integration - Real API', () => { +describe.skip('Add Integration - Real API', () => { const integration = 'Apache'; after(() => { diff --git a/x-pack/plugins/fleet/cypress/screens/fleet.ts b/x-pack/plugins/fleet/cypress/screens/fleet.ts index 25677c823833f..b1083b7c33820 100644 --- a/x-pack/plugins/fleet/cypress/screens/fleet.ts +++ b/x-pack/plugins/fleet/cypress/screens/fleet.ts @@ -24,7 +24,31 @@ export const AGENT_POLICY_SAVE_INTEGRATION = 'saveIntegration'; export const PACKAGE_POLICY_TABLE_LINK = 'PackagePoliciesTableLink'; export const ADD_PACKAGE_POLICY_BTN = 'addPackagePolicyButton'; +export const AGENT_BINARY_SOURCES_TABLE = 'AgentDownloadSourcesTable'; +export const AGENT_BINARY_SOURCES_TABLE_ACTIONS = { + DEFAULT_VALUE: 'editDownloadSourceTable.defaultIcon', + HOST: 'editDownloadSourceTable.host', + ADD: 'addDownloadSourcesBtn', + EDIT: 'editDownloadSourceTable.edit.btn', + DELETE: 'editDownloadSourceTable.delete.btn', + DEFAULT_ICON: 'editDownloadSourceTable.defaultIcon', + HOST_NAME: 'editDownloadSourceTable.host', +}; +export const AGENT_BINARY_SOURCES_FLYOUT = { + NAME_INPUT: 'editDownloadSourcesFlyout.nameInput', + HOST_INPUT: 'editDownloadSourcesFlyout.hostInput', + IS_DEFAULT_SWITCH: 'editDownloadSourcesFlyout.isDefaultSwitch', + SUBMIT_BUTTON: 'editDownloadSourcesFlyout.submitBtn', + CANCEL_BUTTON: 'editDownloadSourcesFlyout.cancelBtn', +}; + export const ADD_AGENT_FLYOUT = { CONFIRM_AGENT_ENROLLMENT_BUTTON: 'ConfirmAgentEnrollmentButton', INCOMING_DATA_CONFIRMED_CALL_OUT: 'IncomingDataConfirmedCallOut', }; +export const CONFIRM_MODAL_CONFIRM_BUTTON = 'confirmModalConfirmButton'; +export const CONFIRM_MODAL_CANCEL_BUTTON = 'confirmModalCancelButton'; + +export const AGENT_POLICY_FORM = { + DOWNLOAD_SOURCE_SELECT: 'agentPolicyForm.downloadSource.select', +}; diff --git a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts index e3ab5684777ca..b0d18fa9cdceb 100644 --- a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts +++ b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts @@ -34,3 +34,17 @@ export function unenrollAgent() { } ); } + +export function cleanupDownloadSources() { + cy.request('/api/fleet/agent_download_sources').then((response: any) => { + response.body.items + .filter((ds: any) => !ds.is_default) + .forEach((ds: any) => { + cy.request({ + method: 'DELETE', + url: `/api/fleet/agent_download_sources/${ds.id}`, + headers: { 'kbn-xsrf': 'kibana' }, + }); + }); + }); +} diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/download_source_table/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/download_source_table/index.tsx index c4b196bbaf15f..c61acb89c310b 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/download_source_table/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/download_source_table/index.tsx @@ -76,7 +76,9 @@ export const DownloadSourceTable: React.FunctionComponent - downloadSource.is_default ? : null, + downloadSource.is_default ? ( + + ) : null, width: '200px', name: i18n.translate('xpack.fleet.settings.downloadSourcesTable.defaultColumnTitle', { defaultMessage: 'Default', @@ -131,5 +133,11 @@ export const DownloadSourceTable: React.FunctionComponent; + return ( + + ); }; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/settings_page/agent_binary_section.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/settings_page/agent_binary_section.tsx index ae9a42a7b2144..8eb5892e3e9a0 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/settings_page/agent_binary_section.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/settings/components/settings_page/agent_binary_section.tsx @@ -50,7 +50,7 @@ export const AgentBinarySection: React.FunctionComponent