-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Endpoint] Policy functional (integration) tests (#64803)
* Re-enable Policy Functional tests * Test service to provide endpoint policy test data - includes workaround to fleet integration service
- Loading branch information
1 parent
0730bae
commit 552bac5
Showing
6 changed files
with
196 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
x-pack/test/functional_endpoint/services/endpoint_policy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
import { | ||
CreateAgentConfigResponse, | ||
CreateDatasourceResponse, | ||
} from '../../../plugins/ingest_manager/common'; | ||
import { Immutable } from '../../../plugins/endpoint/common/types'; | ||
import { factory as policyConfigFactory } from '../../../plugins/endpoint/common/models/policy_config'; | ||
|
||
const INGEST_API_ROOT = '/api/ingest_manager'; | ||
const INGEST_API_AGENT_CONFIGS = `${INGEST_API_ROOT}/agent_configs`; | ||
const INGEST_API_AGENT_CONFIGS_DELETE = `${INGEST_API_AGENT_CONFIGS}/delete`; | ||
const INGEST_API_DATASOURCES = `${INGEST_API_ROOT}/datasources`; | ||
const INGEST_API_DATASOURCES_DELETE = `${INGEST_API_DATASOURCES}/delete`; | ||
|
||
/** | ||
* Holds information about the test resources created to support an Endpoint Policy | ||
*/ | ||
export interface PolicyTestResourceInfo { | ||
/** The Ingest agent configuration created */ | ||
agentConfig: Immutable<CreateAgentConfigResponse['item']>; | ||
/** The Ingest datasource created and added to agent configuration. | ||
* This is where Endpoint Policy is stored. | ||
*/ | ||
datasource: Immutable<CreateDatasourceResponse['item']>; | ||
/** will clean up (delete) the objects created (agent config + datasource) */ | ||
cleanup: () => Promise<void>; | ||
} | ||
|
||
export function EndpointPolicyTestResourcesProvider({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
|
||
return { | ||
/** | ||
* Creates an Ingest Agent Configuration and adds to it the Endpoint Datasource that | ||
* stores the Policy configuration data | ||
*/ | ||
async createPolicy(): Promise<PolicyTestResourceInfo> { | ||
// FIXME: Refactor after https://github.com/elastic/kibana/issues/64822 is fixed. `isInitialized` setup below should be deleted | ||
// Due to an issue in Ingest API, we first create the Fleet user. This avoids the Agent Config api throwing a 500 | ||
const isFleetSetupResponse = await supertest | ||
.get('/api/ingest_manager/fleet/setup') | ||
.set('kbn-xsrf', 'xxx') | ||
.expect(200); | ||
if (!isFleetSetupResponse.body.isInitialized) { | ||
await supertest | ||
.post('/api/ingest_manager/fleet/setup') | ||
.set('kbn-xsrf', 'xxx') | ||
.send() | ||
.expect(200); | ||
} | ||
|
||
// create agent config | ||
const { | ||
body: { item: agentConfig }, | ||
}: { body: CreateAgentConfigResponse } = await supertest | ||
.post(INGEST_API_AGENT_CONFIGS) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ name: 'East Coast', description: 'East Coast call center', namespace: '' }) | ||
.expect(200); | ||
|
||
// create datasource and associated it to agent config | ||
const { | ||
body: { item: datasource }, | ||
}: { body: CreateDatasourceResponse } = await supertest | ||
.post(INGEST_API_DATASOURCES) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ | ||
name: 'Protect East Coast', | ||
description: 'Protect the worlds data - but in the East Coast', | ||
config_id: agentConfig.id, | ||
enabled: true, | ||
output_id: '', | ||
inputs: [ | ||
// TODO: should we retrieve the latest Endpoint Package and build the input (policy) from that? | ||
{ | ||
type: 'endpoint', | ||
enabled: true, | ||
streams: [], | ||
config: { | ||
policy: { | ||
value: policyConfigFactory(), | ||
}, | ||
}, | ||
}, | ||
], | ||
namespace: '', | ||
package: { | ||
name: 'endpoint', | ||
title: 'Elastic Endpoint', | ||
version: '1.0.0', | ||
}, | ||
}) | ||
.expect(200); | ||
|
||
return { | ||
agentConfig, | ||
datasource, | ||
async cleanup() { | ||
// Delete Datasource | ||
await supertest | ||
.post(INGEST_API_DATASOURCES_DELETE) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ datasourceIds: [datasource.id] }) | ||
.expect(200); | ||
|
||
// Delete Agent config | ||
await supertest | ||
.post(INGEST_API_AGENT_CONFIGS_DELETE) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ agentConfigId: agentConfig.id }) | ||
.expect(200); | ||
}, | ||
}; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { services as xPackFunctionalServices } from '../../functional/services'; | ||
import { EndpointPolicyTestResourcesProvider } from './endpoint_policy'; | ||
|
||
export const services = { | ||
...xPackFunctionalServices, | ||
policyTestResources: EndpointPolicyTestResourcesProvider, | ||
}; |