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

[Security Solution] Add endpoint policy revision number #83982

Merged
merged 3 commits into from
Nov 24, 2020
Merged
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 @@ -14,6 +14,8 @@ import {
EuiListGroupItem,
EuiIcon,
EuiText,
EuiFlexGroup,
EuiFlexItem,
} from '@elastic/eui';
import React, { memo, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -139,7 +141,31 @@ export const EndpointDetails = memo(
>
{details.Endpoint.policy.applied.name}
</EndpointPolicyLink>
{isPolicyOutOfDate(details.Endpoint.policy.applied, policyInfo) && <OutOfDate />}
<EuiFlexGroup gutterSize="s" alignItems="baseline">
{details.Endpoint.policy.applied.endpoint_policy_version && (
<EuiFlexItem grow={false}>
<EuiText
color="subdued"
size="xs"
style={{ whiteSpace: 'nowrap' }}
data-test-subj="policyDetailsRevNo"
>
<FormattedMessage
id="xpack.securitySolution.endpoint.details.policy.revisionNumber"
defaultMessage="rev. {revNumber}"
values={{
revNumber: details.Endpoint.policy.applied.endpoint_policy_version,
}}
/>
</EuiText>
</EuiFlexItem>
)}
{isPolicyOutOfDate(details.Endpoint.policy.applied, policyInfo) && (
<EuiFlexItem grow={false}>
<OutOfDate />
</EuiFlexItem>
)}
</EuiFlexGroup>
</>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ describe('when on the list page', () => {
HostInfo['metadata']['Endpoint']['policy']['applied']['status']
> = [];
let firstPolicyID: string;
let firstPolicyRev: number;
beforeEach(() => {
reactTestingLibrary.act(() => {
const mockedEndpointData = mockEndpointResultList({ total: 4 });
const hostListData = mockedEndpointData.hosts;
const queryStrategyVersion = mockedEndpointData.query_strategy_version;

firstPolicyID = hostListData[0].metadata.Endpoint.policy.applied.id;
firstPolicyRev = hostListData[0].metadata.Endpoint.policy.applied.endpoint_policy_version;

// add ability to change (immutable) policy
type DeepMutable<T> = { -readonly [P in keyof T]: DeepMutable<T[P]> };
Expand Down Expand Up @@ -402,6 +404,16 @@ describe('when on the list page', () => {
});
});
});

it('should show revision number', async () => {
const renderResult = render();
await reactTestingLibrary.act(async () => {
await middlewareSpy.waitForAction('serverReturnedEndpointList');
});
const firstPolicyRevElement = (await renderResult.findAllByTestId('policyListRevNo'))[0];
expect(firstPolicyRevElement).not.toBeNull();
expect(firstPolicyRevElement.textContent).toEqual(`rev. ${firstPolicyRev}`);
});
});
});

Expand Down Expand Up @@ -586,6 +598,15 @@ describe('when on the list page', () => {
);
});

it('should display policy revision number', async () => {
const renderResult = await renderAndWaitForData();
const policyDetailsRevElement = await renderResult.findByTestId('policyDetailsRevNo');
expect(policyDetailsRevElement).not.toBeNull();
expect(policyDetailsRevElement.textContent).toEqual(
`rev. ${hostDetails.metadata.Endpoint.policy.applied.endpoint_policy_version}`
);
});

it('should update the URL when policy name link is clicked', async () => {
const renderResult = await renderAndWaitForData();
const policyDetailsLink = await renderResult.findByTestId('policyDetailsValue');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export const EndpointList = () => {

const NOOP = useCallback(() => {}, []);

const PAD_LEFT: React.CSSProperties = { paddingLeft: '6px' };

const handleDeployEndpointsClick = useNavigateToAppEventHandler<AgentPolicyDetailsDeployAgentAction>(
'fleet',
{
Expand Down Expand Up @@ -337,8 +339,22 @@ export const EndpointList = () => {
{policy.name}
</EndpointPolicyLink>
</EuiToolTip>
{policy.endpoint_policy_version && (
<EuiText
color="subdued"
size="xs"
style={{ whiteSpace: 'nowrap', ...PAD_LEFT }}
data-test-subj="policyListRevNo"
>
<FormattedMessage
id="xpack.securitySolution.endpoint.list.policy.revisionNumber"
defaultMessage="rev. {revNumber}"
values={{ revNumber: policy.endpoint_policy_version }}
/>
</EuiText>
)}
{isPolicyOutOfDate(policy, item.policy_info) && (
<OutOfDate style={{ paddingLeft: '6px' }} data-test-subj="rowPolicyOutOfDate" />
<OutOfDate style={PAD_LEFT} data-test-subj="rowPolicyOutOfDate" />
)}
</>
);
Expand Down