-
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.
[Security Solution][Endpoint] Policy creation callback fixes + Improv…
…ed error handling in user manifest loop (#71269) * Clean up matcher types * Rework promise and error-handling in ManifestManager * Write tests for ingest callback and ensure policy is returned when errors occur * More tests for ingest callback * Update tests * Fix tests Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
b24632d
commit 3fc54e7
Showing
11 changed files
with
430 additions
and
191 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 { NewPackageConfig, PackageConfig } from './types/models/package_config'; | ||
|
||
export const createNewPackageConfigMock = () => { | ||
return { | ||
name: 'endpoint-1', | ||
description: '', | ||
namespace: 'default', | ||
enabled: true, | ||
config_id: '93c46720-c217-11ea-9906-b5b8a21b268e', | ||
output_id: '', | ||
package: { | ||
name: 'endpoint', | ||
title: 'Elastic Endpoint', | ||
version: '0.9.0', | ||
}, | ||
inputs: [], | ||
} as NewPackageConfig; | ||
}; | ||
|
||
export const createPackageConfigMock = () => { | ||
const newPackageConfig = createNewPackageConfigMock(); | ||
return { | ||
...newPackageConfig, | ||
id: 'c6d16e42-c32d-4dce-8a88-113cfe276ad1', | ||
version: 'abcd', | ||
revision: 1, | ||
updated_at: '2020-06-25T16:03:38.159292', | ||
updated_by: 'kibana', | ||
created_at: '2020-06-25T16:03:38.159292', | ||
created_by: 'kibana', | ||
inputs: [ | ||
{ | ||
config: {}, | ||
}, | ||
], | ||
} as PackageConfig; | ||
}; |
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/security_solution/server/endpoint/ingest_integration.test.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,91 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { loggerMock } from 'src/core/server/logging/logger.mock'; | ||
import { createNewPackageConfigMock } from '../../../ingest_manager/common/mocks'; | ||
import { factory as policyConfigFactory } from '../../common/endpoint/models/policy_config'; | ||
import { getManifestManagerMock } from './services/artifacts/manifest_manager/manifest_manager.mock'; | ||
import { getPackageConfigCreateCallback } from './ingest_integration'; | ||
|
||
describe('ingest_integration tests ', () => { | ||
describe('ingest_integration sanity checks', () => { | ||
test('policy is updated with manifest', async () => { | ||
const logger = loggerMock.create(); | ||
const manifestManager = getManifestManagerMock(); | ||
const callback = getPackageConfigCreateCallback(logger, manifestManager); | ||
const policyConfig = createNewPackageConfigMock(); | ||
const newPolicyConfig = await callback(policyConfig); | ||
expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); | ||
expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); | ||
expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual({ | ||
artifacts: { | ||
'endpoint-exceptionlist-linux-v1': { | ||
compression_algorithm: 'zlib', | ||
decoded_sha256: '1a8295e6ccb93022c6f5ceb8997b29f2912389b3b38f52a8f5a2ff7b0154b1bc', | ||
decoded_size: 287, | ||
encoded_sha256: 'c3dec543df1177561ab2aa74a37997ea3c1d748d532a597884f5a5c16670d56c', | ||
encoded_size: 133, | ||
encryption_algorithm: 'none', | ||
relative_url: | ||
'/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/1a8295e6ccb93022c6f5ceb8997b29f2912389b3b38f52a8f5a2ff7b0154b1bc', | ||
}, | ||
}, | ||
manifest_version: 'WzAsMF0=', | ||
schema_version: 'v1', | ||
}); | ||
}); | ||
|
||
test('policy is returned even if error is encountered during artifact sync', async () => { | ||
const logger = loggerMock.create(); | ||
const manifestManager = getManifestManagerMock(); | ||
manifestManager.syncArtifacts = jest.fn().mockRejectedValue([new Error('error updating')]); | ||
const lastDispatched = await manifestManager.getLastDispatchedManifest(); | ||
const callback = getPackageConfigCreateCallback(logger, manifestManager); | ||
const policyConfig = createNewPackageConfigMock(); | ||
const newPolicyConfig = await callback(policyConfig); | ||
expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); | ||
expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); | ||
expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual( | ||
lastDispatched.toEndpointFormat() | ||
); | ||
}); | ||
|
||
test('initial policy creation succeeds if snapshot retrieval fails', async () => { | ||
const logger = loggerMock.create(); | ||
const manifestManager = getManifestManagerMock(); | ||
const lastDispatched = await manifestManager.getLastDispatchedManifest(); | ||
manifestManager.getSnapshot = jest.fn().mockResolvedValue(null); | ||
const callback = getPackageConfigCreateCallback(logger, manifestManager); | ||
const policyConfig = createNewPackageConfigMock(); | ||
const newPolicyConfig = await callback(policyConfig); | ||
expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); | ||
expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); | ||
expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual( | ||
lastDispatched.toEndpointFormat() | ||
); | ||
}); | ||
|
||
test('subsequent policy creations succeed', async () => { | ||
const logger = loggerMock.create(); | ||
const manifestManager = getManifestManagerMock(); | ||
const snapshot = await manifestManager.getSnapshot(); | ||
manifestManager.getLastDispatchedManifest = jest.fn().mockResolvedValue(snapshot!.manifest); | ||
manifestManager.getSnapshot = jest.fn().mockResolvedValue({ | ||
manifest: snapshot!.manifest, | ||
diffs: [], | ||
}); | ||
const callback = getPackageConfigCreateCallback(logger, manifestManager); | ||
const policyConfig = createNewPackageConfigMock(); | ||
const newPolicyConfig = await callback(policyConfig); | ||
expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); | ||
expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); | ||
expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual( | ||
snapshot!.manifest.toEndpointFormat() | ||
); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.