Skip to content

Commit

Permalink
[EDR Workflows][tests] Improve artifacts mocked data CY (#189783)
Browse files Browse the repository at this point in the history
## Summary

- unskip `artifacts_mocked_data.cy` test
- make test cases independent
- fix small test bug: check the correct dataset when updating artifacts

flaky runner has passed, see comments

---------

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
gergoabraham and elasticmachine authored Aug 5, 2024
1 parent 5267f4a commit 986e760
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { login, ROLE } from '../../tasks/login';
import { loadPage } from '../../tasks/common';

import { getArtifactsListTestsData } from '../../fixtures/artifacts_page';
import { removeAllArtifacts } from '../../tasks/artifacts';
import {
createArtifactList,
createPerPolicyArtifact,
removeAllArtifacts,
} from '../../tasks/artifacts';
import { performUserActions } from '../../tasks/perform_user_actions';
import { indexEndpointHosts } from '../../tasks/index_endpoint_hosts';
import type { ReturnTypeFromChainable } from '../../types';
Expand Down Expand Up @@ -38,7 +42,9 @@ describe('Artifacts pages', { tags: ['@ess', '@serverless', '@skipInServerlessMK
indexEndpointHosts().then((indexEndpoints) => {
endpointData = indexEndpoints;
});
});

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

Expand All @@ -50,116 +56,124 @@ describe('Artifacts pages', { tags: ['@ess', '@serverless', '@skipInServerlessMK
});

for (const testData of getArtifactsListTestsData()) {
// FLAKY: https://github.com/elastic/kibana/issues/183718
// FLAKY: https://github.com/elastic/kibana/issues/183719
// FLAKY: https://github.com/elastic/kibana/issues/183720
describe.skip(`When on the ${testData.title} entries list`, () => {
it(`no access - should show no privileges callout`, () => {
loginWithoutAccess(`/app/security/administration/${testData.urlPath}`);
cy.getByTestSubj('noPrivilegesPage').should('exist');
cy.getByTestSubj('empty-page-feature-action').should('exist');
cy.getByTestSubj(testData.emptyState).should('not.exist');
cy.getByTestSubj(`${testData.pagePrefix}-emptyState-addButton`).should('not.exist');
});

it(
`read - should show empty state page if there is no ${testData.title} entry and the add button does not exist`,
// there is no such role in Serverless environment that only reads artifacts
{ tags: ['@skipInServerless'] },
() => {
loginWithReadAccess(
testData.privilegePrefix,
`/app/security/administration/${testData.urlPath}`
);
cy.getByTestSubj(testData.emptyState).should('exist');
describe(`When on the ${testData.title} entries list`, () => {
describe('given there are no artifacts yet', () => {
it(`no access - should show no privileges callout`, () => {
loginWithoutAccess(`/app/security/administration/${testData.urlPath}`);
cy.getByTestSubj('noPrivilegesPage').should('exist');
cy.getByTestSubj('empty-page-feature-action').should('exist');
cy.getByTestSubj(testData.emptyState).should('not.exist');
cy.getByTestSubj(`${testData.pagePrefix}-emptyState-addButton`).should('not.exist');
}
);

it(`write - should show empty state page if there is no ${testData.title} entry and the add button exists`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
cy.getByTestSubj(testData.emptyState).should('exist');
cy.getByTestSubj(`${testData.pagePrefix}-emptyState-addButton`).should('exist');
});

it(`write - should create new ${testData.title} entry`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
// Opens add flyout
cy.getByTestSubj(`${testData.pagePrefix}-emptyState-addButton`).click();
});

it(
`read - should show empty state page if there is no ${testData.title} entry and the add button does not exist`,
// there is no such role in Serverless environment that only reads artifacts
{ tags: ['@skipInServerless'] },
() => {
loginWithReadAccess(
testData.privilegePrefix,
`/app/security/administration/${testData.urlPath}`
);
cy.getByTestSubj(testData.emptyState).should('exist');
cy.getByTestSubj(`${testData.pagePrefix}-emptyState-addButton`).should('not.exist');
}
);

it(`write - should show empty state page if there is no ${testData.title} entry and the add button exists`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
cy.getByTestSubj(testData.emptyState).should('exist');
cy.getByTestSubj(`${testData.pagePrefix}-emptyState-addButton`).should('exist');
});

performUserActions(testData.create.formActions);
it(`write - should create new ${testData.title} entry`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
// Opens add flyout
cy.getByTestSubj(`${testData.pagePrefix}-emptyState-addButton`).click();

// Submit create artifact form
cy.getByTestSubj(`${testData.pagePrefix}-flyout-submitButton`).click();
performUserActions(testData.create.formActions);

// Check new artifact is in the list
for (const checkResult of testData.create.checkResults) {
cy.getByTestSubj(checkResult.selector).should('have.text', checkResult.value);
}
// Submit create artifact form
cy.getByTestSubj(`${testData.pagePrefix}-flyout-submitButton`).click();

// Title is shown after adding an item
cy.getByTestSubj('header-page-title').contains(testData.title);
});
// Check new artifact is in the list
for (const checkResult of testData.create.checkResults) {
cy.getByTestSubj(checkResult.selector).should('have.text', checkResult.value);
}

it(
`read - should not be able to update/delete an existing ${testData.title} entry`,
// there is no such role in Serverless environment that only reads artifacts
{ tags: ['@skipInServerless'] },
() => {
loginWithReadAccess(
testData.privilegePrefix,
`/app/security/administration/${testData.urlPath}`
);
// Title is shown after adding an item
cy.getByTestSubj('header-page-title').contains(testData.title);
cy.getByTestSubj(`${testData.pagePrefix}-card-header-actions-button`).should('not.exist');
cy.getByTestSubj(`${testData.pagePrefix}-card-cardEditAction`).should('not.exist');
cy.getByTestSubj(`${testData.pagePrefix}-card-cardDeleteAction`).should('not.exist');
}
);

it(
`read - should not be able to create a new ${testData.title} entry`,
// there is no such role in Serverless environment that only reads artifacts
{ tags: ['@skipInServerless'] },
() => {
loginWithReadAccess(
testData.privilegePrefix,
`/app/security/administration/${testData.urlPath}`
);
cy.getByTestSubj('header-page-title').contains(testData.title);
cy.getByTestSubj(`${testData.pagePrefix}-pageAddButton`).should('not.exist');
}
);

it(`write - should be able to update an existing ${testData.title} entry`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
// Opens edit flyout
cy.getByTestSubj(`${testData.pagePrefix}-card-header-actions-button`).click();
cy.getByTestSubj(`${testData.pagePrefix}-card-cardEditAction`).click();

performUserActions(testData.update.formActions);

// Submit edit artifact form
cy.getByTestSubj(`${testData.pagePrefix}-flyout-submitButton`).click();

for (const checkResult of testData.create.checkResults) {
cy.getByTestSubj(checkResult.selector).should('have.text', checkResult.value);
}

// Title still shown after editing an item
cy.getByTestSubj('header-page-title').contains(testData.title);
});
});

it(`write - should be able to delete the existing ${testData.title} entry`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
// Remove it
cy.getByTestSubj(`${testData.pagePrefix}-card-header-actions-button`).click();
cy.getByTestSubj(`${testData.pagePrefix}-card-cardDeleteAction`).click();
cy.getByTestSubj(`${testData.pagePrefix}-deleteModal-submitButton`).click();
// No card visible after removing it
cy.getByTestSubj(testData.delete.card).should('not.exist');
// Empty state is displayed after removing last item
cy.getByTestSubj(testData.emptyState).should('exist');
describe('given there is an existing artifact', () => {
beforeEach(() => {
createArtifactList(testData.createRequestBody.list_id);
createPerPolicyArtifact(testData.artifactName, testData.createRequestBody);
});

it(
`read - should not be able to update/delete an existing ${testData.title} entry`,
// there is no such role in Serverless environment that only reads artifacts
{ tags: ['@skipInServerless'] },
() => {
loginWithReadAccess(
testData.privilegePrefix,
`/app/security/administration/${testData.urlPath}`
);
cy.getByTestSubj('header-page-title').contains(testData.title);
cy.getByTestSubj(`${testData.pagePrefix}-card-header-actions-button`).should(
'not.exist'
);
cy.getByTestSubj(`${testData.pagePrefix}-card-cardEditAction`).should('not.exist');
cy.getByTestSubj(`${testData.pagePrefix}-card-cardDeleteAction`).should('not.exist');
}
);

it(
`read - should not be able to create a new ${testData.title} entry`,
// there is no such role in Serverless environment that only reads artifacts
{ tags: ['@skipInServerless'] },
() => {
loginWithReadAccess(
testData.privilegePrefix,
`/app/security/administration/${testData.urlPath}`
);
cy.getByTestSubj('header-page-title').contains(testData.title);
cy.getByTestSubj(`${testData.pagePrefix}-pageAddButton`).should('not.exist');
}
);

it(`write - should be able to update an existing ${testData.title} entry`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
// Opens edit flyout
cy.getByTestSubj(`${testData.pagePrefix}-card-header-actions-button`).click();
cy.getByTestSubj(`${testData.pagePrefix}-card-cardEditAction`).click();

performUserActions(testData.update.formActions);

// Submit edit artifact form
cy.getByTestSubj(`${testData.pagePrefix}-flyout-submitButton`).click();

for (const checkResult of testData.update.checkResults) {
cy.getByTestSubj(checkResult.selector).should('have.text', checkResult.value);
}

// Title still shown after editing an item
cy.getByTestSubj('header-page-title').contains(testData.title);
});

it(`write - should be able to delete the existing ${testData.title} entry`, () => {
loginWithWriteAccess(`/app/security/administration/${testData.urlPath}`);
// Remove it
cy.getByTestSubj(`${testData.pagePrefix}-card-header-actions-button`).click();
cy.getByTestSubj(`${testData.pagePrefix}-card-cardDeleteAction`).click();
cy.getByTestSubj(`${testData.pagePrefix}-deleteModal-submitButton`).click();
// No card visible after removing it
cy.getByTestSubj(testData.delete.card).should('not.exist');
// Empty state is displayed after removing last item
cy.getByTestSubj(testData.emptyState).should('exist');
});
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [
{
selector: 'trustedAppsListPage-card-criteriaConditions',
value:
'OSIS WindowsAND file.pathis one of\nc:\\randomFolder\\randomFile.exe\nc:\\randomFolder\\randomFile2.exe',
' OSIS WindowsAND process.executable.caselessIS c:\\randomFolder\\randomFile.exe, c:\\randomFolder\\randomFile2.exe',
},
{
selector: 'trustedAppsListPage-card-header-title',
Expand Down Expand Up @@ -281,10 +281,10 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [
list_id: ENDPOINT_ARTIFACT_LISTS.eventFilters.id,
entries: [
{
field: 'destination.ip',
field: 'agent.id',
operator: 'included',
type: 'match',
value: '1.2.3.4',
value: 'mr agent',
},
],
os_types: ['windows'],
Expand Down Expand Up @@ -382,7 +382,7 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [
{
selector: 'blocklistPage-card-criteriaConditions',
value:
'OSIS WindowsAND file.path.caselessis one of\nc:\\randomFolder\\randomFile.exe\nc:\\randomFolder\\randomFile2.exe',
' OSIS WindowsAND file.path.caselessis one of c:\\randomFolder\\randomFile.exe c:\\randomFolder\\randomFile2.exe',
},
{
selector: 'blocklistPage-card-header-title',
Expand All @@ -404,16 +404,10 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [
list_id: ENDPOINT_ARTIFACT_LISTS.blocklists.id,
entries: [
{
field: 'file.Ext.code_signature',
entries: [
{
field: 'subject_name',
value: ['wegwergwegw'],
type: 'match_any',
operator: 'included',
},
],
type: 'nested',
field: 'file.hash.sha256',
value: ['a4370c0cf81686c0b696fa6261c9d3e0d810ae704ab8301839dffd5d5112f476'],
type: 'match_any',
operator: 'included',
},
],
os_types: ['windows'],
Expand Down Expand Up @@ -484,7 +478,7 @@ export const getArtifactsListTestsData = (): ArtifactsFixtureType[] => [
checkResults: [
{
selector: 'hostIsolationExceptionsListPage-card-criteriaConditions',
value: 'OSIS Windows, Linux, Mac\nAND destination.ipIS 2.2.2.2/24',
value: ' OSIS Windows, Linux, MacAND destination.ipIS 2.2.2.2/24',
},
{
selector: 'hostIsolationExceptionsListPage-card-header-title',
Expand Down

0 comments on commit 986e760

Please sign in to comment.