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] Adds extra cypress and integration tests for setup guide field #180638

Merged
merged 13 commits into from
May 2, 2024

Conversation

dplumlee
Copy link
Contributor

@dplumlee dplumlee commented Apr 11, 2024

Summary

Adds extra tests to cover remaining areas not addressed in #178131

Adds cypress tests and adds setup field to utils to be used in import/export integration tests

Flaky test run (internal)

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@dplumlee dplumlee added test release_note:skip Skip the PR/issue when compiling release notes Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team v8.14.0 labels Apr 11, 2024
@dplumlee dplumlee self-assigned this Apr 11, 2024
@dplumlee
Copy link
Contributor Author

/ci

@banderror banderror added Feature:Rule Creation Security Solution Detection Rule Creation workflow Feature:Rule Edit Security Solution Detection Rule Editing workflow labels Apr 12, 2024
@dplumlee
Copy link
Contributor Author

@elastic/security-detection-rule-management I wanted to double check the conclusions we came to in the tech time meeting this past wednesday. It was my understanding that for cypress tests, it’d be best to group most of the fields into one exhaustive test (common_flows.cy.ts) to not have a separate group of tests for each field. Are we planning on doing a similar thing with import/export tests where we have one major test that groups together all (or most) of the fields and tests the import/export logic on them? I ask because certain fields (like setup in this case) have no real edge cases in these actions and I know it was mentioned in the meeting as an option.

@@ -37,6 +36,5 @@ export const PrebuiltRuleAsset = BaseCreateProps.and(TypeSpecificCreateProps).an
version: RuleVersion,
related_integrations: RelatedIntegrationArray.optional(),
required_fields: RequiredFieldArray.optional(),
setup: SetupGuide.optional(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@dplumlee @jpdjere Can you folks explain this change to me? Should related_integrations and required_fields get the same treatment?

Copy link
Contributor Author

@dplumlee dplumlee Apr 25, 2024

Choose a reason for hiding this comment

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

This is in reference to this comment, so yes if you're adding those fields to BaseDefaultableFields, they should respectively be removed in this type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Removed "required_fields" in my required fields PR.

Comment on lines 1515 to 1529

it('should import a rule with "setup"', async () => {
const ndjson = combineToNdJson(
getCustomQueryRuleParams({
setup: '# some setup markdown',
})
);

await supertest
.post(`${DETECTION_ENGINE_RULES_URL}/_import`)
.set('kbn-xsrf', 'true')
.attach('file', Buffer.from(ndjson), 'rules.ndjson')
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(200);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Interested in what other think here as well, but to answer your question, I think we should create a new describe block that has one test that simply imports a rule with all the fields we want to test for, then read it and asserts that all the fields we defined are present.

I think that should be enough:

        const ruleToImport = getCustomQueryRuleParams({ 
          rule_id: 'rule-1',
          setup: 'testing',
          investigation_fields: // whatever
          // all the fields we want to test
          // we should continously add fields to
          // test in here
        });
        const ndjson = combineToNdJson(ruleToImport);

        await supertest
          .post(`${DETECTION_ENGINE_RULES_URL}/_import`)
          .set('kbn-xsrf', 'true')
          .set('elastic-api-version', '2023-10-31')
          .attach('file', Buffer.from(ndjson), 'rules.ndjson')
          .expect(200);

        const importedRule = await fetchRule(supertest, { ruleId: 'rule-1' });

        // Assert al the fields we imported in the rule are there
        expect(importedRule).toMatchObject(ruleToImport);

Also, we should use the securitySolutionApi that @xcrzx created; but I just noticed it needs fixing for the import endpoint (currently only takes a query)

Copy link
Contributor

Choose a reason for hiding this comment

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

And same with exporting a rule

@dplumlee
Copy link
Contributor Author

/ci

@dplumlee dplumlee marked this pull request as ready for review April 23, 2024 04:27
@dplumlee dplumlee requested review from a team as code owners April 23, 2024 04:27
@dplumlee dplumlee requested review from rylnd and banderror April 23, 2024 04:27
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

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.

LGTM

@@ -63,6 +65,24 @@ export default ({ getService }: FtrProviderContext): void => {
expect(exportedRule).toMatchObject(ruleToExport);
});

it('should export defaultable fields when values are set', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
it('should export defaultable fields when values are set', async () => {
it('exports defaultable fields when non-default values are set', async () => {

@nikitaindik nikitaindik self-requested a review April 24, 2024 11:12
Copy link
Contributor

@nikitaindik nikitaindik left a comment

Choose a reason for hiding this comment

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

Test changes LGTM. They are consistent with tests in @maximpn's "related integrations" PR. Now we'll just need to wait until Maxim merges his PR after the April 29th Serveless release and resolve (hopefully) a few conflicts.

@banderror banderror removed their request for review April 29, 2024 07:06
@banderror
Copy link
Contributor

FYI if tests in this PR depend on #178295 which targets 8.15.0, there's a chance it would be hard to backport this PR to 8.14.

@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 @dplumlee

@dplumlee dplumlee removed the v8.14.0 label May 2, 2024
@dplumlee dplumlee merged commit c1c928d into elastic:main May 2, 2024
35 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 2, 2024
@dplumlee dplumlee deleted the extra-setup-guide-field-tests branch May 2, 2024 16:45
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 Feature:Rule Creation Security Solution Detection Rule Creation workflow Feature:Rule Edit Security Solution Detection Rule Editing workflow release_note:skip Skip the PR/issue when compiling release notes Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. test v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants