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][API testing][Rule Management] Move and restructures remaining rule managements trail-tests #172173

Merged

Conversation

WafaaNasr
Copy link
Contributor

@WafaaNasr WafaaNasr commented Nov 29, 2023

Summary

❓ - Deprecated and should not be exposed in serverless, but is currently
❌ - Some or all tests in suite are broken in serverless

Action File New Path if moved ESS Serverless QA
Delete detection_engine_api_integration/security_and_spaces/README.md - - -
Delete detection_engine_api_integration/security_and_spaces/group1 - - -
Delete detection_engine_api_integration/security_and_spaces/group10 - - -
Delete detection_engine_api_integration/security_and_spaces/tests/import_rules (duplicated) - - -
Move detection_engine_api_integration/security_and_spaces/group1/create_rules_bulk security_solution_api_integration/test_suites/detections_response/default_license/rule_creation/create_rules_bulk.ts
Move detection_engine_api_integration/security_and_spaces/group1/delete_rules_bulk security_solution_api_integration/test_suites/detections_response/default_license/rule_delete/delete_rules_bulk.ts
Move detection_engine_api_integration/security_and_spaces/group1/delete_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_delete/delete_rules.ts
Move detection_engine_api_integration/security_and_spaces/group1/export_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_import_export/export_rules.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_import_export/export_rules_ess.ts - -
Move detection_engine_api_integration/security_and_spaces/group10/import_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_import_export/import_rules.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_import_export/import_rules_ess.ts - -
Move detection_engine_api_integration/security_and_spaces/group10/import_export_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_import_export/import_export_rules.ts - -
Move detection_engine_api_integration/security_and_spaces/group1/find_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_read/find_rules.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_read/find_rules_ess.ts - -
Move detection_engine_api_integration/security_and_spaces/group10/read_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_read/read_rules.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_read/read_rules_ess.ts - -
Move detection_engine_api_integration/security_and_spaces/group10/resolve_read_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_read/resolve_read_rules.ts - -
Move detection_engine_api_integration/security_and_spaces/group10/update_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_update/update_rules.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_update/update_rules_ess.ts - -
Move detection_engine_api_integration/security_and_spaces/group10/update_rules_bulk security_solution_api_integration/test_suites/detections_response/default_license/rule_update/update_rules_bulk.ts
Move detection_engine_api_integration/security_and_spaces/group10/patch_rules security_solution_api_integration/test_suites/detections_response/default_license/rule_patch/patch_rules.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_patch/patch_rules_ess.ts - -
Move detection_engine_api_integration/security_and_spaces/group10/patch_rules_bulk security_solution_api_integration/test_suites/detections_response/default_license/rule_patch/patch_rules_bulk.ts
Move detection_engine_api_integration/security_and_spaces/group1/get_rule_management_filters security_solution_api_integration/test_suites/detections_response/default_license/rule_management/get_rule_management_filters.ts
Move detection_engine_api_integration/security_and_spaces/group10/get_rule_execution_results security_solution_api_integration/test_suites/detections_response/default_license/rule_management/get_rule_execution_results.ts
Move detection_engine_api_integration/security_and_spaces/group10/perform_bulk_action_dry_run security_solution_api_integration/test_suites/detections_response/default_license/rule_bulk_actions/perform_bulk_action_dry_run.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_bulk_actions/perform_bulk_action_dry_run_ess.ts - -
Move detection_engine_api_integration/security_and_spaces/group1/perform_bulk_action security_solution_api_integration/test_suites/detections_response/default_license/rule_bulk_actions/perform_bulk_action.ts
Create NA security_solution_api_integration/test_suites/detections_response/default_license/rule_bulk_actions/perform_bulk_action_ess.ts - -

@WafaaNasr WafaaNasr added release_note:skip Skip the PR/issue when compiling release notes test-api-integration FTR labels Nov 29, 2023
@WafaaNasr WafaaNasr self-assigned this Nov 29, 2023
@yctercero yctercero added Team:Detection Rule Management Security Detection Rule Management Team Team:Detection Engine Security Solution Detection Engine Area labels Dec 2, 2023
@yctercero yctercero marked this pull request as ready for review December 4, 2023 04:09
@yctercero yctercero requested review from a team as code owners December 4, 2023 04:09
@yctercero yctercero requested a review from rylnd December 4, 2023 04:09
Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was very clearly a huge effort; thank you so much for your diligence here.

I had a few questions about test/script/report names, similar to on @yctercero's PR. I assume the inconsistency is due to these efforts being done in parallel, but perhaps it's worth agreeing to a standard naming convention.

I tried my best to track where all the tests/helpers went (I appreciated the table, of course); but on one of the first (create_container_with_exception_entries), that did not have a corresponding test, and seemed to be part of a whole area of dead code? I didn't see that mentioned in the description so I'm not positive; it would be a good callout to explain a bunch of deleted code without associated deletion of its use. But: excellent work identifying and deleting that, if that's the case :).

The concurrent renames + file changes make this branch messier than usual, but since it's entirely tests I think the only real risk here is that we accidentally delete some critical assertion. With that in mind, I was unable to find any such deletions.

LGTM.

...functionalConfig.getAll(),
testFiles: [require.resolve('..')],
junit: {
reportName: 'Rule Bulk Actions API Integration Tests - ESS - Rule bulk actions logic',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little redundant, and also not all of the info? Perhaps you and @yctercero should agree to a template to be used for these, for consistency?

Suggested change
reportName: 'Rule Bulk Actions API Integration Tests - ESS - Rule bulk actions logic',
reportName: 'Rule Bulk Actions - API Integration Tests - ESS - Default License',

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

describe('create_rules_bulk', () => {
// Marking as ESS and brokenInServerless as it's currently exposed in both, but if this is already
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to create a ticket to remove this endpoint? I'd say for now, if the endpoint exists and returns that deprecation header, we should verify it in each environment.

@@ -75,7 +75,7 @@ export default ({ getService }: FtrProviderContext): void => {
});

beforeEach(async () => {
await createSignalsIndex(supertest, log);
await createAlertsIndex(supertest, log);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate these changes, but I wonder how much smaller the diff would've been had we chosen to do them in a separate/subsequent PR ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With git we usually have to make that decision at the commit level, (i.e. it's better to rename a file in one commit and make changes in a subsequent one, so as to better allow git to recognize the rename); our squashing strategy for PRs means we can (and probably should) be making that decision at the PR level.

Not to say that you didn't, or that this wasn't the correct decision here: just pontificating.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call @rylnd and something we can keep in mind moving forward.

Note to self: something we can add in the PR guideline docs as "good practice".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is an example of git getting really confused 😆

const config = getService('config');
const ELASTICSEARCH_USERNAME = config.get('servers.kibana.username');

// Marking as ESS and brokenInServerless as it's currently exposed in both, but if this is already
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on this one. @yctercero should we add a ticket to capture removing these deprecated APIs? Is that something we can/want to do for serverless only?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's an existing old ticket - I'm updating this comment to reference it and enable for serverless as we currently are exposing it there - #130963


// Test to ensure that we have exactly 0 legacy actions by querying the Alerting client REST API directly
// See: https://www.elastic.co/guide/en/kibana/current/find-rules-api.html
// Note: We specifically query for both the filter of type "siem.notifications" and the "has_reference" to keep it very specific
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "keep it very specific" is not very specific 😄 . Maybe:

Suggested change
// Note: We specifically query for both the filter of type "siem.notifications" and the "has_reference" to keep it very specific
// Note: We specifically filter for both the type "siem.notifications" and the "has_reference" field to ensure we only retrieve legacy actions

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

describe('delete_rules', () => {
describe('@ess delete_rules_legacy', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the test description is another opportunity to provide detail/context to the reader. Repeating the name of the file does not add new information.

Of course I understand that you don't necessarily have the original context for this file, and there are a ton of files changed here, and that it originally did not do this. However, even this would be an improvement:

Suggested change
describe('@ess delete_rules_legacy', () => {
describe('@ess Delete Rules - Legacy Behaviors', () => {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I'm addressing the feedback, I'll look to improve on any test descriptions.

const rule = await fetchRule(supertest, { ruleId: 'rule-1' });
expect(rule.investigation_fields).to.eql({ field_names: ['foo', 'bar'] });
/**
* Confirm type on SO so that it's clear in the tests whether it's expected that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to have repeated this a few times; maybe it's worth extracting this into a helper function so that you can document it once?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a util for it. 👍🏽

@banderror banderror self-requested a review December 5, 2023 09:46
@banderror
Copy link
Contributor

@yctercero Could you please rebase the PR? It's now behind main by quite a bunch of commits.

Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yctercero @WafaaNasr Absolutely humongous work! I love the table in the PR description - it is super informative and clear, and will help me a lot with understanding what to do with Rule Management integration tests next.

I do have some suggestions and questions which I'd like to discuss with you @yctercero once you have some time for that. The main concern is the folder structure, I think. Could you please respond to comments and then we maybe could discuss them over zoom? Also, like in the other PR (#172173), I echo @rylnd's comments.

That all said, the size of this PR is crazy and for the sake of reducing the pain let's merge it as is and address comments in follow-up PRs.

LGTM 👍

Comment on lines +45 to +48
// Marking as ESS and brokenInServerless as it's currently exposed in both, but if this is already
// deprecated, it should cease being exposed in Serverless prior to GA, in which case this
// test would be run for ESS only.
describe('@ess @brokenInServerless @skipInQA create_rules_bulk', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really broken in Serverless, or you just skipped it in Serverless this way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm updating to test in serverless too. I'll add a note if it is broken in serverless.

Comment on lines +35 to +36
// TODO: add a new service
const config = getService('config');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? Can we please elaborate or remove this comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It refers to adding a util for pulling in esarchiver, similar to something like getService('loadEsArchiver'). Instead, right now, it requires a couple of lines each time. I think it's ok to leave in, I'm just expanding on the comment in the code.

@WafaaNasr when you're back, maybe we can just create a ticket to track this and update the comment to reference the ticket with details.

Comment on lines +82 to +84
const expectedRule = updateUsername(getSimpleRuleOutput(), ELASTICSEARCH_USERNAME);

expect(bodyToCompare).to.eql(expectedRule);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the cases where we have certain dynamic data in objects under test, like here with the created_by and updated_by fields not matching our mocks, we could exclude these fields from the mocks and assertions by using expect.objectContaining and (if we want) we could assert that these fields are being updated by the server on rule deletion in a separate test.

I'd highly encourage using expect.objectContaining and only asserting what is needed to be asserted according to the logic of a test, instead of adding/removing properties from objects under test as we do in removeServerGeneratedProperties and now in updateUsername.

More context: https://github.com/elastic/security-team/issues/3526#issuecomment-1096724323

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great to add to the planned docs around FTRs and cypress guidelines. I think it's a bit outside the scope of moving the FTRs here, but definitely an improvement we can track.

Comment on lines +30 to +31
// TODO: add a new service
const config = getService('config');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I see 32 such comments in 32 different files. I'd suggest to remove them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It refers to adding a util for pulling in esarchiver, similar to something like getService('loadEsArchiver'). Instead, right now, it requires a couple of lines each time. I think it's ok to leave in, I'm just expanding on the comment in the code.

@WafaaNasr when you're back, maybe we can just create a ticket to track this and update the comment to reference the ticket with details.

Comment on lines +53 to +58
describe('@ess import_rules - ESS specific logic', () => {
beforeEach(async () => {
await deleteAllRules(supertest, log);
});

it('should migrate legacy actions in existing rule if overwrite is set to true', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests covering legacy actions are scattered across many files that contain tests for various rules CRUD and other endpoints. I think we should extract them into their own group of tests, and this whole group would:

  • run only in ESS
  • be owned by the Detection Engine team

Not suggesting to do it in this PR, of course - let's do it separately 🙂


describe('update_rules', () => {
describe('@ess @serverless @skipInQA update_rules', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skipInQA: Do you know what's our plan for enabling tests in MKI environments?

Comment on lines +1332 to +1338
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_delete @elastic/security-detection-rule-management
x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_update @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_patch @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_import_export @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_management @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_bulk_actions @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_read @elastic/security-detection-rule-management
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of the folder structure proposed in this PR.

I think these are too many folders to track them all separately in CODEOWNERS. It would make it much easier for both code navigation and CODEOWNERS if we grouped these test groups into higher-level folders reflecting our subdomains. In this case, all these folders could be under a rule_management folder so we'd only need to add a single line to this file here:

/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_management @elastic/security-detection-rule-management

For the sake of having less pain I'd suggest to merge this PR as is and restructure these folders in a follow-up one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying from other comment:

@banderror let's definitely chat! I plan to address the comments that don't deal with restructuring first, and then open a PR dedicated to any structure updates. For the ownership on the endpoints we largely followed what we saw in the folders structure in the code itself (these routes are under rule_management, but it definitely felt a bit confusing.

I'll find a time to sync!

/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_management @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_bulk_actions @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_read @elastic/security-detection-rule-management
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_creation/create_rules_bulk.ts @elastic/security-detection-rule-management
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add a single file to CODEOWNERS? We shouldn't target individual files in CODEOWNERS because this can get out of sync with actual files pretty quickly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying from other comment:

@banderror let's definitely chat! I plan to address the comments that don't deal with restructuring first, and then open a PR dedicated to any structure updates. For the ownership on the endpoints we largely followed what we saw in the folders structure in the code itself (these routes are under rule_management, but it definitely felt a bit confusing.

I'll find a time to sync!

Comment on lines +1406 to +1408
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_creation/create_new_terms @elastic/security-detection-engine
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_creation/create_rules @elastic/security-detection-engine
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_creation/preview_rules @elastic/security-detection-engine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't target individual files in CODEOWNERS because this can get out of sync with actual files pretty quickly.

Copy link
Contributor

@yctercero yctercero Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying from other comment:

@banderror let's definitely chat! I plan to address the comments that don't deal with restructuring first, and then open a PR dedicated to any structure updates. For the ownership on the endpoints we largely followed what we saw in the folders structure in the code itself (these routes are under rule_management, but it definitely felt a bit confusing.

I'll find a time to sync!

Comment on lines +1415 to +1420
x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_update/update_rules.ts @elastic/security-detection-engine
x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_update/update_rules_ess.ts @elastic/security-detection-engine
x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_patch/patch_rules.ts @elastic/security-detection-engine
x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_patch/patch_rules_ess.ts @elastic/security-detection-engine
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_delete/delete_rules.ts @elastic/security-detection-engine
/x-pack/test/security_solution_api_integration/test_suites/detections_response/default_license/rule_delete/delete_rules_ess.ts @elastic/security-detection-engine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here regarding targeting individual files.

Also, I'd like to chat with you @yctercero about which team should own which rules CRUD tests. I don't understand the proposed separation between our two teams, and I have some thoughts about how we should do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@banderror let's definitely chat! I plan to address the comments that don't deal with restructuring first, and then open a PR dedicated to any structure updates. For the ownership on the endpoints we largely followed what we saw in the folders structure in the code itself (these routes are under rule_management, but it definitely felt a bit confusing.

I'll find a time to sync!

@yctercero
Copy link
Contributor

@rylnd @banderror acknowledging all the comments here. Will follow up merge with a PR to address all comments. Thanks so much for reviewing the huge PR.

@yctercero yctercero enabled auto-merge (squash) December 13, 2023 00:07
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @WafaaNasr

@yctercero yctercero merged commit 88dd20b into elastic:main Dec 13, 2023
36 checks passed
@kibanamachine kibanamachine added v8.13.0 backport:skip This commit does not require backporting labels Dec 13, 2023
yctercero added a commit that referenced this pull request Jan 12, 2024
## Summary

Addressing feedback from #172173.

This is not yet addressing file restructure, going to keep the file
restructure in a separate PR to try to make reviews more readable.
@WafaaNasr WafaaNasr deleted the move-structure-remaining-rulemanagmenttests branch February 6, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting FTR release_note:skip Skip the PR/issue when compiling release notes Team:Detection Engine Security Solution Detection Engine Area Team:Detection Rule Management Security Detection Rule Management Team test-api-integration v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants