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

[Fleet] Fix circular ref by moving code & tests into Fleet #94171

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ import {
GLOBAL_SETTINGS_SAVED_OBJECT_TYPE,
} from '../constants';

import {
migratePackagePolicyToV7110,
migratePackagePolicyToV7120,
// @ts-expect-error
} from './security_solution';
import { migratePackagePolicyToV7110, migratePackagePolicyToV7120 } from './security_solution';
import {
migrateAgentToV7100,
migrateAgentEventToV7100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* 2.0.
*/

import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { cloneDeep } from 'lodash';

import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';

import { PackagePolicy } from '../../../../../fleet/common';

export const migratePackagePolicyToV7110: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
* 2.0.
*/

export {
migratePackagePolicyToV7110,
migratePackagePolicyToV7120,
} from '../../../security_solution/common';
export { migratePackagePolicyToV7110 } from './to_v7_11_0';
export { migratePackagePolicyToV7120 } from './to_v7_12_0';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import { SavedObjectMigrationContext, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { PackagePolicy } from '../../../../../fleet/common';

import { PackagePolicy } from '../../../common';

import { migratePackagePolicyToV7110 } from './to_v7_11_0';

describe('7.11.0 Endpoint Package Policy migration', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
jfsiii marked this conversation as resolved.
Show resolved Hide resolved
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { cloneDeep } from 'lodash';

import { PackagePolicy } from '../../../common';

export const migratePackagePolicyToV7110: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
packagePolicyDoc
) => {
const updatedPackagePolicyDoc: SavedObjectUnsanitizedDoc<PackagePolicy> = cloneDeep(
packagePolicyDoc
);
if (packagePolicyDoc.attributes.package?.name === 'endpoint') {
const input = updatedPackagePolicyDoc.attributes.inputs[0];
const popup = {
malware: {
message: '',
enabled: false,
},
};
if (input && input.config) {
const policy = input.config.policy.value;

policy.windows.antivirus_registration = policy.windows.antivirus_registration || {
enabled: false,
};
policy.windows.popup = popup;
policy.mac.popup = popup;
}
}

return updatedPackagePolicyDoc;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
*/

import { SavedObjectMigrationContext, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { PackagePolicy } from '../../../../../fleet/common';
import { PolicyData, ProtectionModes } from '../../types';

import { PackagePolicy } from '../../../common';

import { migratePackagePolicyToV7120 } from './to_v7_12_0';

describe('7.12.0 Endpoint Package Policy migration', () => {
const migration = migratePackagePolicyToV7120;
it('adds ransomware option and notification customization', () => {
const doc: SavedObjectUnsanitizedDoc<PolicyData> = {
const doc = {
id: 'mock-saved-object-id',
attributes: {
name: 'Some Policy Name',
Expand Down Expand Up @@ -41,7 +42,6 @@ describe('7.12.0 Endpoint Package Policy migration', () => {
policy: {
value: {
windows: {
// @ts-expect-error
popup: {
malware: {
message: '',
Expand All @@ -58,9 +58,7 @@ describe('7.12.0 Endpoint Package Policy migration', () => {
type: ' nested',
};

expect(
migration(doc, {} as SavedObjectMigrationContext) as SavedObjectUnsanitizedDoc<PolicyData>
).toEqual({
expect(migration(doc, {} as SavedObjectMigrationContext)).toEqual({
attributes: {
name: 'Some Policy Name',
package: {
Expand Down Expand Up @@ -88,7 +86,7 @@ describe('7.12.0 Endpoint Package Policy migration', () => {
value: {
windows: {
ransomware: {
mode: ProtectionModes.off,
mode: 'off',
},
popup: {
malware: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { SavedObjectMigrationFn, SavedObjectUnsanitizedDoc } from 'kibana/server';
import { cloneDeep } from 'lodash';
import { PackagePolicy } from '../../../../../fleet/common';
import { ProtectionModes } from '../../types';

import type { PackagePolicy } from '../../../common';

export const migratePackagePolicyToV7120: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
packagePolicyDoc
Expand All @@ -19,7 +19,7 @@ export const migratePackagePolicyToV7120: SavedObjectMigrationFn<PackagePolicy,
if (packagePolicyDoc.attributes.package?.name === 'endpoint') {
const input = updatedPackagePolicyDoc.attributes.inputs[0];
const ransomware = {
mode: ProtectionModes.off,
mode: 'off',
};
const ransomwarePopup = {
message: '',
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/security_solution/common/shared_exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ export { exactCheck } from './exact_check';
export { getPaths, foldLeftRight, removeExternalLinkText } from './test_utils';
export { validate, validateEither } from './validate';
export { formatErrors } from './format_errors';
export { migratePackagePolicyToV7110 } from './endpoint/policy/migrations/to_v7_11_0';
export { migratePackagePolicyToV7120 } from './endpoint/policy/migrations/to_v7_12_0';
export { addIdToItem, removeIdFromItem } from './add_remove_id_to_item';