Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EDR Workflows] Workflow Insights - Cypress #204562

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export type AssistantFeatureKey = keyof AssistantFeatures;
*/
export const defaultAssistantFeatures = Object.freeze({
assistantModelEvaluation: false,
defendInsights: false,
defendInsights: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* 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 {
createBedrockAIConnector,
deleteConnectors,
expectDefendInsightsApiToBeCalled,
expectPostDefendInsightsApiToBeCalled,
expectWorkflowInsightsApiToBeCalled,
interceptGetDefendInsightsApiCall,
interceptGetWorkflowInsightsApiCall,
interceptPostDefendInsightsApiCall,
setConnectorIdInLocalStorage,
stubDefendInsightsApiResponse,
stubPutWorkflowInsightsApiResponse,
stubWorkflowInsightsApiResponse,
validateUserGotRedirectedToEndpointDetails,
validateUserGotRedirectedToTrustedApps,
} from '../../tasks/insights';
import { loadEndpointDetailsFlyout, workflowInsightsSelectors } from '../../screens/insights';
import { indexEndpointHosts, type CyIndexEndpointHosts } from '../../tasks/index_endpoint_hosts';
import { login } from '../../tasks/login';

const {
addConnectorButtonExists,
insightsComponentExists,
chooseConnectorButtonExistsWithLabel,
selectConnector,
clickScanButton,
insightsResultExists,
insightsEmptyResultsCalloutDoesNotExist,
clickInsightsResultRemediationButton,
scanButtonShouldBe,
clickTrustedAppFormSubmissionButton,
} = workflowInsightsSelectors;

describe(
'Workflow Insights',
{
tags: [
'@ess',
'@serverless',
// skipped on MKI since feature flags are not supported there
'@skipInServerlessMKI',
],
env: {
ftrConfig: {
kbnServerArgs: [
`--xpack.securitySolution.enableExperimental=${JSON.stringify(['defendInsights'])}`,
],
},
},
},
() => {
const connectorName = 'TEST-CONNECTOR';
let loadedEndpoint: CyIndexEndpointHosts;
let endpointId: string;

// Since the endpoint is used only for displaying details flyout, we can use the same endpoint for all tests
before(() => {
indexEndpointHosts({ count: 1 }).then((indexedEndpoint) => {
loadedEndpoint = indexedEndpoint;
endpointId = indexedEndpoint.data.hosts[0].agent.id;
});
});

after(() => {
if (loadedEndpoint) {
loadedEndpoint.cleanup();
}
});

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

it('should render Insights section on endpoint flyout with option to define connectors', () => {
loadEndpointDetailsFlyout(endpointId);
insightsComponentExists();
addConnectorButtonExists();
});

describe('Workflow Insights first visit', () => {
let connectorId: string | undefined;
beforeEach(() => {
createBedrockAIConnector(connectorName).then((response) => {
connectorId = response.body.id;
});
});

afterEach(() => {
deleteConnectors();
connectorId = undefined;
});

it('should properly initialize workflow insights for the first time', () => {
interceptGetWorkflowInsightsApiCall();
interceptGetDefendInsightsApiCall();

loadEndpointDetailsFlyout(endpointId);

expectWorkflowInsightsApiToBeCalled();
expectDefendInsightsApiToBeCalled();

chooseConnectorButtonExistsWithLabel('Select a connector');
selectConnector(connectorId);
chooseConnectorButtonExistsWithLabel(connectorName);

scanButtonShouldBe('enabled');
});
});

describe('Workflow Insights consequent visit', () => {
beforeEach(() => {
createBedrockAIConnector(connectorName).then(setConnectorIdInLocalStorage);
});

afterEach(() => {
deleteConnectors();
});

it('should properly initialize workflow insights with a connector already defined', () => {
loadEndpointDetailsFlyout(endpointId);
chooseConnectorButtonExistsWithLabel(connectorName);
scanButtonShouldBe('enabled');
});

it('should disable Scan button if there is an ongoing scan', () => {
stubDefendInsightsApiResponse();
loadEndpointDetailsFlyout(endpointId);
scanButtonShouldBe('disabled');
});

it('should trigger insight generation on Scan button click', () => {
interceptPostDefendInsightsApiCall();
interceptGetWorkflowInsightsApiCall();
interceptGetDefendInsightsApiCall();

loadEndpointDetailsFlyout(endpointId);
clickScanButton();

expectPostDefendInsightsApiToBeCalled();
expectWorkflowInsightsApiToBeCalled();
expectDefendInsightsApiToBeCalled();
});

it('should render existing Insights', () => {
stubWorkflowInsightsApiResponse(endpointId);

loadEndpointDetailsFlyout(endpointId);

insightsResultExists();
insightsEmptyResultsCalloutDoesNotExist();
clickInsightsResultRemediationButton();

validateUserGotRedirectedToTrustedApps();
stubPutWorkflowInsightsApiResponse();
clickTrustedAppFormSubmissionButton();
validateUserGotRedirectedToEndpointDetails(endpointId);
});
});
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { loadPage } from '../tasks/common';

export const loadEndpointDetailsFlyout = (endpointId: string) =>
loadPage(
`/app/security/administration/endpoints?page_index=0&page_size=10&selected_endpoint=${endpointId}&show=details`
);

export const workflowInsightsSelectors = {
insightsComponentExists: () => cy.getByTestSubj('endpointDetailsInsightsWrapper').should('exist'),
addConnectorButtonExists: () => cy.getByTestSubj('addNewConnectorButton').should('exist'),
chooseConnectorButtonExistsWithLabel: (label: string) =>
cy.getByTestSubj('connector-selector').contains(label),
selectConnector: (connectorId?: string) => {
cy.getByTestSubj('connector-selector').click();
if (connectorId) return cy.getByTestSubj(connectorId).click();
},
selectScanButton: () => cy.getByTestSubj('workflowInsightsScanButton'),
scanButtonShouldBe: (state: 'enabled' | 'disabled') =>
workflowInsightsSelectors.selectScanButton().should(`be.${state}`),
clickScanButton: () => workflowInsightsSelectors.selectScanButton().click(),
insightsResultExists: (index = 0) =>
cy.getByTestSubj(`workflowInsightsResult-${index}`).should('exist'),
clickInsightsResultRemediationButton: (index = 0) =>
cy.getByTestSubj(`workflowInsightsResult-${index}-remediation`).click(),
insightsEmptyResultsCalloutDoesNotExist: () =>
cy.getByTestSubj('workflowInsightsEmptyResultsCallout').should('not.exist'),
clickTrustedAppFormSubmissionButton: () =>
cy.getByTestSubj('trustedAppsListPage-flyout-submitButton').click(),
};
Loading