Skip to content

Commit

Permalink
Expand unit testing to complete code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jshcodes committed Sep 6, 2023
1 parent f1267fc commit 1f7655d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
12 changes: 9 additions & 3 deletions tests/test_authentications.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,21 @@ def serviceAny_forceCrossCloudResponseFailure(self):
return False

def serviceAny_forceCrossCloudResponseGovFailure(self):
_success = False
falcon = OAuth2(client_id=os.environ["CROSS_DEBUG_KEY"],
client_secret=os.environ["CROSS_DEBUG_SECRET"],
base_url="us1", debug=_DEBUG
)
result = falcon.token()
if result["status_code"] == 403:
return True
else:
return False
falcon = APIHarness(client_id=os.environ["CROSS_DEBUG_KEY"],
client_secret=os.environ["CROSS_DEBUG_SECRET"],
base_url="us1", debug=_DEBUG
)
result = falcon.authenticate()
if falcon.token_status == 403:
_success = True
return _success

def serviceAny_checkRegionNameLookups(self):
falcon = OAuth2(client_id=auth.config["falcon_client_id"],
Expand Down
9 changes: 8 additions & 1 deletion tests/test_falcon_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Import our sibling src folder into the path
sys.path.append(os.path.abspath('src'))
# Classes to test - manually imported from sibling folder
from falconpy import FalconContainer, APIHarness
from falconpy import FalconContainer, APIHarness, APIHarnessV2

auth = Authorization.TestAuthorization()
config = auth.getConfigObject()
Expand All @@ -18,6 +18,10 @@
client_secret=falcon.auth_object.creds["client_secret"],
base_url=falcon.auth_object.base_url
)
uber2 = APIHarnessV2(client_id=falcon.auth_object.creds["client_id"],
client_secret=falcon.auth_object.creds["client_secret"],
base_url=falcon.auth_object.base_url
)
AllowedResponses = [200, 201, 204, 400, 403, 404, 429, 500, 502] # Allowing no content returned as code paths are confirmed


Expand All @@ -33,6 +37,9 @@ def run_tests(self):
"GetAssessmentUber": uber.command("GetImageAssessmentReport", repository="misp", tag="latest"),
"DeleteImageDetailsUber": uber.command("DeleteImageDetails", image_id="12345678"),
"ImageMatchesPolicyUber": uber.command("ImageMatchesPolicy", repository="whatever", tag="whatever"),
"GetAssessmentUber2": uber2.command("GetImageAssessmentReport", repository="misp", tag="latest"),
"DeleteImageDetailsUber2": uber2.command("DeleteImageDetails", image_id="12345678"),
"ImageMatchesPolicyUber2": uber2.command("ImageMatchesPolicy", repository="whatever", tag="whatever"),
"read_image_vulnerabilities": falcon.read_image_vulnerabilities(osversion="Windows", packages={"LayerIndex": 1}),
"ReadRegistryEntities": falcon.read_registry_entities(),
"ReadRegistryEntitiesByUUID": falcon.read_registry_entities_by_uuid(ids="12345678"),
Expand Down
9 changes: 6 additions & 3 deletions tests/test_service_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ def test_auth_object_invalid_config(self):
@not_supported
def test_log_facility_shutdown(self):
_thing = OAuth2(creds=config.creds, debug=True)
if _thing.log_facility.active:
_thing.log_facility.deactivate_log()
_thing.login()
if _thing.authenticated() and not _thing.token_expired(): # Duplicative, testing methods
if _thing.log_facility.active:
_thing.log_facility.deactivate_log()

assert not _thing.log

Expand Down Expand Up @@ -364,7 +366,8 @@ def test_list_response_component_get_property_fail(self):
with pytest.warns(SSLDisabledWarning):
_no_ssl = Hosts(creds=config.creds, pythonic=True, debug=_DEBUG, ssl_verify=False)
try:
_thing: Result = _no_ssl.query_devices(limit=3)
if _no_ssl.token_valid and not _no_ssl.token_stale: # Duplicative, just testing the properties
_thing: Result = _no_ssl.query_devices(limit=3)
except APIError:
pytest.skip("SSL required for GovCloud testing.")

Expand Down
23 changes: 15 additions & 8 deletions tests/test_uber.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# flake8: noqa=E402
# pylint: disable=C0103
# Classes to test - manually imported from our sibling folder
from falconpy import APIAdvanced, APIError
from falconpy import APIHarnessV2, APIError
# Import perform_request from _util so we can test generating 405's directly
from falconpy._util import perform_request, force_default

Expand All @@ -37,7 +37,7 @@
else:
sys.exit(1)

falcon = APIAdvanced(
falcon = APIHarnessV2(
client_id=config["falcon_client_id"],
client_secret=config["falcon_client_secret"],
base_url=config["falcon_base_url"], debug=_DEBUG
Expand All @@ -46,10 +46,14 @@

class TestUber:
def uberCCAWS_GetAWSSettings(self):
returned = False
authenticated = falcon.authenticated()
expired = falcon.token_expired()
if falcon.command("GetAWSSettings")["status_code"] in AllowedResponses:
return True
returned = True
else:
return False
returned = False
return returned

def uberCCAWS_QueryAWSAccounts(self):
if falcon.command("QueryAWSAccounts", parameters={"limit": 1})["status_code"] in AllowedResponses:
Expand Down Expand Up @@ -235,14 +239,14 @@ def uberCCAWS_GenerateTokenError(self):
return returned

def uberCCAWS_BadAuthentication(self):
falcon = APIAdvanced(debug=_DEBUG)
falcon = APIHarnessV2(debug=_DEBUG)
if falcon.command("QueryAWSAccounts", parameters={"limit": 1})["status_code"] in AllowedResponses:
return True
else:
return False

def uberCCAWS_DisableSSLVerify(self):
falcon = APIAdvanced(
falcon = APIHarnessV2(
creds={
"client_id": config["falcon_client_id"],
"client_secret": config["falcon_client_secret"]
Expand Down Expand Up @@ -354,13 +358,16 @@ def test_uber_deprecated_attributes(self):

def test_uber_properties(self):
# Force a new object so we can flip the debug flag
temp_falcon = APIAdvanced(access_token=falcon.token_value,
temp_falcon = APIHarnessV2(access_token=falcon.token_value,
base_url=config["falcon_base_url"],
debug=True
)

assert bool(temp_falcon.debug)

def test_uber_token_generate(self):
assert(bool(falcon.command("oauth2AccessToken")["status_code"] == 201))

def test_uber_revoke_failure(self):
assert bool(falcon.command("oauth2RevokeToken")["status_code"] == 400)

Expand All @@ -371,7 +378,7 @@ def test_uber_revoke_success(self):

def test_pythonic_failure(self):
_success = False
new_falcon = APIAdvanced(access_token=falcon.token_value,
new_falcon = APIHarnessV2(access_token=falcon.token_value,
base_url=config["falcon_base_url"],
debug=_DEBUG,
pythonic=True
Expand Down
20 changes: 18 additions & 2 deletions tests/test_uber_api_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ def uberCCAWS_OverrideAndHeader(self):

def uberContainer_TestBodyIDsPayload(self):
successful = False
if falcon.command("GetDeviceDetails", ids="12345678")["status_code"] in AllowedResponses:
successful = True
if falcon.authenticated and not falcon.token_expired():
if falcon.command("GetDeviceDetails", ids="12345678")["status_code"] in AllowedResponses:
successful = True

return successful

Expand Down Expand Up @@ -339,6 +340,21 @@ def test_BadAuthentication(self):
def test_DisableSSLVerify(self):
assert self.uberCCAWS_DisableSSLVerify() is True

def test_crossover_properties(self):
_success = True
try:
_ = falcon.token_value
debug_setting = falcon.debug
pythonic_setting = falcon.pythonic
falcon.pythonic = False
debug_rec_count = falcon.debug_record_count
falcon.debug_record_count = 101
sanitize = falcon.sanitize_log
falcon.sanitize_log = True
except:
_success = False
assert _success

# def test_uber_deprecated_methods(self):
# assert bool(falcon.valid_cred_format()
# and falcon.headers()
Expand Down

0 comments on commit 1f7655d

Please sign in to comment.