diff --git a/x-pack/plugins/endpoint/common/generate_data.ts b/x-pack/plugins/endpoint/common/generate_data.ts index 1d1d02fb45f0..4f5a6eaeb0a5 100644 --- a/x-pack/plugins/endpoint/common/generate_data.ts +++ b/x-pack/plugins/endpoint/common/generate_data.ts @@ -14,7 +14,7 @@ import { OSFields, PolicyData, HostPolicyResponse, - PolicyResponseActionStatus, + HostPolicyResponseActionStatus, } from './types'; import { factory as policyFactory } from './models/policy_config'; @@ -540,23 +540,23 @@ export class EndpointDocGenerator { applied: { version: '1.0.0', id: '17d4b81d-9940-4b64-9de5-3e03ef1fb5cf', - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, response: { configurations: { malware: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, concerned_actions: ['download_model', 'workflow', 'a_custom_future_action'], }, events: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, concerned_actions: ['ingest_events_config', 'workflow'], }, logging: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, concerned_actions: ['configure_elasticsearch_connection'], }, streaming: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, concerned_actions: [ 'detect_file_open_events', 'download_global_artifacts', @@ -566,31 +566,31 @@ export class EndpointDocGenerator { }, actions: { download_model: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, message: 'model downloaded', }, ingest_events_config: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, message: 'no action taken', }, workflow: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, message: 'the flow worked well', }, a_custom_future_action: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, message: 'future message', }, configure_elasticsearch_connection: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, message: 'some message', }, detect_file_open_events: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, message: 'some message', }, download_global_artifacts: { - status: PolicyResponseActionStatus.success, + status: HostPolicyResponseActionStatus.success, message: 'some message', }, }, diff --git a/x-pack/plugins/endpoint/common/types.ts b/x-pack/plugins/endpoint/common/types.ts index 9f4ac0f75477..4da4f9bc797c 100644 --- a/x-pack/plugins/endpoint/common/types.ts +++ b/x-pack/plugins/endpoint/common/types.ts @@ -577,7 +577,7 @@ export type NewPolicyData = NewDatasource & { /** * the possible status for actions, configurations and overall Policy Response */ -export enum PolicyResponseActionStatus { +export enum HostPolicyResponseActionStatus { success = 'success', failure = 'failure', warning = 'warning', @@ -587,7 +587,7 @@ export enum PolicyResponseActionStatus { * The details of a given action */ interface HostPolicyResponseActionDetails { - status: PolicyResponseActionStatus; + status: HostPolicyResponseActionStatus; message: string; } @@ -621,7 +621,7 @@ interface HostPolicyResponseActions { } interface HostPolicyResponseConfigurationStatus { - status: PolicyResponseActionStatus; + status: HostPolicyResponseActionStatus; concerned_actions: Array; } @@ -652,7 +652,7 @@ export interface HostPolicyResponse { applied: { version: string; id: string; - status: PolicyResponseActionStatus; + status: HostPolicyResponseActionStatus; response: { configurations: { malware: HostPolicyResponseConfigurationStatus; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/hosts/details/host_details.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/hosts/details/host_details.tsx index e876920b0ff1..ce4d07816861 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/hosts/details/host_details.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/hosts/details/host_details.tsx @@ -90,7 +90,10 @@ export const HostDetails = memo(({ details }: { details: HostMetadata }) => { defaultMessage: 'Policy Status', }), description: ( - + {/* eslint-disable-next-line @elastic/eui/href-or-on-click */} { + const docGenerator = new EndpointDocGenerator(); let render: () => ReturnType; let history: AppContextTestRender['history']; let store: AppContextTestRender['store']; @@ -91,6 +93,19 @@ describe('when on the hosts page', () => { describe('when there is a selected host in the url', () => { let hostDetails: HostInfo; + const dispatchServerReturnedHostPolicyResponse = ( + overallStatus: HostPolicyResponseActionStatus = HostPolicyResponseActionStatus.success + ) => { + const policyResponse = docGenerator.generatePolicyResponse(); + policyResponse.endpoint.policy.applied.status = overallStatus; + store.dispatch({ + type: 'serverReturnedHostPolicyResponse', + payload: { + policy_response: policyResponse, + }, + }); + }; + beforeEach(() => { const { host_status, @@ -137,7 +152,6 @@ describe('when on the hosts page', () => { const renderResult = render(); const policyStatusLink = await renderResult.findByTestId('policyStatusValue'); expect(policyStatusLink).not.toBeNull(); - expect(policyStatusLink.textContent).toEqual('Success'); expect(policyStatusLink.getAttribute('href')).toEqual( '?selected_host=1&show=policy_response' ); @@ -152,10 +166,58 @@ describe('when on the hosts page', () => { const changedUrlAction = await userChangedUrlChecker; expect(changedUrlAction.payload.search).toEqual('?selected_host=1&show=policy_response'); }); - it.todo('should display Success overall policy status'); - it.todo('should display Warning overall policy status'); - it.todo('should display Failed overall policy status'); - it.todo('should display Unknown overall policy status'); + it('should display Success overall policy status', async () => { + const renderResult = render(); + const policyStatusLink = await renderResult.findByTestId('policyStatusValue'); + expect(policyStatusLink.textContent).toEqual('Success'); + + const policyStatusHealth = await renderResult.findByTestId('policyStatusHealth'); + expect( + policyStatusHealth.querySelector('[data-euiicon-type][color="success"]') + ).not.toBeNull(); + }); + it('should display Warning overall policy status', async () => { + const renderResult = render(); + await middlewareSpy.waitForAction('serverReturnedHostPolicyResponse'); + reactTestingLibrary.act(() => { + dispatchServerReturnedHostPolicyResponse(HostPolicyResponseActionStatus.warning); + }); + const policyStatusLink = await renderResult.findByTestId('policyStatusValue'); + expect(policyStatusLink.textContent).toEqual('Warning'); + + const policyStatusHealth = await renderResult.findByTestId('policyStatusHealth'); + expect( + policyStatusHealth.querySelector('[data-euiicon-type][color="warning"]') + ).not.toBeNull(); + }); + it('should display Failed overall policy status', async () => { + const renderResult = render(); + await middlewareSpy.waitForAction('serverReturnedHostPolicyResponse'); + reactTestingLibrary.act(() => { + dispatchServerReturnedHostPolicyResponse(HostPolicyResponseActionStatus.failure); + }); + const policyStatusLink = await renderResult.findByTestId('policyStatusValue'); + expect(policyStatusLink.textContent).toEqual('Failed'); + + const policyStatusHealth = await renderResult.findByTestId('policyStatusHealth'); + expect( + policyStatusHealth.querySelector('[data-euiicon-type][color="danger"]') + ).not.toBeNull(); + }); + it('should display Unknown overall policy status', async () => { + const renderResult = render(); + await middlewareSpy.waitForAction('serverReturnedHostPolicyResponse'); + reactTestingLibrary.act(() => { + dispatchServerReturnedHostPolicyResponse('' as HostPolicyResponseActionStatus); + }); + const policyStatusLink = await renderResult.findByTestId('policyStatusValue'); + expect(policyStatusLink.textContent).toEqual('Unknown'); + + const policyStatusHealth = await renderResult.findByTestId('policyStatusHealth'); + expect( + policyStatusHealth.querySelector('[data-euiicon-type][color="subdued"]') + ).not.toBeNull(); + }); it('should include the link to logs', async () => { const renderResult = render(); const linkToLogs = await renderResult.findByTestId('hostDetailsLinkToLogs');