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

Unit tests for syscollector legacy decoder #15985

Merged
merged 1 commit into from Feb 3, 2023

Conversation

tdrauncieal
Copy link
Member

Related issue
#10368

Description

  • Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()

Tests

2023-01-20_11-28
2023-01-20_11-35

  • Compilation without warnings in every supported platform
    • Linux
    • Windows
    • MAC OS X
  • Source installation
  • Package installation
  • Source upgrade
  • Package upgrade
  • Review logs syntax and correct language
  • QA templates contemplate the added capabilities
  • Memory tests for Linux
    • Scan-build report
    • Coverity
    • Valgrind (memcheck and descriptor leaks check)
    • Dr. Memory
    • AddressSanitizer
  • Memory tests for Windows
    • Scan-build report
    • Coverity
    • Dr. Memory
  • Memory tests for macOS
    • Scan-build report
    • Leaks
    • AddressSanitizer
  • Retrocompatibility with older Wazuh versions
  • Working on cluster environments
  • Configuration on demand reports new parameters
  • The data flow works as expected (agent-manager-api-app)
  • Added unit tests (for new features)
  • Stress test for affected components
  • Decoder/Rule tests
    • Added unit testing files ".ini"
    • runtests.py executed without errors

Comment on lines +849 to +850
merror("Invalid message. Type not found."); // LCOV_EXCL_LINE
goto end; // LCOV_EXCL_LINE
Copy link
Member

Choose a reason for hiding this comment

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

Why are we not testing this and ignoring instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is not posible to achieve this section of code, because the only one entry point for decoder_XXX functions is by call on DecodeSyscollector().

Copy link
Member

Choose a reason for hiding this comment

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

I think it is possible but we would need to mock this json_type = cJSON_GetObjectItem(logJSON, "type"); it would affect the entire file and probably not worth it. The team may decide this.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure we can't send a JSON without type to force cJSON_GetObjectItem() to return NULL?

it would affect the entire file and probably not worth it.

Wrapping this function directly would indeed generate too many changes. Every test should be updated.

The only thing I can think of is updating __wrap_cJSON_GetObjectItem() to allow selecting when we want the real function and when we need the fake one.

Something like

if(test_mode) {
    //fake method
    ...
    return mock;
}
else {
    //real method
    __real_cJSON_GetObjectItem();

}

Copy link
Member

Choose a reason for hiding this comment

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

Let's not apply changes around this, this is a candidate for refactoring, it doesn't make sense to pass a string for a check that is done from the caller. A boolean would suffice to identify the end message.

Comment on lines +1201 to +1202
merror("Invalid message. Type not found."); // LCOV_EXCL_LINE
goto end; // LCOV_EXCL_LINE
Copy link
Member

Choose a reason for hiding this comment

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

I would normalize this message using the approach of the one above by adding the function name. The same for all cases

Copy link
Member Author

Choose a reason for hiding this comment

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

This refactoring exceeds the scope of the issue.

Copy link
Member

Choose a reason for hiding this comment

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

ok

MiguelazoDS
MiguelazoDS previously approved these changes Jan 20, 2023
\"timestamp\":\"2021/10/29 14:26:24\",\
\"inventory\":{\
\"board_serial\" : \"86\",\
\"cpu_name\" : \"87\",\
Copy link
Member

Choose a reason for hiding this comment

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

I would use a more representative example but not change requested.

\"type\":\"hotfix\",\
\"ID\":100,\
\"timestamp\":\"2021/10/29 14:26:24\",\
\"hotfix\":\"hotfix-version-test\"\
Copy link
Member

Choose a reason for hiding this comment

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

I would use a more representative example but not change requested.

\"ID\":100,\
\"timestamp\":\"2021/10/29 14:26:24\",\
\"iface\":{\
\"name\" : \"86\",\
Copy link
Member

Choose a reason for hiding this comment

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

I would use a more representative example but not change requested.

@snaow snaow changed the title Unit tests for syscollector legacy decoder #10368 Unit tests for syscollector legacy decoder Jan 23, 2023
@tdrauncieal tdrauncieal force-pushed the dev-10368-UT-syscollector-legacy branch from 8db2785 to 6580a42 Compare January 24, 2023 18:56
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
@tdrauncieal tdrauncieal force-pushed the dev-10368-UT-syscollector-legacy branch from 6580a42 to bb683c6 Compare January 30, 2023 21:47
Copy link
Member

@pereyra-m pereyra-m left a comment

Choose a reason for hiding this comment

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

GJ!

Comment on lines +849 to +850
merror("Invalid message. Type not found."); // LCOV_EXCL_LINE
goto end; // LCOV_EXCL_LINE
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure we can't send a JSON without type to force cJSON_GetObjectItem() to return NULL?

it would affect the entire file and probably not worth it.

Wrapping this function directly would indeed generate too many changes. Every test should be updated.

The only thing I can think of is updating __wrap_cJSON_GetObjectItem() to allow selecting when we want the real function and when we need the fake one.

Something like

if(test_mode) {
    //fake method
    ...
    return mock;
}
else {
    //real method
    __real_cJSON_GetObjectItem();

}

@Dwordcito Dwordcito merged commit 18ff868 into master Feb 3, 2023
@Dwordcito Dwordcito deleted the dev-10368-UT-syscollector-legacy branch February 3, 2023 16:25
fdalmaup pushed a commit that referenced this pull request Feb 6, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
TomasTurina pushed a commit that referenced this pull request Feb 24, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
tdrauncieal added a commit that referenced this pull request Apr 24, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
GGP1 pushed a commit that referenced this pull request Apr 24, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
GGP1 added a commit that referenced this pull request Apr 24, 2023
tdrauncieal added a commit that referenced this pull request Apr 24, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
GGP1 pushed a commit that referenced this pull request Apr 26, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
GGP1 added a commit that referenced this pull request Apr 26, 2023
jotacarma90 pushed a commit that referenced this pull request May 16, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
mhamra pushed a commit that referenced this pull request May 23, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
mhamra pushed a commit that referenced this pull request May 23, 2023
fdalmaup pushed a commit that referenced this pull request Jun 21, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
GGP1 pushed a commit that referenced this pull request Jun 27, 2023
* Add 100% UT coverage on these functions:

    decode_netinfo()
    decode_osinfo()
    decode_hardware()
    decode_package()
    decode_hotfix()
    decode_port()
    decode_process()
mhamra pushed a commit that referenced this pull request Aug 14, 2023
GGP1 added a commit that referenced this pull request Sep 29, 2023
GGP1 added a commit that referenced this pull request Oct 2, 2023
GGP1 added a commit that referenced this pull request Oct 2, 2023
GGP1 added a commit that referenced this pull request Oct 2, 2023
GGP1 added a commit that referenced this pull request Oct 3, 2023
GGP1 added a commit that referenced this pull request Oct 9, 2023
mhamra pushed a commit that referenced this pull request Oct 17, 2023
fdalmaup pushed a commit that referenced this pull request Oct 30, 2023
fdalmaup pushed a commit that referenced this pull request Nov 2, 2023
fdalmaup pushed a commit that referenced this pull request Nov 3, 2023
fdalmaup pushed a commit that referenced this pull request Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit tests for syscollector legacy decoder
4 participants