Skip to content

Commit

Permalink
Unit testing adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
jshcodes committed Mar 22, 2024
1 parent 6aad42b commit 7e5f623
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 35 deletions.
16 changes: 16 additions & 0 deletions tests/test_cloud_connect_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
if _DEBUG:
_DEBUG = True

usone_only = pytest.mark.skipif(falcon.base_url.lower() != "https://api.crowdstrike.com",
reason="US-1 unit testing only",
)

class TestCloudConnectAWS:
def serviceCCAWS_AuthWithCreds(self):
falconWithCreds = CloudConnectAWS(creds={
Expand Down Expand Up @@ -169,12 +173,15 @@ def serviceCCAWS_GenerateErrors(self):

return errorChecks

@usone_only
def test_GetAWSSettings(self):
assert bool(falcon.GetAWSSettings()["status_code"] in AllowedResponses) is True

@usone_only
def test_QueryAWSAccounts(self):
assert bool(falcon.QueryAWSAccounts(parameters={"limit": 1})["status_code"] in AllowedResponses) is True

@usone_only
@pytest.mark.skipif(falcon.QueryAWSAccounts(
parameters={"limit": 1}
)["status_code"] == 429, reason="API rate limit reached")
Expand All @@ -186,32 +193,41 @@ def test_GetAWSAccounts(self):
test_id = "123456789012"
assert bool(falcon.GetAWSAccounts(ids=test_id)["status_code"] in AllowedResponses) is True

@usone_only
@pytest.mark.skipif(falcon.QueryAWSAccounts(
parameters={"limit": 1}
)["status_code"] == 429, reason="API rate limit reached")
def test_GetAWSAccountsUsingList(self):
assert self.serviceCCAWS_GetAWSAccountsUsingList() is True

@usone_only
def test_QueryAWSAccountsForIDs(self):
assert bool(falcon.QueryAWSAccountsForIDs(parameters={"limit": 1})["status_code"] in AllowedResponses) is True

@usone_only
def test_AuthWithCreds(self):
assert self.serviceCCAWS_AuthWithCreds() is True

@usone_only
def test_AuthWithObject(self):
assert self.serviceCCAWS_AuthWithObject() is True

@usone_only
def test_RefreshToken(self):
assert self.serviceCCAWS_RefreshToken() is True

@usone_only
def test_InvalidPayloads(self):
assert self.serviceCCAWS_InvalidPayloads() is True

@usone_only
def test_ForceAttributeError(self):
assert self.serviceCCAWS_ForceAttributeError() is True

@usone_only
def test_argument_vs_keyword(self):
assert bool(falcon.get_aws_accounts("123456789012")["status_code"] in AllowedResponses) is True

@usone_only
def test_Errors(self):
assert self.serviceCCAWS_GenerateErrors() is True
7 changes: 4 additions & 3 deletions tests/test_intel.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ def intel_test_all_code_paths(self):
"query_mitre_attacks": falcon.QueryMitreAttacks("fancy-bear"),
"mitre_attacks": falcon.PostMitreAttacks(["fancy-bear", "slippy-spider"]),
"get_mitre_report": falcon.GetMitreReport(actor_id="fancy-bear", format="CSV"),
"get_malware_entities": falcon.get_malware_entities("fancy-bear"),
"query_mitre_attacks_for_malware": falcon.query_mitre_attacks_for_malware(ids="fancy-bear"),
"query_malware": falcon.query_malware(limit=1)
# "get_vulnerabilities": falcon.get_vulnerabilities(ids="12345678"),
# "query_vulnerabilities": falcon.query_vulnerabilities()
}
Expand All @@ -49,6 +46,10 @@ def intel_test_all_code_paths(self):
# US-1 only for now.
tests["get_vulnerabilities"] = falcon.get_vulnerabilities(ids="12345678")
tests["query_vulnerabilities"] = falcon.query_vulnerabilities()
tests["get_malware_entities"] = falcon.get_malware_entities("fancy-bear")
tests["query_mitre_attacks_for_malware"] = falcon.query_mitre_attacks_for_malware(ids="fancy-bear")
tests["query_malware"] = falcon.query_malware(limit=1)

for key in tests:
if isinstance(tests[key], dict): # Allow for GetMitreReport's binary response
if tests[key]["status_code"] not in AllowedResponses:
Expand Down
1 change: 1 addition & 0 deletions tests/test_result_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ def test_unnecessary_encoding_used_warning(self):
reason="Unit testing unavailable on US-GOV-1"
)
@not_supported
@pytest.mark.skipif("us-1" not in config.base_url, reason="This unit test is only supported in US-1.")
def test_pythonic_deprecation_warnings(self):
_success = False
with pytest.warns(SDKDeprecationWarning):
Expand Down
32 changes: 16 additions & 16 deletions tests/test_uber.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def uberCCAWS_TestUploadDownload(self):
return True

def uberCCAWS_GenerateError(self):
if falcon.command("QueryAWSAccounts", partition=0)["status_code"] in AllowedResponses:
if falcon.command("QueryDetects", partition=0)["status_code"] in AllowedResponses:
return True
else:
return False
Expand All @@ -169,7 +169,7 @@ def uberCCAWS_GenerateInvalidPayload(self):
return False

def uberCCAWS_OverrideAndHeader(self):
if falcon.command(override="GET,/cloud-connect-aws/combined/accounts/v1",
if falcon.command(override="GET,/detects/queries/detects/v1",
headers={"Nothing": "Special"})["status_code"] in AllowedResponses:
return True
else:
Expand All @@ -195,7 +195,7 @@ def uberCCAWS_TestMSSP(self):
return returned

def uberCCAWS_BadMethod(self):
if falcon.command(action="", override="BANANA,/cloud-connect-aws/combined/accounts/v1",
if falcon.command(action="", override="BANANA,/detects/queries/detects/v1",
headers={"Nothing": "Special"})["status_code"] in AllowedResponses:
return True
else:
Expand All @@ -208,7 +208,7 @@ def uberCCAWS_BadCommand(self):
return False

def uberCCAWS_GenerateServerError(self):
if falcon.command("GetAWSAccounts", ids="123", data=['Kerash!'])["status_code"] == 500:
if falcon.command("GetDetectSummaries", ids="123", data=['Kerash!'])["status_code"] == 500:
return True
else:
return False
Expand Down Expand Up @@ -247,7 +247,7 @@ def uberCCAWS_GenerateTokenError(self):

def uberCCAWS_BadAuthentication(self):
falcon = APIHarnessV2(debug=_DEBUG)
if falcon.command("QueryAWSAccounts", parameters={"limit": 1})["status_code"] in AllowedResponses:
if falcon.command("QueryDetects", parameters={"limit": 1})["status_code"] in AllowedResponses:
return True
else:
return False
Expand All @@ -259,7 +259,7 @@ def uberCCAWS_DisableSSLVerify(self):
"client_secret": config["falcon_client_secret"]
}, ssl_verify=False, base_url=config["falcon_base_url"], debug=_DEBUG
)
if falcon.command("QueryAWSAccounts", parameters={"limit": 1})["status_code"] in AllowedResponses:
if falcon.command("QueryDetects", parameters={"limit": 1})["status_code"] in AllowedResponses:
return True
else:
return False
Expand All @@ -279,25 +279,25 @@ def uber_test_distinct_field(self):
else:
return False

def test_GetAWSSettings(self):
assert self.uberCCAWS_GetAWSSettings() is True
# def test_GetAWSSettings(self):
# assert self.uberCCAWS_GetAWSSettings() is True

def test_reserved_words(self):
assert self.uber_test_invalid_reserved_word_payload() is True

def test_distinct_field(self):
assert self.uber_test_distinct_field() is True

def test_QueryAWSAccounts(self):
assert self.uberCCAWS_QueryAWSAccounts() is True
# def test_QueryAWSAccounts(self):
# assert self.uberCCAWS_QueryAWSAccounts() is True

@pytest.mark.skipif(falcon.command("QueryAWSAccounts",
parameters={"limit": 1})["status_code"] == 429, reason="API rate limit reached")
def test_GetAWSAccounts(self):
assert self.uberCCAWS_GetAWSAccounts() is True
# @pytest.mark.skipif(falcon.command("QueryAWSAccounts",
# parameters={"limit": 1})["status_code"] == 429, reason="API rate limit reached")
# def test_GetAWSAccounts(self):
# assert self.uberCCAWS_GetAWSAccounts() is True

def test_QueryAWSAccountsForIDs(self):
assert self.uberCCAWS_QueryAWSAccountsForIDs() is True
# def test_QueryAWSAccountsForIDs(self):
# assert self.uberCCAWS_QueryAWSAccountsForIDs() is True

@pytest.mark.skipif("laggar" in falcon.base_url, reason="US-GOV-1 testing disabled")
def test_UploadDownload(self):
Expand Down
32 changes: 16 additions & 16 deletions tests/test_uber_api_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def uberCCAWS_TestUploadDownload(self):
return True

def uberCCAWS_GenerateError(self):
if falcon.command("QueryAWSAccounts", partition=0)["status_code"] in AllowedResponses:
if falcon.command("QueryDetects", partition=0)["status_code"] in AllowedResponses:
return True
else:
return False
Expand All @@ -158,7 +158,7 @@ def uberCCAWS_GenerateInvalidPayload(self):
return False

def uberCCAWS_OverrideAndHeader(self):
if falcon.command(override="GET,/cloud-connect-aws/combined/accounts/v1",
if falcon.command(override="GET,/detects/queries/detects/v1",
headers={"Nothing": "Special"})["status_code"] in AllowedResponses:
return True
else:
Expand All @@ -185,7 +185,7 @@ def uberCCAWS_TestMSSP(self):
return returned

def uberCCAWS_BadMethod(self):
if falcon.command(action="", override="BANANA,/cloud-connect-aws/combined/accounts/v1",
if falcon.command(action="", override="BANANA,/detects/queries/detects/v1",
headers={"Nothing": "Special"})["status_code"] in AllowedResponses:
return True
else:
Expand All @@ -198,7 +198,7 @@ def uberCCAWS_BadCommand(self):
return False

def uberCCAWS_GenerateServerError(self):
if falcon.command("GetAWSAccounts", ids="123", data=['Kerash!'])["status_code"] == 500:
if falcon.command("GetDetectSummaries", ids="123", data=['Kerash!'])["status_code"] == 500:
return True
else:
return False
Expand Down Expand Up @@ -237,7 +237,7 @@ def uberCCAWS_GenerateTokenError(self):

def uberCCAWS_BadAuthentication(self):
falcon = APIHarness(debug=_DEBUG)
if falcon.command("QueryAWSAccounts", parameters={"limit": 1})["status_code"] in AllowedResponses:
if falcon.command("QueryDetects", parameters={"limit": 1})["status_code"] in AllowedResponses:
return True
else:
return False
Expand All @@ -249,7 +249,7 @@ def uberCCAWS_DisableSSLVerify(self):
"client_secret": config["falcon_client_secret"]
}, ssl_verify=False, base_url=config["falcon_base_url"], debug=_DEBUG
)
if falcon.command("QueryAWSAccounts", parameters={"limit": 1})["status_code"] in AllowedResponses:
if falcon.command("QueryDetects", parameters={"limit": 1})["status_code"] in AllowedResponses:
return True
else:
return False
Expand All @@ -269,25 +269,25 @@ def uber_test_distinct_field(self):
else:
return False

def test_GetAWSSettings(self):
assert self.uberCCAWS_GetAWSSettings() is True
# def test_GetAWSSettings(self):
# assert self.uberCCAWS_GetAWSSettings() is True

def test_reserved_words(self):
assert self.uber_test_invalid_reserved_word_payload() is True

def test_distinct_field(self):
assert self.uber_test_distinct_field() is True

def test_QueryAWSAccounts(self):
assert self.uberCCAWS_QueryAWSAccounts() is True
# def test_QueryAWSAccounts(self):
# assert self.uberCCAWS_QueryAWSAccounts() is True

@pytest.mark.skipif(falcon.command("QueryAWSAccounts",
parameters={"limit": 1})["status_code"] == 429, reason="API rate limit reached")
def test_GetAWSAccounts(self):
assert self.uberCCAWS_GetAWSAccounts() is True
# @pytest.mark.skipif(falcon.command("QueryAWSAccounts",
# parameters={"limit": 1})["status_code"] == 429, reason="API rate limit reached")
# def test_GetAWSAccounts(self):
# assert self.uberCCAWS_GetAWSAccounts() is True

def test_QueryAWSAccountsForIDs(self):
assert self.uberCCAWS_QueryAWSAccountsForIDs() is True
# def test_QueryAWSAccountsForIDs(self):
# assert self.uberCCAWS_QueryAWSAccountsForIDs() is True

@pytest.mark.skipif("laggar" in falcon.base_url, reason="US-GOV-1 testing disabled")
def test_UploadDownload(self):
Expand Down

0 comments on commit 7e5f623

Please sign in to comment.