Skip to content

Commit

Permalink
[Security Solution] fix tests for unique policy names
Browse files Browse the repository at this point in the history
  • Loading branch information
joeypoon committed Nov 10, 2021
1 parent 145ce01 commit 7c19447
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { Client } from '@elastic/elasticsearch';
import { cloneDeep, merge } from 'lodash';
import { AxiosResponse } from 'axios';
import uuid from 'uuid';
// eslint-disable-next-line import/no-extraneous-dependencies
import { KbnClient } from '@kbn/test';
import { DeleteByQueryResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
Expand Down Expand Up @@ -139,12 +140,13 @@ export async function indexEndpointHostDocs({

if (enrollFleet) {
const { id: appliedPolicyId, name: appliedPolicyName } = hostMetadata.Endpoint.policy.applied;
const uniqueAppliedPolicyName = `${appliedPolicyName}-${uuid.v4()}`;

// If we don't yet have a "real" policy record, then create it now in ingest (package config)
if (!realPolicies[appliedPolicyId]) {
const createdPolicies = await indexFleetEndpointPolicy(
kbnClient,
appliedPolicyName,
uniqueAppliedPolicyName,
epmEndpointPackage.version
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(agentFullPolicy.inputs).to.eql([
getExpectedAgentPolicyEndpointInput({
id: policyInfo.packagePolicy.id,
name: policyInfo.packagePolicy.name,
meta: {
package: {
version: policyInfo.packageInfo.version,
Expand Down Expand Up @@ -447,6 +448,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(agentFullPolicy.inputs).to.eql([
getExpectedAgentPolicyEndpointInput({
id: policyInfo.packagePolicy.id,
name: policyInfo.packagePolicy.name,
meta: {
package: {
version: policyInfo.packageInfo.version,
Expand Down Expand Up @@ -485,6 +487,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(agentFullPolicyUpdated.inputs).to.eql([
getExpectedAgentPolicyEndpointInput({
id: policyInfo.packagePolicy.id,
name: policyInfo.packagePolicy.name,
revision: 3,
meta: {
package: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import uuid from 'uuid';
import { FtrProviderContext } from '../ftr_provider_context';
import {
CreateAgentPolicyRequest,
Expand Down Expand Up @@ -161,7 +162,7 @@ export function EndpointPolicyTestResourcesProvider({ getService }: FtrProviderC
let agentPolicy: CreateAgentPolicyResponse['item'];
try {
const newAgentPolicyData: CreateAgentPolicyRequest['body'] = {
name: 'East Coast',
name: `East Coast ${uuid.v4()}`,
description: 'East Coast call center',
namespace: 'default',
};
Expand All @@ -182,7 +183,7 @@ export function EndpointPolicyTestResourcesProvider({ getService }: FtrProviderC
let packagePolicy: CreatePackagePolicyResponse['item'];
try {
const newPackagePolicyData: CreatePackagePolicyRequest['body'] = {
name: 'Protect East Coast',
name: `Protect East Coast ${uuid.v4()}`,
description: 'Protect the worlds data - but in the East Coast',
policy_id: agentPolicy!.id,
enabled: true,
Expand Down

0 comments on commit 7c19447

Please sign in to comment.