|
4 | 4 | * you may not use this file except in compliance with the Elastic License. |
5 | 5 | */ |
6 | 6 |
|
7 | | -// eslint-disable-next-line @kbn/eslint/no-restricted-paths |
8 | | -import { loggerMock } from 'src/core/server/logging/logger.mock'; |
| 7 | +import { loggingSystemMock } from 'src/core/server/mocks'; |
9 | 8 | import { createNewPackageConfigMock } from '../../../ingest_manager/common/mocks'; |
10 | 9 | import { factory as policyConfigFactory } from '../../common/endpoint/models/policy_config'; |
11 | | -import { getManifestManagerMock } from './services/artifacts/manifest_manager/manifest_manager.mock'; |
| 10 | +import { |
| 11 | + getManifestManagerMock, |
| 12 | + ManifestManagerMockType, |
| 13 | +} from './services/artifacts/manifest_manager/manifest_manager.mock'; |
12 | 14 | import { getPackageConfigCreateCallback } from './ingest_integration'; |
| 15 | +import { ManifestConstants } from './lib/artifacts'; |
13 | 16 |
|
14 | 17 | describe('ingest_integration tests ', () => { |
15 | 18 | describe('ingest_integration sanity checks', () => { |
16 | | - test('policy is updated with manifest', async () => { |
17 | | - const logger = loggerMock.create(); |
18 | | - const manifestManager = getManifestManagerMock(); |
| 19 | + test('policy is updated with initial manifest', async () => { |
| 20 | + const logger = loggingSystemMock.create().get('ingest_integration.test'); |
| 21 | + const manifestManager = getManifestManagerMock({ |
| 22 | + mockType: ManifestManagerMockType.InitialSystemState, |
| 23 | + }); |
| 24 | + |
19 | 25 | const callback = getPackageConfigCreateCallback(logger, manifestManager); |
20 | | - const policyConfig = createNewPackageConfigMock(); |
21 | | - const newPolicyConfig = await callback(policyConfig); |
| 26 | + const policyConfig = createNewPackageConfigMock(); // policy config without manifest |
| 27 | + const newPolicyConfig = await callback(policyConfig); // policy config WITH manifest |
| 28 | + |
22 | 29 | expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); |
23 | 30 | expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); |
24 | 31 | expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual({ |
25 | 32 | artifacts: { |
26 | 33 | 'endpoint-exceptionlist-linux-v1': { |
27 | 34 | compression_algorithm: 'zlib', |
28 | | - decoded_sha256: '1a8295e6ccb93022c6f5ceb8997b29f2912389b3b38f52a8f5a2ff7b0154b1bc', |
29 | | - decoded_size: 287, |
30 | | - encoded_sha256: 'c3dec543df1177561ab2aa74a37997ea3c1d748d532a597884f5a5c16670d56c', |
31 | | - encoded_size: 133, |
| 35 | + decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', |
| 36 | + decoded_size: 14, |
| 37 | + encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', |
| 38 | + encoded_size: 22, |
| 39 | + encryption_algorithm: 'none', |
| 40 | + relative_url: |
| 41 | + '/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', |
| 42 | + }, |
| 43 | + 'endpoint-exceptionlist-macos-v1': { |
| 44 | + compression_algorithm: 'zlib', |
| 45 | + decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', |
| 46 | + decoded_size: 14, |
| 47 | + encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', |
| 48 | + encoded_size: 22, |
| 49 | + encryption_algorithm: 'none', |
| 50 | + relative_url: |
| 51 | + '/api/endpoint/artifacts/download/endpoint-exceptionlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', |
| 52 | + }, |
| 53 | + 'endpoint-exceptionlist-windows-v1': { |
| 54 | + compression_algorithm: 'zlib', |
| 55 | + decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', |
| 56 | + decoded_size: 14, |
| 57 | + encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', |
| 58 | + encoded_size: 22, |
32 | 59 | encryption_algorithm: 'none', |
33 | 60 | relative_url: |
34 | | - '/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/1a8295e6ccb93022c6f5ceb8997b29f2912389b3b38f52a8f5a2ff7b0154b1bc', |
| 61 | + '/api/endpoint/artifacts/download/endpoint-exceptionlist-windows-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', |
35 | 62 | }, |
36 | 63 | }, |
37 | | - manifest_version: 'WzAsMF0=', |
| 64 | + manifest_version: 'a9b7ef358a363f327f479e31efc4f228b2277a7fb4d1914ca9b4e7ca9ffcf537', |
38 | 65 | schema_version: 'v1', |
39 | 66 | }); |
40 | 67 | }); |
41 | 68 |
|
42 | | - test('policy is returned even if error is encountered during artifact sync', async () => { |
43 | | - const logger = loggerMock.create(); |
| 69 | + test('policy is returned even if error is encountered during artifact creation', async () => { |
| 70 | + const logger = loggingSystemMock.create().get('ingest_integration.test'); |
44 | 71 | const manifestManager = getManifestManagerMock(); |
45 | | - manifestManager.syncArtifacts = jest.fn().mockRejectedValue([new Error('error updating')]); |
46 | | - const lastDispatched = await manifestManager.getLastDispatchedManifest(); |
| 72 | + manifestManager.pushArtifacts = jest.fn().mockResolvedValue([new Error('error updating')]); |
| 73 | + const lastComputed = await manifestManager.getLastComputedManifest( |
| 74 | + ManifestConstants.SCHEMA_VERSION |
| 75 | + ); |
| 76 | + |
47 | 77 | const callback = getPackageConfigCreateCallback(logger, manifestManager); |
48 | 78 | const policyConfig = createNewPackageConfigMock(); |
49 | 79 | const newPolicyConfig = await callback(policyConfig); |
| 80 | + |
50 | 81 | expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); |
51 | 82 | expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); |
52 | 83 | expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual( |
53 | | - lastDispatched.toEndpointFormat() |
| 84 | + lastComputed!.toEndpointFormat() |
54 | 85 | ); |
55 | 86 | }); |
56 | 87 |
|
57 | | - test('initial policy creation succeeds if snapshot retrieval fails', async () => { |
58 | | - const logger = loggerMock.create(); |
59 | | - const manifestManager = getManifestManagerMock(); |
60 | | - const lastDispatched = await manifestManager.getLastDispatchedManifest(); |
61 | | - manifestManager.getSnapshot = jest.fn().mockResolvedValue(null); |
| 88 | + test('initial policy creation succeeds if manifest retrieval fails', async () => { |
| 89 | + const logger = loggingSystemMock.create().get('ingest_integration.test'); |
| 90 | + const manifestManager = getManifestManagerMock({ |
| 91 | + mockType: ManifestManagerMockType.InitialSystemState, |
| 92 | + }); |
| 93 | + const lastComputed = await manifestManager.getLastComputedManifest( |
| 94 | + ManifestConstants.SCHEMA_VERSION |
| 95 | + ); |
| 96 | + expect(lastComputed).toEqual(null); |
| 97 | + |
| 98 | + manifestManager.buildNewManifest = jest.fn().mockRejectedValue(new Error('abcd')); |
62 | 99 | const callback = getPackageConfigCreateCallback(logger, manifestManager); |
63 | 100 | const policyConfig = createNewPackageConfigMock(); |
64 | 101 | const newPolicyConfig = await callback(policyConfig); |
| 102 | + |
65 | 103 | expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); |
66 | 104 | expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); |
67 | | - expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual( |
68 | | - lastDispatched.toEndpointFormat() |
69 | | - ); |
70 | 105 | }); |
71 | 106 |
|
72 | 107 | test('subsequent policy creations succeed', async () => { |
73 | | - const logger = loggerMock.create(); |
| 108 | + const logger = loggingSystemMock.create().get('ingest_integration.test'); |
74 | 109 | const manifestManager = getManifestManagerMock(); |
75 | | - const snapshot = await manifestManager.getSnapshot(); |
76 | | - manifestManager.getLastDispatchedManifest = jest.fn().mockResolvedValue(snapshot!.manifest); |
77 | | - manifestManager.getSnapshot = jest.fn().mockResolvedValue({ |
78 | | - manifest: snapshot!.manifest, |
79 | | - diffs: [], |
80 | | - }); |
| 110 | + const lastComputed = await manifestManager.getLastComputedManifest( |
| 111 | + ManifestConstants.SCHEMA_VERSION |
| 112 | + ); |
| 113 | + |
| 114 | + manifestManager.buildNewManifest = jest.fn().mockResolvedValue(lastComputed); // no diffs |
81 | 115 | const callback = getPackageConfigCreateCallback(logger, manifestManager); |
82 | 116 | const policyConfig = createNewPackageConfigMock(); |
83 | 117 | const newPolicyConfig = await callback(policyConfig); |
| 118 | + |
84 | 119 | expect(newPolicyConfig.inputs[0]!.type).toEqual('endpoint'); |
85 | 120 | expect(newPolicyConfig.inputs[0]!.config!.policy.value).toEqual(policyConfigFactory()); |
86 | 121 | expect(newPolicyConfig.inputs[0]!.config!.artifact_manifest.value).toEqual( |
87 | | - snapshot!.manifest.toEndpointFormat() |
| 122 | + lastComputed!.toEndpointFormat() |
88 | 123 | ); |
89 | 124 | }); |
90 | 125 | }); |
|
0 commit comments