[Security Solution][Admin][Policy] Adds policy list functional tests (#129786)

This commit is contained in:
Candace Park 2022-05-05 01:19:46 -04:00 committed by GitHub
parent 79fc3815a4
commit fe92ccfbc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 10 deletions

View file

@ -25,7 +25,7 @@ export const PolicyEndpointCount = memo<
policyId: string;
nonLinkCondition: boolean;
}
>(({ policyId, nonLinkCondition, children, ...otherProps }) => {
>(({ policyId, nonLinkCondition, 'data-test-subj': dataTestSubj, children, ...otherProps }) => {
const filterByPolicyQuery = `(language:kuery,query:'united.endpoint.Endpoint.policy.applied.id : "${policyId}"')`;
const { search } = useLocation();
const { getAppUrl } = useAppUrl();
@ -59,11 +59,15 @@ export const PolicyEndpointCount = memo<
const clickHandler = useNavigateByRouterEventHandler(toRoutePathWithBackOptions);
if (nonLinkCondition) {
return <EuiText size="s">{children}</EuiText>;
return (
<EuiText size="s" data-test-subj={`${dataTestSubj}_nonLink`}>
{children}
</EuiText>
);
}
return (
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiLink href={toRouteUrl} onClick={clickHandler} {...otherProps}>
<EuiLink href={toRouteUrl} data-test-subj={dataTestSubj} onClick={clickHandler} {...otherProps}>
{children}
</EuiLink>
);

View file

@ -99,15 +99,23 @@ describe('When on the policy list page', () => {
expect(policyNameCells).toBeTruthy();
expect(policyNameCells.length).toBe(5);
});
it('should show a avatar for the Created by column', () => {
it('should show an avatar and name for the Created by column', () => {
const expectedAvatarName = policies.items[0].created_by;
const createdByCells = renderResult.getAllByTestId('created-by-avatar');
const firstCreatedByName = renderResult.getAllByTestId('created-by-name')[0];
expect(createdByCells).toBeTruthy();
expect(createdByCells.length).toBe(5);
expect(createdByCells[0].textContent).toEqual(expectedAvatarName.charAt(0));
expect(firstCreatedByName.textContent).toEqual(expectedAvatarName);
});
it('should show a avatar for the Updated by column', () => {
it('should show an avatar and name for the Updated by column', () => {
const expectedAvatarName = policies.items[0].updated_by;
const updatedByCells = renderResult.getAllByTestId('updated-by-avatar');
const firstUpdatedByName = renderResult.getAllByTestId('updated-by-name')[0];
expect(updatedByCells).toBeTruthy();
expect(updatedByCells.length).toBe(5);
expect(updatedByCells[0].textContent).toEqual(expectedAvatarName.charAt(0));
expect(firstUpdatedByName.textContent).toEqual(expectedAvatarName);
});
it('should show the correct endpoint count', () => {
const endpointCount = renderResult.getAllByTestId('policyEndpointCountLink');

View file

@ -189,7 +189,9 @@ export const PolicyList = memo(() => {
<EuiAvatar name={name} data-test-subj={'created-by-avatar'} size="s" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s">{name}</EuiText>
<EuiText size="s" data-test-subj="created-by-name">
{name}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
);
@ -222,7 +224,9 @@ export const PolicyList = memo(() => {
<EuiAvatar name={name} data-test-subj={'updated-by-avatar'} size="s" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s">{name}</EuiText>
<EuiText size="s" data-test-subj="updated-by-name">
{name}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
);

View file

@ -82,7 +82,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await deleteAllDocsFromMetadataUnitedIndex(getService);
await pageObjects.endpoint.navigateToEndpointList();
});
it('finds no data in list and prompts onboarding to add policy', async () => {
await testSubjects.exists('emptyPolicyTable');
});
@ -99,7 +98,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
after(async () => {
await deleteAllDocsFromMetadataCurrentIndex(getService);
await deleteAllDocsFromMetadataUnitedIndex(getService);
await endpointTestResources.unloadEndpointData(indexedData);
if (indexedData) {
await endpointTestResources.unloadEndpointData(indexedData);
}
});
it('finds page title', async () => {

View file

@ -35,6 +35,7 @@ export default function (providerContext: FtrProviderContext) {
await endpointTestResources.installOrUpgradeEndpointFleetPackage();
});
loadTestFile(require.resolve('./endpoint_list'));
loadTestFile(require.resolve('./policy_list'));
loadTestFile(require.resolve('./policy_details'));
loadTestFile(require.resolve('./endpoint_telemetry'));
loadTestFile(require.resolve('./trusted_apps_list'));

View file

@ -331,6 +331,8 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});
it('should show event filters card and link should go back to policy', async () => {
await testSubjects.existOrFail('eventFilters-fleet-integration-card');
const eventFiltersCard = await testSubjects.find('eventFilters-fleet-integration-card');
await pageObjects.ingestManagerCreatePackagePolicy.scrollToCenterOfWindow(eventFiltersCard);
await (await testSubjects.find('eventFilters-link-to-exceptions')).click();
await testSubjects.existOrFail('policyDetailsPage');
await (await testSubjects.find('policyDetailsBackLink')).click();

View file

@ -0,0 +1,111 @@
/*
* 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 expect from '@kbn/expect';
import { IndexedHostsAndAlertsResponse } from '@kbn/security-solution-plugin/common/endpoint/index_data';
import { FtrProviderContext } from '../../ftr_provider_context';
import { PolicyTestResourceInfo } from '../../services/endpoint_policy';
export default function ({ getPageObjects, getService }: FtrProviderContext) {
const browser = getService('browser');
const pageObjects = getPageObjects([
'common',
'endpoint',
'policy',
'endpointPageUtils',
'ingestManagerCreatePackagePolicy',
'trustedApps',
]);
const testSubjects = getService('testSubjects');
const policyTestResources = getService('policyTestResources');
const endpointTestResources = getService('endpointTestResources');
describe('When on the Endpoint Policy List Page', () => {
before(async () => {
const endpointPackage = await policyTestResources.getEndpointPackage();
await endpointTestResources.setMetadataTransformFrequency('1s', endpointPackage.version);
await browser.refresh();
});
describe('with no policies', () => {
it('shows the empty page', async () => {
await pageObjects.policy.navigateToPolicyList();
await testSubjects.existOrFail('emptyPolicyTable');
});
it('navigates to Fleet and ensures the integration page is loaded correctly', async () => {
const fleetButton = await testSubjects.find('onboardingStartButton');
await fleetButton.click();
await testSubjects.existOrFail('createPackagePolicy_pageTitle');
expect(await testSubjects.getVisibleText('createPackagePolicy_pageTitle')).to.equal(
'Add Endpoint Security integration'
);
});
it('navigates back to the policy list page', async () => {
const cancelButton = await testSubjects.find('createPackagePolicy_cancelBackLink');
cancelButton.click();
await pageObjects.policy.ensureIsOnListPage();
});
});
describe('with policies', () => {
let indexedData: IndexedHostsAndAlertsResponse;
let policyInfo: PolicyTestResourceInfo;
before(async () => {
indexedData = await endpointTestResources.loadEndpointData();
policyInfo = await policyTestResources.createPolicy();
await browser.refresh();
});
after(async () => {
if (indexedData) {
await endpointTestResources.unloadEndpointData(indexedData);
}
if (policyInfo) {
await policyInfo.cleanup();
}
});
it('shows the policy list table', async () => {
await pageObjects.policy.navigateToPolicyList();
await testSubjects.existOrFail('policyListTable');
});
it('navigates to the policy details page when the policy name is clicked and returns back to the policy list page using the header back button', async () => {
const policyName = (await testSubjects.findAll('policyNameCellLink'))[0];
await policyName.click();
await pageObjects.policy.ensureIsOnDetailsPage();
const backButton = await testSubjects.find('policyDetailsBackLink');
await backButton.click();
await pageObjects.policy.ensureIsOnListPage();
});
describe('when the endpoint count link is clicked', () => {
it('navigates to the endpoint list page filtered by policy', async () => {
const endpointCount = (await testSubjects.findAll('policyEndpointCountLink'))[0];
await endpointCount.click();
await pageObjects.endpoint.ensureIsOnEndpointListPage();
});
it('admin searchbar contains the selected policy id', async () => {
const expectedPolicyId = indexedData.integrationPolicies[0].id;
await pageObjects.endpoint.ensureIsOnEndpointListPage();
expect(await testSubjects.getVisibleText('adminSearchBar')).to.equal(
`united.endpoint.Endpoint.policy.applied.id : "${expectedPolicyId}"`
);
});
it('endpoint table shows the endpoints associated with selected policy', async () => {
const expectedPolicyName = indexedData.integrationPolicies[0].name;
await pageObjects.endpoint.ensureIsOnEndpointListPage();
const policyName = (await testSubjects.findAll('policyNameCellLink'))[0];
expect(await policyName.getVisibleText()).to.be.equal(
expectedPolicyName.substring(0, expectedPolicyName.indexOf('-'))
);
});
it('returns back to the policy list page when the header back button is clicked', async () => {
await pageObjects.endpoint.ensureIsOnEndpointListPage();
const backButton = await testSubjects.find('endpointListBackLink');
await backButton.click();
await pageObjects.policy.ensureIsOnListPage();
});
});
});
});
}

View file

@ -25,6 +25,10 @@ export function EndpointPageProvider({ getService, getPageObjects }: FtrProvider
await pageObjects.header.waitUntilLoadingHasFinished();
},
async ensureIsOnEndpointListPage() {
await testSubjects.existOrFail('endpointPage');
},
async waitForTableToHaveData(dataTestSubj: string, timeout = 2000) {
await retry.waitForWithTimeout('table to have data', timeout, async () => {
const tableData = await pageObjects.endpointPageUtils.tableData(dataTestSubj);

View file

@ -14,6 +14,16 @@ export function EndpointPolicyPageProvider({ getService, getPageObjects }: FtrPr
const retryService = getService('retry');
return {
/**
* Navigates to the Endpoint Policy List page
*/
async navigateToPolicyList() {
await pageObjects.common.navigateToUrlWithBrowserHistory(
'securitySolutionManagement',
`/policy`
);
await pageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Navigates to the Endpoint Policy Details page
*
@ -27,6 +37,12 @@ export function EndpointPolicyPageProvider({ getService, getPageObjects }: FtrPr
await pageObjects.header.waitUntilLoadingHasFinished();
},
/**
* Ensures the current page is the policy list page
*/
async ensureIsOnListPage() {
await testSubjects.existOrFail('policyListPage');
},
/**
* Finds and returns the Policy Details Page Save button
*/
@ -127,7 +143,7 @@ export function EndpointPolicyPageProvider({ getService, getPageObjects }: FtrPr
/**
* Used when looking a the Ingest create/edit package policy pages. Finds the endpoint
* custom configuaration component
* custom configuration component
* @param onEditPage
*/
async findPackagePolicyEndpointCustomConfiguration(onEditPage: boolean = false) {