Skip to content
Merged
Show file tree
Hide file tree
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 @@ -13,6 +13,7 @@ export default ({ loadTestFile }: FtrProviderContext): void => {
loadTestFile(require.resolve('./import_export'));
loadTestFile(require.resolve('./install_prebuilt_rules'));
loadTestFile(require.resolve('./prebuilt_rules_package'));
loadTestFile(require.resolve('./non_customizable_fields'));
loadTestFile(require.resolve('./status'));
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 type { FtrProviderContext } from '../../../../../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./non_customizable_fields'));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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 expect from 'expect';

import { PREBUILT_RULES_PACKAGE_NAME } from '@kbn/security-solution-plugin/common/detection_engine/constants';
import { deleteAllRules } from '../../../../../../../common/utils/security_solution';
import type { FtrProviderContext } from '../../../../../../ftr_provider_context';
import {
getCustomQueryRuleParams,
createPrebuiltRulesPackage,
installFleetPackageByUpload,
installPrebuiltRules,
} from '../../../../utils';
import {
MOCK_PKG_VERSION,
PREBUILT_RULE_ASSET_A,
PREBUILT_RULE_ASSET_B,
PREBUILT_RULE_ID_A,
} from '../configs/edge_cases/ess_air_gapped_with_bundled_packages.config';

export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const securitySolutionApi = getService('securitySolutionApi');
const log = getService('log');
const es = getService('es');

describe('@ess @serverless @serverlessQA modifying non-customizable fields', () => {
describe('patch rules', () => {
beforeEach(async () => {
await deleteAllRules(supertest, log);
});

it('throws an error if rule has external rule source and non-customizable fields are changed', async () => {
const securityDetectionEnginePackageZip = createPrebuiltRulesPackage({
packageName: PREBUILT_RULES_PACKAGE_NAME,
packageSemver: MOCK_PKG_VERSION,
prebuiltRuleAssets: [PREBUILT_RULE_ASSET_A, PREBUILT_RULE_ASSET_B],
});

await installFleetPackageByUpload({
getService,
packageBuffer: securityDetectionEnginePackageZip.toBuffer(),
});

await installPrebuiltRules(es, supertest);

const { body } = await securitySolutionApi
.patchRule({
body: {
rule_id: PREBUILT_RULE_ID_A,
author: ['new user'],
},
})
.expect(400);

expect(body.message).toEqual('Cannot update "author" field for prebuilt rules');
});
});

describe('update rules', () => {
afterEach(async () => {
await deleteAllRules(supertest, log);
});

it('throws an error if rule has external rule source and non-customizable fields are changed', async () => {
const securityDetectionEnginePackageZip = createPrebuiltRulesPackage({
packageName: PREBUILT_RULES_PACKAGE_NAME,
packageSemver: MOCK_PKG_VERSION,
prebuiltRuleAssets: [PREBUILT_RULE_ASSET_A, PREBUILT_RULE_ASSET_B],
});

await installFleetPackageByUpload({
getService,
packageBuffer: securityDetectionEnginePackageZip.toBuffer(),
});

await installPrebuiltRules(es, supertest);

const { body: existingRule } = await securitySolutionApi
.readRule({
query: { rule_id: PREBUILT_RULE_ID_A },
})
.expect(200);

const { body } = await securitySolutionApi
.updateRule({
body: getCustomQueryRuleParams({
...existingRule,
rule_id: PREBUILT_RULE_ID_A,
id: undefined,
license: 'new license',
}),
})
.expect(400);

expect(body.message).toEqual('Cannot update "license" field for prebuilt rules');
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import expect from 'expect';
import { createRule, deleteAllRules } from '../../../../../../common/utils/security_solution';
import { FtrProviderContext } from '../../../../../ftr_provider_context';
import {
createHistoricalPrebuiltRuleAssetSavedObjects,
createRuleAssetSavedObject,
deleteAllPrebuiltRuleAssets,
getCustomQueryRuleParams,
getSimpleRule,
getSimpleRuleOutput,
getSimpleRuleOutputWithoutRuleId,
installPrebuiltRules,
removeServerGeneratedProperties,
removeServerGeneratedPropertiesIncludingRuleId,
updateUsername,
Expand All @@ -27,7 +23,6 @@ export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const securitySolutionApi = getService('securitySolutionApi');
const log = getService('log');
const es = getService('es');
const utils = getService('securitySolutionUtils');

describe('@ess @serverless @serverlessQA patch_rules', () => {
Expand Down Expand Up @@ -232,26 +227,6 @@ export default ({ getService }: FtrProviderContext) => {
});
});

it('@skipInServerlessMKI throws an error if rule has external rule source and non-customizable fields are changed', async () => {
await deleteAllPrebuiltRuleAssets(es, log);
// Install base prebuilt detection rule
await createHistoricalPrebuiltRuleAssetSavedObjects(es, [
createRuleAssetSavedObject({ rule_id: 'rule-1', author: ['elastic'] }),
]);
await installPrebuiltRules(es, supertest);

const { body } = await securitySolutionApi
.patchRule({
body: {
rule_id: 'rule-1',
author: ['new user'],
},
})
.expect(400);

expect(body.message).toEqual('Cannot update "author" field for prebuilt rules');
});

describe('max signals', () => {
it('does NOT patch a rule when max_signals is less than 1', async () => {
await securitySolutionApi.createRule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import {
getSimpleMlRuleUpdate,
getSimpleRule,
updateUsername,
createHistoricalPrebuiltRuleAssetSavedObjects,
installPrebuiltRules,
createRuleAssetSavedObject,
} from '../../../utils';
import {
createAlertsIndex,
Expand Down Expand Up @@ -312,34 +309,6 @@ export default ({ getService }: FtrProviderContext) => {
expect(updatedRuleResponse).toMatchObject(expectedRule);
});
});

// Unskip: https://github.com/elastic/kibana/issues/195921
it('@skipInServerlessMKI throws an error if rule has external rule source and non-customizable fields are changed', async () => {
// Install base prebuilt detection rule
await createHistoricalPrebuiltRuleAssetSavedObjects(es, [
createRuleAssetSavedObject({ rule_id: 'rule-1', license: 'elastic' }),
]);
await installPrebuiltRules(es, supertest);

const { body: existingRule } = await securitySolutionApi
.readRule({
query: { rule_id: 'rule-1' },
})
.expect(200);

const { body } = await securitySolutionApi
.updateRule({
body: getCustomQueryRuleParams({
...existingRule,
rule_id: 'rule-1',
id: undefined,
license: 'new license',
}),
})
.expect(400);

expect(body.message).toEqual('Cannot update "license" field for prebuilt rules');
});
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export const installFleetPackageByUpload = async ({
},
{
retryCount: MAX_RETRIES,
timeout: FLEET_RATE_LIMIT_TIMEOUT * 3,
retryDelay: FLEET_RATE_LIMIT_TIMEOUT,
timeout: FLEET_RATE_LIMIT_TIMEOUT * 2,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '@kbn/security-solution-plugin/common/api/detection_engine/prebuilt_rules';
import type { Client } from '@elastic/elasticsearch';
import type SuperTest from 'supertest';
import { refreshSavedObjectIndices } from '../../refresh_index';

/**
* Installs available prebuilt rules in Kibana. Rules are
Expand Down Expand Up @@ -47,7 +46,5 @@ export const installPrebuiltRules = async (
.send(payload)
.expect(200);

await refreshSavedObjectIndices(es);

return response.body;
};