Skip to content

Commit

Permalink
[Security Solution] unskip cypress endpoint list tests (elastic#174977)
Browse files Browse the repository at this point in the history
## Summary

Unskip endpoint page cypress tests. Adjust assertions / actions to
improve consistency.

Flaky test runs:
-
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5418
(x25 ✅ )
-
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5421
(x25 ✅ )


### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
joeypoon authored Mar 8, 2024
1 parent 671b0b2 commit 82b9466
Showing 1 changed file with 108 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
*/

import type { Agent } from '@kbn/fleet-plugin/common';
import {
AGENT_HOSTNAME_CELL,
AGENT_POLICY_CELL,
TABLE_ROW_ACTIONS,
TABLE_ROW_ACTIONS_MENU,
} from '../../screens';
import { AGENT_HOSTNAME_CELL, TABLE_ROW_ACTIONS, TABLE_ROW_ACTIONS_MENU } from '../../screens';
import type { PolicyData } from '../../../../../common/endpoint/types';
import { APP_ENDPOINTS_PATH } from '../../../../../common/constants';
import { HOST_METADATA_LIST_ROUTE } from '../../../../../common/endpoint/constants';
import {
createAgentPolicyTask,
getAgentByHostName,
Expand All @@ -32,8 +28,7 @@ import { createEndpointHost } from '../../tasks/create_endpoint_host';
import { deleteAllLoadedEndpointData } from '../../tasks/delete_all_endpoint_data';
import { enableAllPolicyProtections } from '../../tasks/endpoint_policy';

// Failing: See https://github.com/elastic/kibana/issues/169903
describe.skip('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
describe('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
let indexedPolicy: IndexedFleetEndpointPolicyResponse;
let policy: PolicyData;
let createdHost: CreateAndEnrollEndpointHostResponse;
Expand All @@ -54,6 +49,10 @@ describe.skip('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
});
});

beforeEach(() => {
login();
});

after(() => {
if (createdHost) {
cy.task('destroyEndpointHost', createdHost);
Expand All @@ -68,10 +67,6 @@ describe.skip('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
}
});

beforeEach(() => {
login();
});

it('Shows endpoint on the list', () => {
loadPage(APP_ENDPOINTS_PATH);
cy.contains('Hosts running Elastic Defend').should('exist');
Expand All @@ -80,13 +75,67 @@ describe.skip('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
.should('have.text', createdHost.hostname);
});

it('should update endpoint policy on Endpoint', () => {
cy.intercept({ pathname: HOST_METADATA_LIST_ROUTE }).as('metadataRequest');
loadPage(APP_ENDPOINTS_PATH);

const agentIdPath = 'response.body.data[0].metadata.agent.id';
// ideally we should use applied policy instead: https://github.com/elastic/security-team/issues/8837
const policyVersionPath = 'response.body.data[0].policy_info.endpoint.revision';
cy.wait('@metadataRequest', { timeout: 30000 });
cy.get('@metadataRequest').its(agentIdPath).should('be.a', 'string').as('endpointId');
cy.get('@metadataRequest')
.its(policyVersionPath)
.should('be.a', 'number')
.as('originalPolicyRevision');
cy.get<string>('@endpointId')
.then((endpointId: string) => cy.get(`[data-endpoint-id=${endpointId}]`))
.as('endpointRow');

// policyNameCellLink be.visible alone can potentially click too quickly
// using TABLE_ROW_ACTIONS be.visible as a delay since it loads last on the row
cy.get('@endpointRow').findByTestSubj(TABLE_ROW_ACTIONS).should('be.visible');
cy.get('@endpointRow').findByTestSubj('policyNameCellLink').should('be.visible').click();
cy.location('pathname', { timeout: 20000 }).should(
'match',
/^\/app\/security\/administration\/policy\/[a-f0-9-]+\/settings$/
);

// make a change to enable save
cy.getByTestSubj('endpointPolicyForm-malware-blocklist-enableDisableSwitch')
.should('be.visible')
.as('blocklistSwitch');
cy.get('@blocklistSwitch').click();
cy.get('@blocklistSwitch').should('be.enabled');

cy.getByTestSubj('policyDetailsSaveButton').should('be.visible').click();
cy.getByTestSubj('policyDetailsConfirmModal').should('be.visible').click();
cy.getByTestSubj('confirmModalConfirmButton').should('be.visible').click();
cy.contains(/has been updated/);
cy.getByTestSubj('policyDetailsBackLink').should('be.visible').click();
cy.location('pathname', { timeout: 20000 }).should('equal', APP_ENDPOINTS_PATH);

// Assert disappearing 'Out-of-date' indicator, Success Policy Status and increased revision number
cy.get('@endpointRow')
.findByTestSubj('rowPolicyOutOfDate', { timeout: 25000 })
.should('not.exist'); // depends on the 10s auto-refresh

cy.get('@endpointRow').findByTestSubj('policyStatusCellLink').should('contain', 'Success');

cy.get<number>('@originalPolicyRevision').then((originalRevision: number) => {
const revisionRegex = new RegExp(`^rev\\. ${originalRevision + 1}$`);
cy.get('@endpointRow').findByTestSubj('policyListRevNo').contains(revisionRegex);
});
});

describe('Endpoint reassignment', () => {
let response: IndexedFleetEndpointPolicyResponse;
let initialAgentData: Agent;

before(() => {
getAgentByHostName(createdHost.hostname).then((agentData) => {
initialAgentData = agentData;
return initialAgentData;
});
getEndpointIntegrationVersion().then((version) => {
createAgentPolicyTask(version).then((data) => {
Expand All @@ -95,75 +144,63 @@ describe.skip('Endpoints page', { tags: ['@ess', '@serverless'] }, () => {
});
});

beforeEach(() => {
login();
});

after(() => {
afterEach(() => {
if (initialAgentData?.policy_id) {
reassignAgentPolicy(initialAgentData.id, initialAgentData.policy_id);
}
});

after(() => {
if (response) {
cy.task('deleteIndexedFleetEndpointPolicies', response);
}
});

it('User can reassign a single endpoint to a different Agent Configuration', () => {
cy.intercept({ pathname: HOST_METADATA_LIST_ROUTE }).as('metadataRequest');
loadPage(APP_ENDPOINTS_PATH);
cy.getByTestSubj(AGENT_HOSTNAME_CELL)
.filter(`:contains("${createdHost.hostname}")`)
.then((hostname) => {
const tableRow = hostname.parents('tr');

tableRow.find(`[data-test-subj=${TABLE_ROW_ACTIONS}`).trigger('click');
cy.getByTestSubj(TABLE_ROW_ACTIONS_MENU).contains('Reassign agent policy').click();
cy.getByTestSubj(FLEET_REASSIGN_POLICY_MODAL)
.find('select')
.select(response.agentPolicies[0].name);
cy.getByTestSubj(FLEET_REASSIGN_POLICY_MODAL_CONFIRM_BUTTON).click();
cy.getByTestSubj(AGENT_HOSTNAME_CELL)
.filter(`:contains("${createdHost.hostname}")`)
.should('exist');
cy.getByTestSubj(AGENT_HOSTNAME_CELL)
.filter(`:contains("${createdHost.hostname}")`)
.parents('tr')
.findByTestSubj(AGENT_POLICY_CELL)
.should('have.text', response.agentPolicies[0].name);
});
});
});

it('should update endpoint policy on Endpoint', () => {
const parseRevNumber = (revString: string) => Number(revString.match(/\d+/)?.[0]);

loadPage(APP_ENDPOINTS_PATH);

cy.getByTestSubj('policyListRevNo')
.first()
.invoke('text')
.then(parseRevNumber)
.then((initialRevisionNumber) => {
// Update policy
cy.getByTestSubj('policyNameCellLink').first().click();

cy.getByTestSubj('policyDetailsSaveButton').click();
cy.getByTestSubj('policyDetailsConfirmModal').should('exist');
cy.getByTestSubj('confirmModalConfirmButton').click();
cy.contains(/has been updated/);

cy.getByTestSubj('policyDetailsBackLink').click();

// Assert disappearing 'Out-of-date' indicator, Success Policy Status and increased revision number
cy.getByTestSubj('rowPolicyOutOfDate').should('exist');
cy.getByTestSubj('rowPolicyOutOfDate').should('not.exist'); // depends on the 10s auto-refresh

cy.getByTestSubj('policyStatusCellLink').first().should('contain', 'Success');

cy.getByTestSubj('policyListRevNo')
.first()
.invoke('text')
.then(parseRevNumber)
.should('equal', initialRevisionNumber + 1);
});
const agentIdPath = 'response.body.data[0].metadata.agent.id';
cy.wait('@metadataRequest', { timeout: 30000 })
.its(agentIdPath)
.should('be.a', 'string')
.as('endpointId');
cy.get<string>('@endpointId')
.then((endpointId: string) => cy.get(`[data-endpoint-id=${endpointId}]`))
.should('be.visible')
.as('endpointRow');

cy.get('@endpointRow')
.findByTestSubj(TABLE_ROW_ACTIONS)
.should('be.visible')
.trigger('click');
cy.getByTestSubj(TABLE_ROW_ACTIONS_MENU)
.should('be.visible')
.contains('Reassign agent policy')
.click();
cy.location('pathname', { timeout: 20000 }).should(
'match',
/^\/app\/fleet\/agents\/[a-f0-9-]+$/
);

cy.getByTestSubj(FLEET_REASSIGN_POLICY_MODAL)
.find('select')
.should('be.visible')
.as('reassignPolicySelect');
cy.get('@reassignPolicySelect').select(response.agentPolicies[0].name);
cy.get('@reassignPolicySelect').should('have.value', response.agentPolicies[0].id);

cy.getByTestSubj(FLEET_REASSIGN_POLICY_MODAL_CONFIRM_BUTTON)
.should('be.visible')
.and('be.enabled');
cy.getByTestSubj(FLEET_REASSIGN_POLICY_MODAL_CONFIRM_BUTTON).click();

// ideally we should use applied policy instead: https://github.com/elastic/security-team/issues/8837
const policyIdPath = 'response.body.data[0].policy_info.agent.configured.id';
// relies on multiple transforms so might take some extra time
cy.get('@metadataRequest', { timeout: 120000 })
.its(policyIdPath)
.should('equal', response.agentPolicies[0].id);
});
});
});

0 comments on commit 82b9466

Please sign in to comment.