Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Refactor policy details tests to focus on only fields changed #126458

Merged
merged 4 commits into from
Mar 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
*/

import expect from '@kbn/expect';
import { DeepPartial } from 'utility-types';
import { merge } from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context';
import { PolicyTestResourceInfo } from '../../services/endpoint_policy';
import { IndexedHostsAndAlertsResponse } from '../../../../plugins/security_solution/common/endpoint/index_data';
import { FullAgentPolicyInput } from '../../../../plugins/fleet/common';
import { PolicyConfig } from '../../../../plugins/security_solution/common/endpoint/types';
import { ManifestSchema } from '../../../../plugins/security_solution/common/endpoint/schema/manifest';
import { policyFactory } from '../../../../plugins/security_solution/common/endpoint/models/policy_config';
import { popupVersionsMap } from '../../../../plugins/security_solution/public/management/pages/policy/view/policy_forms/protections/popup_options_to_versions';

export default function ({ getPageObjects, getService }: FtrProviderContext) {
Expand All @@ -32,210 +26,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const policyTestResources = getService('policyTestResources');
const endpointTestResources = getService('endpointTestResources');

type FullAgentPolicyEndpointInput = Omit<FullAgentPolicyInput, 'streams'> & {
policy: PolicyConfig;
artifact_manifest: ManifestSchema;
};

/**
* Returns the Fleet Agent Policy Input that represents an Endpoint Policy. Use it to
* validate expecte output when looking at the Fleet Agent policy to validate that updates
* to the Endpoint Policy are making it through to the overall Fleet Agent Policy
*
* @param overrides
*/
const getExpectedAgentPolicyEndpointInput = (
overrides: DeepPartial<FullAgentPolicyEndpointInput> = {}
): FullAgentPolicyInput => {
return merge(
{
id: '123',
revision: 2,
data_stream: { namespace: 'default' },
name: 'Protect East Coast',
meta: {
package: {
name: 'endpoint',
version: '1.0',
},
},
artifact_manifest: {
artifacts: {
'endpoint-exceptionlist-linux-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-exceptionlist-linux-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-exceptionlist-macos-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-exceptionlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-exceptionlist-windows-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-exceptionlist-windows-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-hostisolationexceptionlist-linux-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-hostisolationexceptionlist-linux-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-hostisolationexceptionlist-macos-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-hostisolationexceptionlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-hostisolationexceptionlist-windows-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-hostisolationexceptionlist-windows-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-trustlist-linux-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-trustlist-linux-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-trustlist-macos-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-trustlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-trustlist-windows-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-trustlist-windows-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-eventfilterlist-linux-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-eventfilterlist-linux-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-eventfilterlist-macos-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-eventfilterlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
'endpoint-eventfilterlist-windows-v1': {
compression_algorithm: 'zlib',
decoded_sha256: 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
decoded_size: 14,
encoded_sha256: 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda',
encoded_size: 22,
encryption_algorithm: 'none',
relative_url:
'/api/fleet/artifacts/endpoint-eventfilterlist-windows-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658',
},
},
manifest_version: '1',
schema_version: 'v1',
},
policy: merge(policyFactory(), {
windows: {
popup: {
malware: {
message: 'Elastic Security {action} {filename}',
},
ransomware: {
message: 'Elastic Security {action} {filename}',
},
memory_protection: {
message: 'Elastic Security {action} {rule}',
},
behavior_protection: {
message: 'Elastic Security {action} {rule}',
},
},
},
mac: {
popup: {
malware: {
message: 'Elastic Security {action} {filename}',
},
behavior_protection: {
message: 'Elastic Security {action} {rule}',
},
memory_protection: {
message: 'Elastic Security {action} {rule}',
},
},
},
linux: {
popup: {
malware: {
message: 'Elastic Security {action} {filename}',
},
behavior_protection: {
message: 'Elastic Security {action} {rule}',
},
memory_protection: {
message: 'Elastic Security {action} {rule}',
},
},
},
}),
type: 'endpoint',
use_output: 'default',
},
overrides
);
};

describe('When on the Endpoint Policy Details Page', function () {
let indexedData: IndexedHostsAndAlertsResponse;

Expand Down Expand Up @@ -337,8 +127,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});
});

// FLAKY: https://github.com/elastic/kibana/issues/92567
describe.skip('and the save button is clicked', () => {
describe('and the save button is clicked', () => {
let policyInfo: PolicyTestResourceInfo;

beforeEach(async () => {
Expand Down Expand Up @@ -401,34 +190,12 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
policyInfo.agentPolicy.id
);

expect(agentFullPolicy.inputs).to.eql([
getExpectedAgentPolicyEndpointInput({
id: policyInfo.packagePolicy.id,
name: policyInfo.packagePolicy.name,
meta: {
package: {
version: policyInfo.packageInfo.version,
},
},
artifact_manifest: agentFullPolicy.inputs[0].artifact_manifest,
policy: {
linux: {
events: {
file: false,
},
advanced: {
agent: {
connection_delay: 'true',
},
},
},
mac: {
events: { file: false },
},
windows: { events: { file: false } },
},
}),
]);
expect(agentFullPolicy.inputs[0].policy.linux.advanced.agent.connection_delay).to.eql(
'true'
);
expect(agentFullPolicy.inputs[0].policy.linux.events.file).to.eql(false);
expect(agentFullPolicy.inputs[0].policy.mac.events.file).to.eql(false);
expect(agentFullPolicy.inputs[0].policy.windows.events.file).to.eql(false);
});

it('should have cleared the advanced section when the user deletes the value', async () => {
Expand All @@ -447,28 +214,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
policyInfo.agentPolicy.id
);

expect(agentFullPolicy.inputs).to.eql([
getExpectedAgentPolicyEndpointInput({
id: policyInfo.packagePolicy.id,
name: policyInfo.packagePolicy.name,
revision: agentFullPolicy.inputs[0].revision,
meta: {
package: {
version: policyInfo.packageInfo.version,
},
},
artifact_manifest: agentFullPolicy.inputs[0].artifact_manifest,
policy: {
linux: {
advanced: {
agent: {
connection_delay: 'true',
},
},
},
},
}),
]);
expect(agentFullPolicy.inputs[0].policy.linux.advanced.agent.connection_delay).to.eql(
'true'
);

// Clear the value
await advancedPolicyField.click();
Expand All @@ -484,19 +232,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
policyInfo.agentPolicy.id
);

expect(agentFullPolicyUpdated.inputs).to.eql([
getExpectedAgentPolicyEndpointInput({
id: policyInfo.packagePolicy.id,
name: policyInfo.packagePolicy.name,
revision: agentFullPolicyUpdated.inputs[0].revision,
meta: {
package: {
version: policyInfo.packageInfo.version,
},
},
artifact_manifest: agentFullPolicyUpdated.inputs[0].artifact_manifest,
}),
]);
expect(agentFullPolicyUpdated.inputs[0].policy.linux.advanced).to.eql(undefined);
});
});

Expand Down