-
Notifications
You must be signed in to change notification settings - Fork 13
More integration tests #173
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ef9c9b3
Added positive cases for audit-logs command
kiran-chaudhary ce0fc77
added alerts, alert_rules and audit-logs tests
kiran-chaudhary 39c2128
more tests
kiran-chaudhary 80ead12
removed incomplete tests
kiran-chaudhary d78731c
reformat style
kiran-chaudhary 57f0bdd
String format
kiran-chaudhary 7c420d7
added integration marker
kiran-chaudhary f92661c
added test dependency
kiran-chaudhary 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
from integration import run_command | ||
|
||
ALERT_RULES_COMMAND = "code42 alert-rules" | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
"{} list".format(ALERT_RULES_COMMAND), | ||
"{} show test-rule-id".format(ALERT_RULES_COMMAND), | ||
"{} list -f CSV".format(ALERT_RULES_COMMAND), | ||
"{} list -f TABLE".format(ALERT_RULES_COMMAND), | ||
"{} list -f RAW-JSON".format(ALERT_RULES_COMMAND), | ||
"{} list -f JSON".format(ALERT_RULES_COMMAND), | ||
"{} list --format CSV".format(ALERT_RULES_COMMAND), | ||
"{} list --format TABLE".format(ALERT_RULES_COMMAND), | ||
"{} list --format JSON".format(ALERT_RULES_COMMAND), | ||
"{} list --format RAW-JSON".format(ALERT_RULES_COMMAND), | ||
], | ||
) | ||
def test_alert_rules_command_returns_success_return_code(command): | ||
return_code, response = run_command(command) | ||
assert return_code == 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, error_msg", | ||
[ | ||
( | ||
"{} add-user --rule-id test-rule-id".format(ALERT_RULES_COMMAND), | ||
"Missing option '-u' / '--username'.", | ||
), | ||
( | ||
"{} remove-user --rule-id test-rule-id".format(ALERT_RULES_COMMAND), | ||
"Missing option '-u' / '--username'.", | ||
), | ||
("{} add-user".format(ALERT_RULES_COMMAND), "Missing option '--rule-id'."), | ||
("{} remove-user".format(ALERT_RULES_COMMAND), "Missing option '--rule-id'."), | ||
("{} show".format(ALERT_RULES_COMMAND), "Missing argument 'RULE_ID'."), | ||
( | ||
"{} bulk add".format(ALERT_RULES_COMMAND), | ||
"Error: Missing argument 'CSV_FILE'.", | ||
), | ||
( | ||
"{} bulk remove".format(ALERT_RULES_COMMAND), | ||
"Error: Missing argument 'CSV_FILE'.", | ||
), | ||
], | ||
) | ||
def test_alert_rules_command_returns_error_exit_status_when_missing_required_parameters( | ||
command, error_msg | ||
): | ||
return_code, response = run_command(command) | ||
assert return_code == 2 | ||
assert error_msg in "".join(response) |
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 |
---|---|---|
|
@@ -11,21 +11,48 @@ | |
end_date_str = end_date.strftime("%Y-%m-%d") | ||
|
||
ALERT_COMMAND = "code42 alerts search -b {} -e {}".format(begin_date_str, end_date_str) | ||
ADVANCED_QUERY = """{"groupClause":"AND", "groups":[{"filterClause":"AND", | ||
"filters":[{"operator":"ON_OR_AFTER", "term":"eventTimestamp", "value":"2020-09-13T00:00:00.000Z"}, | ||
{"operator":"ON_OR_BEFORE", "term":"eventTimestamp", "value":"2020-12-07T13:20:15.195Z"}]}], | ||
"srtDir":"asc", "srtKey":"eventId", "pgNum":1, "pgSize":10000} | ||
""" | ||
ALERT_ADVANCED_QUERY_COMMAND = "code42 alerts search --advanced-query '{}'".format( | ||
ADVANCED_QUERY | ||
) | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
("{}".format(ALERT_COMMAND)), | ||
("{} --state OPEN".format(ALERT_COMMAND)), | ||
("{} --state RESOLVED".format(ALERT_COMMAND)), | ||
("{} --actor [email protected]".format(ALERT_COMMAND)), | ||
("{} --rule-name 'File Upload Alert'".format(ALERT_COMMAND)), | ||
("{} --rule-id 962a6a1c-54f6-4477-90bd-a08cc74cbf71".format(ALERT_COMMAND)), | ||
("{} --rule-type FedEndpointExfiltration".format(ALERT_COMMAND)), | ||
("{} --description 'Alert on any file upload'".format(ALERT_COMMAND)), | ||
ALERT_COMMAND, | ||
"{} --state OPEN".format(ALERT_COMMAND), | ||
"{} --state RESOLVED".format(ALERT_COMMAND), | ||
"{} --actor [email protected]".format(ALERT_COMMAND), | ||
"{} --rule-name 'File Upload Alert'".format(ALERT_COMMAND), | ||
"{} --rule-id 962a6a1c-54f6-4477-90bd-a08cc74cbf71".format(ALERT_COMMAND), | ||
"{} --rule-type FedEndpointExfiltration".format(ALERT_COMMAND), | ||
"{} --description 'Alert on any file upload'".format(ALERT_COMMAND), | ||
"{} --exclude-rule-type 'FedEndpointExfiltration'".format(ALERT_COMMAND), | ||
"{} --exclude-rule-id '962a6a1c-54f6-4477-90bd-a08cc74cbf71'".format( | ||
ALERT_COMMAND | ||
), | ||
"{} --exclude-rule-name 'File Upload Alert'".format(ALERT_COMMAND), | ||
"{} --exclude-actor-contains '[email protected]'".format(ALERT_COMMAND), | ||
"{} --exclude-actor '[email protected]'".format(ALERT_COMMAND), | ||
"{} --actor-contains '[email protected]'".format(ALERT_COMMAND), | ||
ALERT_ADVANCED_QUERY_COMMAND, | ||
], | ||
) | ||
def test_alert_returns_success_return_code(command): | ||
def test_alert_command_returns_success_return_code(command): | ||
return_code, response = run_command(command) | ||
assert return_code == 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command", ["{} --advanced-query '{}'".format(ALERT_COMMAND, ADVANCED_QUERY)] | ||
) | ||
def test_begin_cant_be_used_with_advanced_query(command): | ||
return_code, response = run_command(command) | ||
assert return_code == 2 | ||
assert "--begin can't be used with: --advanced-query" in response[0] |
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
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,30 @@ | ||
import pytest | ||
from integration import run_command | ||
|
||
DEPARTING_EMPLOYEE_COMMAND = "code42 departing-employee" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, error_msg", | ||
[ | ||
("{} add".format(DEPARTING_EMPLOYEE_COMMAND), "Missing argument 'USERNAME'."), | ||
( | ||
"{} remove".format(DEPARTING_EMPLOYEE_COMMAND), | ||
"Missing argument 'USERNAME'.", | ||
), | ||
( | ||
"{} bulk add".format(DEPARTING_EMPLOYEE_COMMAND), | ||
"Missing argument 'CSV_FILE'.", | ||
), | ||
( | ||
"{} bulk remove".format(DEPARTING_EMPLOYEE_COMMAND), | ||
"Missing argument 'FILE'.", | ||
), | ||
], | ||
) | ||
def test_departing_employee_command_returns_error_exit_status_when_missing_required_parameters( | ||
command, error_msg | ||
): | ||
return_code, response = run_command(command) | ||
assert return_code == 2 | ||
assert error_msg in "".join(response) |
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,29 @@ | ||
import pytest | ||
from integration import run_command | ||
|
||
HR_EMPLOYEE_COMMAND = "code42 high-risk-employee" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, error_msg", | ||
[ | ||
("{} add".format(HR_EMPLOYEE_COMMAND), "Missing argument 'USERNAME'."), | ||
("{} remove".format(HR_EMPLOYEE_COMMAND), "Missing argument 'USERNAME'."), | ||
("{} bulk add".format(HR_EMPLOYEE_COMMAND), "Missing argument 'CSV_FILE'."), | ||
("{} bulk remove".format(HR_EMPLOYEE_COMMAND), "Missing argument 'FILE'."), | ||
( | ||
"{} bulk add-risk-tags".format(HR_EMPLOYEE_COMMAND), | ||
"Missing argument 'CSV_FILE'.", | ||
), | ||
( | ||
"{} bulk remove-risk-tags".format(HR_EMPLOYEE_COMMAND), | ||
"Missing argument 'CSV_FILE'.", | ||
), | ||
], | ||
) | ||
def test_hr_employee_command_returns_error_exit_status_when_missing_required_parameters( | ||
command, error_msg | ||
): | ||
return_code, response = run_command(command) | ||
assert return_code == 2 | ||
assert error_msg in "".join(response) |
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,63 @@ | ||
import pytest | ||
from integration import run_command | ||
|
||
LEGAL_HOLD_COMMAND = "code42 legal-hold" | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize( | ||
"command", | ||
[ | ||
"{} list".format(LEGAL_HOLD_COMMAND), | ||
"{} show 984140047896012577".format(LEGAL_HOLD_COMMAND), | ||
"{} list -f CSV".format(LEGAL_HOLD_COMMAND), | ||
"{} list -f TABLE".format(LEGAL_HOLD_COMMAND), | ||
"{} list -f RAW-JSON".format(LEGAL_HOLD_COMMAND), | ||
"{} list -f JSON".format(LEGAL_HOLD_COMMAND), | ||
"{} list --format CSV".format(LEGAL_HOLD_COMMAND), | ||
"{} list --format TABLE".format(LEGAL_HOLD_COMMAND), | ||
"{} list --format JSON".format(LEGAL_HOLD_COMMAND), | ||
"{} list --format RAW-JSON".format(LEGAL_HOLD_COMMAND), | ||
], | ||
) | ||
def test_alert_rules_command_returns_success_return_code(command): | ||
return_code, response = run_command(command) | ||
assert return_code == 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"command, error_msg", | ||
[ | ||
( | ||
"{} add-user --matter-id test-matter-id".format(LEGAL_HOLD_COMMAND), | ||
"Missing option '-u' / '--username'.", | ||
), | ||
( | ||
"{} remove-user --matter-id test-matter-id".format(LEGAL_HOLD_COMMAND), | ||
"Missing option '-u' / '--username'.", | ||
), | ||
( | ||
"{} add-user".format(LEGAL_HOLD_COMMAND), | ||
"Missing option '-m' / '--matter-id'.", | ||
), | ||
( | ||
"{} remove-user".format(LEGAL_HOLD_COMMAND), | ||
"Missing option '-m' / '--matter-id'.", | ||
), | ||
("{} show".format(LEGAL_HOLD_COMMAND), "Missing argument 'MATTER_ID'."), | ||
( | ||
"{} bulk add".format(LEGAL_HOLD_COMMAND), | ||
"Error: Missing argument 'CSV_FILE'.", | ||
), | ||
( | ||
"{} bulk remove".format(LEGAL_HOLD_COMMAND), | ||
"Error: Missing argument 'CSV_FILE'.", | ||
), | ||
], | ||
) | ||
def test_alert_rules_command_returns_error_exit_status_when_missing_required_parameters( | ||
command, error_msg | ||
): | ||
return_code, response = run_command(command) | ||
assert return_code == 2 | ||
assert error_msg in "".join(response) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -10,14 +10,15 @@ deps = | |
pytest == 4.6.11 | ||
pytest-mock == 2.0.0 | ||
pytest-cov == 2.10.0 | ||
pexpect == 4.8.0 | ||
|
||
commands = | ||
# -v: verbose | ||
# -rsxX: show extra test summary info for (s)skipped, (x)failed, (X)passed | ||
# -l: show locals in tracebacks | ||
# --tb=short: short traceback print mode | ||
# --strict: marks not registered in configuration file raise errors | ||
pytest --cov=code42cli --cov-report xml -v -rsxX -l --tb=short --strict | ||
pytest --cov=code42cli --cov-report xml -v -rsxX -l --tb=short --strict -m "not integration" | ||
|
||
[testenv:docs] | ||
deps = | ||
|
@@ -44,3 +45,7 @@ deps = | |
pytest-cov == 2.10.0 | ||
git+https://github.com/code42/py42.git@master#egg=py42 | ||
git+ssh://[email protected]/code42/c42eventextractor.git@master#egg=c42eventextractor | ||
|
||
[pytest] | ||
markers = | ||
integration: mark test as a integration test. |
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.
These negative tests should fall under unit tests.
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.
Yes I agree. Should we move them to their respective unit test modules? There might some tests of this similar nature dispersed already, but I know there is not a ton