- Notifications
You must be signed in to change notification settings - Fork 818
Rephrase custom PBA file descriptions in configuration #1027
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
Merged
mssalvatore merged 7 commits into guardicore:release/1.10.0 from shreyamalviya:rephrasing-config-custom-pba Mar 11, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits Select commit Hold shift + click to select a range
307e1e3 Rephrase custom PBA file descriptions in configuration
shreyamalviya eeba051 Only upload custom PBA file; execute only if specified in custom PBA …
shreyamalviya 6f134bd Download custom PBA file during execution, not initialisation
shreyamalviya 72a88c8 Add unit tests
shreyamalviya 9167aa6 Unit test modifications
shreyamalviya 4928109 Rephrase custom PBA file config descriptions
shreyamalviya 2b4fd9e Rephrase custom PBA command config descriptions
shreyamalviya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions 152 monkey/infection_monkey/post_breach/tests/actions/test_users_custom_pba.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import pytest | ||
| | ||
| from infection_monkey.post_breach.actions.users_custom_pba import ( | ||
| DIR_CHANGE_LINUX, DIR_CHANGE_WINDOWS, UsersPBA) | ||
| | ||
| MONKEY_DIR_PATH = "/dir/to/monkey/" | ||
| CUSTOM_LINUX_CMD = "command-for-linux" | ||
| CUSTOM_LINUX_FILENAME = "filename-for-linux" | ||
| CUSTOM_WINDOWS_CMD = "command-for-windows" | ||
| CUSTOM_WINDOWS_FILENAME = "filename-for-windows" | ||
| | ||
| | ||
| @pytest.fixture | ||
| def fake_monkey_dir_path(monkeypatch): | ||
| monkeypatch.setattr( | ||
| "infection_monkey.post_breach.actions.users_custom_pba.get_monkey_dir_path", | ||
| lambda: MONKEY_DIR_PATH, | ||
| ) | ||
| | ||
| | ||
| @pytest.fixture | ||
| def set_os_linux(monkeypatch): | ||
| monkeypatch.setattr( | ||
| "infection_monkey.post_breach.actions.users_custom_pba.is_windows_os", | ||
| lambda: False, | ||
| ) | ||
| | ||
| | ||
| @pytest.fixture | ||
| def set_os_windows(monkeypatch): | ||
| monkeypatch.setattr( | ||
| "infection_monkey.post_breach.actions.users_custom_pba.is_windows_os", | ||
| lambda: True, | ||
| ) | ||
| | ||
| | ||
| @pytest.fixture | ||
| def mock_UsersPBA_linux_custom_file_and_cmd( | ||
| set_os_linux, fake_monkey_dir_path, monkeypatch | ||
| ): | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.custom_PBA_linux_cmd", | ||
| CUSTOM_LINUX_CMD, | ||
| ) | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.PBA_linux_filename", | ||
| CUSTOM_LINUX_FILENAME, | ||
| ) | ||
| return UsersPBA() | ||
| | ||
| | ||
| def test_command_linux_custom_file_and_cmd( | ||
| mock_UsersPBA_linux_custom_file_and_cmd, | ||
| ): | ||
| expected_command = f"cd {MONKEY_DIR_PATH} ; {CUSTOM_LINUX_CMD}" | ||
| assert mock_UsersPBA_linux_custom_file_and_cmd.command == expected_command | ||
| | ||
| | ||
| @pytest.fixture | ||
| def mock_UsersPBA_windows_custom_file_and_cmd( | ||
| set_os_windows, fake_monkey_dir_path, monkeypatch | ||
| ): | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.custom_PBA_windows_cmd", | ||
| CUSTOM_WINDOWS_CMD, | ||
| ) | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.PBA_windows_filename", | ||
| CUSTOM_WINDOWS_FILENAME, | ||
| ) | ||
| return UsersPBA() | ||
| | ||
| | ||
| def test_command_windows_custom_file_and_cmd( | ||
| mock_UsersPBA_windows_custom_file_and_cmd, | ||
| ): | ||
| expected_command = f"cd {MONKEY_DIR_PATH} & {CUSTOM_WINDOWS_CMD}" | ||
| assert mock_UsersPBA_windows_custom_file_and_cmd.command == expected_command | ||
| | ||
| | ||
| @pytest.fixture | ||
| def mock_UsersPBA_linux_custom_file(set_os_linux, fake_monkey_dir_path, monkeypatch): | ||
| | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.custom_PBA_linux_cmd", None | ||
| ) | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.PBA_linux_filename", | ||
| CUSTOM_LINUX_FILENAME, | ||
| ) | ||
| return UsersPBA() | ||
| | ||
| | ||
| def test_command_linux_custom_file(mock_UsersPBA_linux_custom_file): | ||
| expected_command = "" | ||
| assert mock_UsersPBA_linux_custom_file.command == expected_command | ||
| | ||
| | ||
| @pytest.fixture | ||
| def mock_UsersPBA_windows_custom_file( | ||
| set_os_windows, fake_monkey_dir_path, monkeypatch | ||
| ): | ||
| | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.custom_PBA_windows_cmd", None | ||
| ) | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.PBA_windows_filename", | ||
| CUSTOM_WINDOWS_FILENAME, | ||
| ) | ||
| return UsersPBA() | ||
| | ||
| | ||
| def test_command_windows_custom_file(mock_UsersPBA_windows_custom_file): | ||
| expected_command = "" | ||
| assert mock_UsersPBA_windows_custom_file.command == expected_command | ||
| | ||
| | ||
| @pytest.fixture | ||
| def mock_UsersPBA_linux_custom_cmd(set_os_linux, fake_monkey_dir_path, monkeypatch): | ||
| | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.custom_PBA_linux_cmd", | ||
| CUSTOM_LINUX_CMD, | ||
| ) | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.PBA_linux_filename", None | ||
| ) | ||
| return UsersPBA() | ||
| | ||
| | ||
| def test_command_linux_custom_cmd(mock_UsersPBA_linux_custom_cmd): | ||
| expected_command = CUSTOM_LINUX_CMD | ||
| assert mock_UsersPBA_linux_custom_cmd.command == expected_command | ||
| | ||
| | ||
| @pytest.fixture | ||
| def mock_UsersPBA_windows_custom_cmd(set_os_windows, fake_monkey_dir_path, monkeypatch): | ||
| | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.custom_PBA_windows_cmd", | ||
| CUSTOM_WINDOWS_CMD, | ||
| ) | ||
| monkeypatch.setattr( | ||
| "infection_monkey.config.WormConfiguration.PBA_windows_filename", None | ||
| ) | ||
| return UsersPBA() | ||
| | ||
| | ||
| def test_command_windows_custom_cmd(mock_UsersPBA_windows_custom_cmd): | ||
| expected_command = CUSTOM_WINDOWS_CMD | ||
| assert mock_UsersPBA_windows_custom_cmd.command == expected_command | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit tests are nice, but not a silver bullet. There's an antipattern in TDD called the "mockery", when most of the functionality is mocked. I don't suggest refactoring the whole pba's to solve it, but I can see BB tests bringing more value here and still being trivial enough to implement (command execution at least). Other PBA's should be tested with BB's IMO.