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

Add AWSServices discard_regex integration tests #4278

Merged
merged 4 commits into from
Aug 16, 2023

Conversation

fdalmaup
Copy link
Member

@fdalmaup fdalmaup commented Jul 4, 2023

Related issue
wazuh/wazuh#17388

Description

This PR adds new test cases for the discard_regex functionality, more precisely for the CloudWatchLogs and Inspector services.

Added

Tier 0

  • discard_regex parameter tests for AWSCloudWatchLogs
  • discard_regex parameter tests for AWSInspector

Testing performed

Tester Test path Jenkins Local OS Commit Notes
@fdalmaup (Developer) tests/integration/test_aws/test_discard_regex.py ⚫⚫⚫ 🟢 Ubuntu 22.04 e50f774 Nothing to highlight
@user (Reviewer) ⚫⚫⚫ 🚫 🚫 🚫 Nothing to highlight

EduLeon12
EduLeon12 previously approved these changes Jul 14, 2023
Copy link
Contributor

@EduLeon12 EduLeon12 left a comment

Choose a reason for hiding this comment

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

After reviewing the proposed test cases I think they fulfill the development made, Therefore it's approved.

Copy link
Contributor

@Selutario Selutario left a comment

Choose a reason for hiding this comment

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

Code changes LGTM. However, AWS ITs are available in 4.6.0 so the base branch can be changed. Also, take a look at the failing checks to fix them.

@fdalmaup fdalmaup changed the base branch from master to 4.6.0 July 17, 2023 15:32
@fdalmaup fdalmaup dismissed EduLeon12’s stale review July 17, 2023 15:32

The base branch was changed.

@fdalmaup fdalmaup force-pushed the 17388-aws-services-discard-regex-its branch 7 times, most recently from 57edfab to 5f2ffce Compare July 17, 2023 18:06
Copy link
Contributor

@Selutario Selutario left a comment

Choose a reason for hiding this comment

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

LGTM

@Selutario
Copy link
Contributor

This PR can be merged once this issue is finished:

Copy link
Contributor

@Selutario Selutario left a comment

Choose a reason for hiding this comment

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

Updating the changelog is required

@Selutario Selutario force-pushed the 17388-aws-services-discard-regex-its branch from 19a7d65 to d354572 Compare August 9, 2023 09:10
@Selutario Selutario force-pushed the 17388-aws-services-discard-regex-its branch from d354572 to 522cdcf Compare August 9, 2023 09:13
Selutario
Selutario previously approved these changes Aug 9, 2023
Copy link
Contributor

@mauromalara mauromalara left a comment

Choose a reason for hiding this comment

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

I requested some changes but, for me, the most important things to be considered before proceeding with applying those changes are:

  • I see that all test functions do the same and change minimal things like configuration or metadata. I would compress everything in a single test with different cases defined in a single YAML so that the test, according to these cases, knows what to validate and what not. If this is not possible, please detail what and why so that we can discuss about it.

  • I do not see a test case that checks that the JSON field on which you want to filter does not exist (negative case).

  • I don't see a validation to test for not discarding logs that don't apply to the filter set in <discard_regex> (negative case).

@fdalmaup
Copy link
Member Author

fdalmaup commented Aug 14, 2023

Hi @mauromalara, regarding your comments:

I see that all test functions do the same and change minimal things like configuration or metadata. I would compress everything in a single test with different cases defined in a single YAML so that the test, according to these cases, knows what to validate and what not. If this is not possible, please detail what and why so we can discuss it.

The single YAML approach was tested, but due to the differences between the base configuration of the module for each case, these failed to execute as expected (e.g., for Cloudwatch having and not having the field attribute inside the discard_regex parameter depending on if it is JSON or simple text failed because it added an empty value for the --discard-field parameter to the module's execution).
What you mentioned could be analyzed in the tests migration issue.

I do not see a test case that checks that the JSON field you want to filter does not exist (negative case).

The test environment contains both JSON and simple text logs. If the JSON field does not exist, the module does not show any related message, it processes every available log without discarding them.

I don't see a validation to test for not discarding logs that don't apply to the filter set in <discard_regex> (negative case).

This is also related to the test environment mentioned previously, if more logs than expected were discarded due to unexpected behavior of the module, then the pattern defined in the tests should find more matches than the ones described in the test cases and fail.

@mauromalara
Copy link
Contributor

The single YAML approach was tested, but due to the differences between the base configuration of the module for each case, these failed to execute as expected (e.g., for Cloudwatch having and not having the field attribute inside the discard_regex parameter depending on if it is JSON or simple text failed because it added an empty value for the --discard-field parameter to the module's execution).
What you mentioned could be analyzed in the wazuh/wazuh#17788.

Great! Please, update the issue you mentioned before to explicitly describe that you need to change this to reduce duplicated code.

The test environment contains both JSON and simple text logs. If the JSON field does not exist, the module does not show any related message, it processes every available log without discarding them.

In my view, I think this might not be good for the user. Picture this situation: as a user, what if I make a mistake while specifying the JSON field? Wouldn't it be preferable to promptly detect such issues by examining the logs? I suggest we create an issue on this matter and, furthermore, develop a test case to encompass this particular scenario.

This is also related to the test environment mentioned previously, if more logs than expected were discarded due to unexpected behavior of the module, then the pattern defined in the tests should find more matches than the ones described in the test cases and fail.

You're right, didn't think about it.

@fdalmaup fdalmaup force-pushed the 17388-aws-services-discard-regex-its branch from 26d67e4 to bcc8e01 Compare August 14, 2023 16:53
Copy link
Contributor

@mauromalara mauromalara left a comment

Choose a reason for hiding this comment

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

LGTM!

@Rebits Rebits merged commit f537bd0 into 4.6.0 Aug 16, 2023
4 checks passed
@Rebits Rebits deleted the 17388-aws-services-discard-regex-its branch August 16, 2023 14:17
@fdalmaup
Copy link
Member Author

Test execution 🟢

Three consecutive runs of the discard_regex ITs have been launched giving successful results:

====================================================================== test session starts ======================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.2.0
rootdir: /wazuh-qa/tests/integration, configfile: pytest.ini
plugins: testinfra-5.0.0, html-3.1.1, metadata-3.0.0
collected 17 items                                                                                                                                              

tests/integration/test_aws/test_discard_regex.py .................                                                                                        [100%]

------------------------------------------------------ generated html file: file:///wazuh-qa/report-1.html ------------------------------------------------------
================================================================ 17 passed in 330.45s (0:05:30) =================================================================
====================================================================== test session starts ======================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.2.0
rootdir: /wazuh-qa/tests/integration, configfile: pytest.ini
plugins: testinfra-5.0.0, html-3.1.1, metadata-3.0.0
collected 17 items                                                                                                                                              

tests/integration/test_aws/test_discard_regex.py .................                                                                                        [100%]

------------------------------------------------------ generated html file: file:///wazuh-qa/report-2.html ------------------------------------------------------
================================================================ 17 passed in 327.16s (0:05:27) =================================================================
====================================================================== test session starts ======================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.2.0
rootdir: /wazuh-qa/tests/integration, configfile: pytest.ini
plugins: testinfra-5.0.0, html-3.1.1, metadata-3.0.0
collected 17 items                                                                                                                                              

tests/integration/test_aws/test_discard_regex.py .................                                                                                        [100%]

------------------------------------------------------ generated html file: file:///wazuh-qa/report-3.html ------------------------------------------------------
================================================================ 17 passed in 324.24s (0:05:24) =================================================================

report-1.zip
report-2.zip
report-3.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants