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

IT for macos file_status #1466

Merged
merged 18 commits into from
Oct 15, 2021

Conversation

juliancnn
Copy link
Member

@juliancnn juliancnn commented Jun 17, 2021

Related issue
Closes #1465

Description

Hi team!,

The following tests are necessary to have a minimum validation standard for the macos feature on Wazuh-Logcollector

  • Test macOS file_status.json: Ensure file_status.json correctly works for oslog format events.
    • Test to check that file_status.json contains "macos" information with "macos" localfile block with only-feature-events set to yes when at least one log was obtained.
    • Test to check that file_status.json contains "macos" information with "macos" localfile block with only-feature-events set to no when at least one log was obtained.
    • Test to check that file_status.json does not contain "macos" information with "macos" localfile block with a wrong predicate.
    • Test to check that file_status.json does not contain "macos" information with "macos" localfile block with a wrong predicate and only-feature-events set to "no".
    • Test to check that file_status.json does not contain "macos" information after being updated when the agent starts and there is no "macos" localfile block configured, even when there was an old valid status of a "macos" localfile stored on it.

Tests

  • Proven that tests pass when they have to pass.
  • Proven that tests fail when they have to fail.
  • Python codebase satisfies PEP-8 style style guide. pycodestyle --max-line-length=120 --show-source --show-pep8 file.py.
  • Python codebase is documented following the Google Style for Python docstrings.
  • The test is documented in wazuh-qa/docs.
  • provision_documentation.sh generate the docs without errors.

nmkoremblum
nmkoremblum previously approved these changes Jun 24, 2021
Copy link
Contributor

@nmkoremblum nmkoremblum left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@JcabreraC JcabreraC force-pushed the 1465-macos-filestatus-IT-T0 branch 4 times, most recently from 929a9a2 to 8fc5f5b Compare June 24, 2021 12:00
@nmkoremblum nmkoremblum force-pushed the 1465-macos-filestatus-IT-T0 branch from 9cd2e24 to 80ddbc8 Compare June 24, 2021 13:43
@juliancnn
Copy link
Member Author

juliancnn commented Jun 24, 2021

LGTM!

The integration tests for macOS in jenkins passed successfully. The only test that failed was to be expected as it is an uncorrected bug in the master branch.

============================= test session starts ==============================
platform darwin -- Python 3.7.3, pytest-6.2.3, py-1.10.0, pluggy-0.13.1 -- /Library/Developer/CommandLineTools/usr/bin/python3
cachedir: .pytest_cache
metadata: {'Python': '3.7.3', 'Platform': 'Darwin-19.0.0-x86_64-i386-64bit', 'Packages': {'pytest': '6.2.3', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'testinfra': '5.0.0', 'html': '3.1.1', 'metadata': '1.8.0'}}
rootdir: /private/tmp/Test_integration_B816_20210624153651/tests/integration, configfile: pytest.ini
plugins: testinfra-5.0.0, html-3.1.1, metadata-1.8.0
collecting ... collected 81 items

test_logcollector/test_macos/test_macos_file_status_basic.py::test_macos_file_status_basic[yes-macos_message0] PASSED [  1%]
test_logcollector/test_macos/test_macos_file_status_basic.py::test_macos_file_status_basic[no-macos_message0] PASSED [  2%]
test_logcollector/test_macos/test_macos_file_status_predicate.py::test_macos_file_status_predicate[yes] PASSED [  3%]
test_logcollector/test_macos/test_macos_file_status_predicate.py::test_macos_file_status_predicate[no] PASSED [  4%]
test_logcollector/test_macos/test_macos_file_status_when_no_macos.py::test_macos_file_status_when_no_macos[get_configuration0] PASSED [  6%]
test_logcollector/test_macos/test_macos_format_basic.py::test_macos_format_basic[get_configuration0-macos_message0] PASSED [  7%]
test_logcollector/test_macos/test_macos_format_basic.py::test_macos_format_basic[get_configuration0-macos_message1] FAILED [  8%]Killing wazuh-modulesd... 
Killing wazuh-logcollector... 
Killing wazuh-syscheckd... 
Killing wazuh-agentd... 
Killing wazuh-execd... 
Wazuh v4.3.0 Stopped
Starting Wazuh v4.3.0...
Started wazuh-execd...
Started wazuh-agentd...
Started wazuh-syscheckd...
Started wazuh-logcollector...
Started wazuh-modulesd...
Completed.


=================================== FAILURES ===================================
__________ test_macos_format_basic[get_configuration0-macos_message1] __________

get_configuration = {'apply_to_modules': ['test_macos_format_basic'], 'metadata': {}, 'sections': [{'elements': [{'server': {'elements': [...'value': 'macos'}}, {'log_format': {'value': 'macos'}}], 'section': 'localfile'}], 'tags': ['test_macos_format_basic']}
configure_environment = None
get_connection_configuration = {'authd_port': 1515, 'client_keys': '/Library/Ossec/etc/client.keys', 'ip_address': 'localhost', 'protocol': 'tcp', ...}
init_authd_remote_simulator = None
macos_message = {'category': 'category', 'command': 'os_log', 'level': 'error', 'subsystem': 'testing.wazuh-agent.macos', ...}
restart_logcollector = None

    @pytest.mark.parametrize('macos_message', macos_log_messages)
    def test_macos_format_basic(get_configuration, configure_environment, get_connection_configuration,
                                init_authd_remote_simulator, macos_message, restart_logcollector):
    
        """Check if logcollector gather correctly macOS unified logging system events.
    
        This test uses logger tool and a custom log to generate ULS events. The agent is connected to a authd simulator
        and sended events are gather using remoted simulator tool.
    
        Raises:
            TimeoutError: If the expected callback is not generated.
        """
        expected_macos_message = ""
        log_command = macos_message['command']
    
        macos_logcollector_monitored = logcollector.callback_monitoring_macos_logs
        wazuh_log_monitor.start(timeout=30, callback=macos_logcollector_monitored,
                                error_message=logcollector.GENERIC_CALLBACK_ERROR_TARGET_SOCKET)
    
        if log_command == 'logger':
            logcollector.generate_macos_logger_log(macos_message['message'])
            expected_macos_message = logcollector.format_macos_message_pattern(macos_message['command'],
                                                                               macos_message['message'])
    
        elif log_command == 'os_log':
>           logcollector.generate_macos_custom_log(macos_message['type'], macos_message['subsystem'], macos_message['category'])
E           TypeError: generate_macos_custom_log() missing 1 required positional argument: 'category'

test_logcollector/test_macos/test_macos_format_basic.py:73: TypeError
- generated html file: file:///tmp/Test_integration_B816_20210624153651/report.html -
=========================== short test summary info ============================
FAILED test_logcollector/test_macos/test_macos_format_basic.py::test_macos_format_basic[get_configuration0-macos_message1]
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
=================== 1 failed, 6 passed in 211.95s (0:03:31) ====================

@nmkoremblum nmkoremblum force-pushed the 1465-macos-filestatus-IT-T0 branch from e180804 to 4d15f2f Compare September 27, 2021 17:31
@nmkoremblum nmkoremblum force-pushed the 1465-macos-filestatus-IT-T0 branch from 4d15f2f to 0a532b2 Compare September 28, 2021 15:33
JcabreraC
JcabreraC previously approved these changes Sep 28, 2021
Copy link
Member

@JcabreraC JcabreraC left a comment

Choose a reason for hiding this comment

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

Jenkins result

test_logcollector/test_macos/test_macos_file_status_basic.py::test_macos_file_status_basic[yes] PASSED [  1%]
test_logcollector/test_macos/test_macos_file_status_basic.py::test_macos_file_status_basic[no] PASSED [  2%]
test_logcollector/test_macos/test_macos_file_status_predicate.py::test_macos_file_status_predicate[yes] PASSED [  3%]
test_logcollector/test_macos/test_macos_file_status_predicate.py::test_macos_file_status_predicate[no] PASSED [  5%]
test_logcollector/test_macos/test_macos_file_status_when_no_macos.py::test_macos_file_status_when_no_macos[/tmp/dummy_file.log] PASSED [  6%]
test_logcollector/test_macos/test_macos_format_basic.py::test_macos_format_basic[get_configuration0-example] PASSED [  7%]
test_logcollector/test_macos/test_macos_format_only_future_events.py::test_macos_format_only_future_events[yes] PASSED [  8%]
test_logcollector/test_macos/test_macos_format_only_future_events.py::test_macos_format_only_future_events[no] PASSED [ 10%]

nmkoremblum
nmkoremblum previously approved these changes Sep 28, 2021
Copy link
Contributor

@nmkoremblum nmkoremblum left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Member

@Rebits Rebits left a comment

Choose a reason for hiding this comment

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

GJ but some changes are required

@nmkoremblum nmkoremblum force-pushed the 1465-macos-filestatus-IT-T0 branch 2 times, most recently from f1aff26 to 016ced1 Compare September 30, 2021 14:18
Copy link
Member

@juliamagan juliamagan left a comment

Choose a reason for hiding this comment

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

Here are some requested changes.

@nmkoremblum nmkoremblum force-pushed the 1465-macos-filestatus-IT-T0 branch 2 times, most recently from c9a41b4 to 07b996a Compare October 1, 2021 16:14
@nmkoremblum nmkoremblum force-pushed the 1465-macos-filestatus-IT-T0 branch from 07b996a to 66552be Compare October 5, 2021 05:06
@Rebits Rebits changed the base branch from 1329-4.3.0-macOS-logcollector to master October 11, 2021 16:07
@Rebits Rebits dismissed stale reviews from nmkoremblum and JcabreraC October 11, 2021 16:07

The base branch was changed.

@juliamagan
Copy link
Member

juliamagan commented Oct 11, 2021

These tests are being tested with the rest of the tests of #1329 in a temporal branch: temp-test-logcollector-macos

Package

Version Revision Link
4.3.0 40301 https://packages-dev.wazuh.com/warehouse/test/4.3/rpm/var/wazuh-manager-4.3.0-vr.testing.macos.logcollector.x86_64.rpm
4.3.0 40301 https://packages-dev.wazuh.com/warehouse/test/4.3/macos/wazuh-agent-4.3.0-vr.testing.macos.logcollector.pkg

Testing

test_logcollector/test_macos

OS Local Jenkins Notes
PS1 🔴
PS2 🔴

  • 🟢: All pass
  • 🟡: Some warnings
  • 🔴: Some errors/fails
  • 🔵: In progress

@juliamagan
Copy link
Member

juliamagan commented Oct 14, 2021

As these tests passed, we are going to merge them into 1329-4.3.0-macOS-logcollector

Package

Version Revision Link
4.3.0 40301 https://packages-dev.wazuh.com/warehouse/test/4.3/rpm/var/wazuh-manager-4.3.0-vr.testing.macos.logcollector.x86_64.rpm
4.3.0 40301 https://packages-dev.wazuh.com/warehouse/test/4.3/macos/wazuh-agent-4.3.0-vr.testing.macos.logcollector.pkg

Testing

test_logcollector/test_macos/test_macos_file_status_*

OS Local Jenkins Notes
PS1 🟢 🟢
PS2 🟢 🟢
PS2 🟢 🔵

  • 🟢: All pass
  • 🟡: Some warnings
  • 🔴: Some errors/fails
  • 🔵: In progress

@juliamagan juliamagan changed the base branch from master to 1329-4.3.0-macOS-logcollector October 15, 2021 07:39
Copy link
Member

@Rebits Rebits 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 e5825cc into 1329-4.3.0-macOS-logcollector Oct 15, 2021
@Rebits Rebits deleted the 1465-macos-filestatus-IT-T0 branch October 15, 2021 08:15
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.

Logcollector integration tests T0: Tests "macos" status stored on file_status.json
7 participants