Skip to content

Commit

Permalink
[Security Solution] Filter Default policy details (elastic#76112) (el…
Browse files Browse the repository at this point in the history
  • Loading branch information
pzl authored Sep 4, 2020
1 parent 6d649dd commit 8b400c1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { getHostPolicyResponseHandler } from './handlers';

export const BASE_POLICY_RESPONSE_ROUTE = `/api/endpoint/policy_response`;

export const INITIAL_POLICY_ID = '00000000-0000-0000-0000-000000000000';

export function registerPolicyRoutes(router: IRouter, endpointAppContext: EndpointAppContext) {
router.get(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { GetPolicyResponseSchema } from '../../../../common/endpoint/schema/policy';
import { getESQueryPolicyResponseByHostID } from './service';

describe('test policy handlers schema', () => {
it('validate that get policy response query schema', async () => {
Expand All @@ -17,3 +18,21 @@ describe('test policy handlers schema', () => {
expect(() => GetPolicyResponseSchema.query.validate({})).toThrowError();
});
});

describe('test policy query', () => {
it('queries for the correct host', async () => {
const hostID = 'f757d3c0-e874-11ea-9ad9-015510b487f4';
const query = getESQueryPolicyResponseByHostID(hostID, 'anyindex');
expect(query.body.query.bool.filter.term).toEqual({ 'host.id': hostID });
});

it('filters out initial policy by ID', async () => {
const query = getESQueryPolicyResponseByHostID(
'f757d3c0-e874-11ea-9ad9-015510b487f4',
'anyindex'
);
expect(query.body.query.bool.must_not.term).toEqual({
'Endpoint.policy.applied.id': '00000000-0000-0000-0000-000000000000',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@
import { SearchResponse } from 'elasticsearch';
import { ILegacyScopedClusterClient } from 'kibana/server';
import { GetHostPolicyResponse, HostPolicyResponse } from '../../../../common/endpoint/types';
import { INITIAL_POLICY_ID } from './index';

export function getESQueryPolicyResponseByHostID(hostID: string, index: string) {
return {
body: {
query: {
match: {
'host.id': hostID,
bool: {
filter: {
term: {
'host.id': hostID,
},
},
must_not: {
term: {
'Endpoint.policy.applied.id': INITIAL_POLICY_ID,
},
},
},
},
sort: [
Expand Down

0 comments on commit 8b400c1

Please sign in to comment.