-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated service class unit tests (#31)
* Package layout updates * Package updates * Cleaning up tabs * README and LICENSE updates * More package testing * Broken link fixes * Uber class custom headers, Content-Type retained * v0.1.8 - Uber class custom headers * Uber class fix for octet-stream file uploads * README.md updates * Package development status alignment * Typo fix in README.md * Minor README.md text edits * Initial unit tests: Service and Uber Auth / Revoke * Initial unit tests: CCAWS - GetAWSSettings * Uber class fix for non-JSON API responses * Updated to support GitHub workflow execution * Working directory fix * Fixed authorization unit test 500 error * Adjusted workflow directory * Added working directory * Changed working directory * Working directory debugging * Debugging workflows * Lessee if this werks... * Reverted linting.yml change * Now there's a test package * Pytest debugging * Trying it another way * Another variation * Fix to reduce flakiness in test_authorization.py * Comment typo * New unit tests for: AWS Accounts APIs * New unit tests, requires updated svc classes * Added coverage to test workflow * GitHub workflow debugging * Workaround for GitHub to CS API rate limiting * Added pytest skips for rate limit barriers * Added pytest skips for rate limit barriers * Added pytest skips for rate limit barriers Co-authored-by: Shawn Wells <shawn.d.wells@gmail.com>
- Loading branch information
1 parent
85d5782
commit 9cbaed5
Showing
19 changed files
with
1,080 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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,55 @@ | ||
# test_detects.py | ||
# This class tests the detects service class | ||
|
||
import json | ||
import os | ||
import sys | ||
import pytest | ||
# Authentication via the test_authorization.py | ||
from tests import test_authorization as Authorization | ||
|
||
#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 detects as FalconDetections | ||
|
||
auth = Authorization.TestAuthorization() | ||
auth.serviceAuth() | ||
falcon = FalconDetections.Detects(access_token=auth.token) | ||
AllowedResponses = [200, 429] #Adding rate-limiting as an allowed response for now | ||
|
||
class TestDetects: | ||
|
||
def serviceDetects_QueryDetects(self): | ||
if falcon.QueryDetects(parameters={"limit":1})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
@pytest.mark.skipif(falcon.QueryDetects(parameters={"limit":1})["status_code"] == 429, reason="API rate limit reached") | ||
def serviceDetects_GetDetectSummaries(self): | ||
if falcon.GetDetectSummaries(body={"ids":falcon.QueryDetects(parameters={"limit":1})["body"]["resources"]})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
# def serviceDetects_GetAggregateDetects(self): | ||
# auth, falcon = self.authenticate() | ||
# if falcon.GetAggregateDetects(body={"ids":falcon.QueryDetects(parameters={"limit":1})["body"]["resources"]})["status_code"] in AllowedResponses: | ||
# auth.serviceRevoke() | ||
# return True | ||
# else: | ||
# auth.serviceRevoke() | ||
# return False | ||
|
||
def test_QueryDetects(self): | ||
assert self.serviceDetects_QueryDetects() == True | ||
|
||
def test_GetDetectSummaries(self): | ||
assert self.serviceDetects_GetDetectSummaries() == True | ||
|
||
# def test_GetAggregateDetects(self): | ||
# assert self.serviceDetects_GetAggregateDetects() == True | ||
|
||
def test_logout(self): | ||
assert auth.serviceRevoke() == True |
This file contains 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,72 @@ | ||
# test_device_control_poligies.py | ||
# This class tests the device_control_policies service class | ||
|
||
import json | ||
import os | ||
import sys | ||
import pytest | ||
# Authentication via the test_authorization.py | ||
from tests import test_authorization as Authorization | ||
|
||
#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 device_control_policies as FalconDeviceControlPolicy | ||
|
||
auth = Authorization.TestAuthorization() | ||
auth.serviceAuth() | ||
falcon = FalconDeviceControlPolicy.Device_Control_Policies(access_token=auth.token) | ||
AllowedResponses = [200, 429] #Adding rate-limiting as an allowed response for now | ||
|
||
class TestDeviceControlPolicy: | ||
|
||
def serviceDeviceControlPolicies_queryDeviceControlPolicies(self): | ||
if falcon.queryDeviceControlPolicies(parameters={"limit":1})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
@pytest.mark.skipif(falcon.queryDeviceControlPolicies(parameters={"limit":1})["status_code"] == 429, reason="API rate limit reached") | ||
def serviceDeviceControlPolicies_queryDeviceControlPolicyMembers(self): | ||
if falcon.queryDeviceControlPolicyMembers(parameters={"id": falcon.queryDeviceControlPolicies(parameters={"limit":1})["body"]["resources"][0]})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
@pytest.mark.skipif(falcon.queryDeviceControlPolicies(parameters={"limit":1})["status_code"] == 429, reason="API rate limit reached") | ||
def serviceDeviceControlPolicies_getDeviceControlPolicies(self): | ||
if falcon.getDeviceControlPolicies(ids=falcon.queryDeviceControlPolicies(parameters={"limit":1})["body"]["resources"][0])["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
def serviceDeviceControlPolicies_queryCombinedDeviceControlPolicies(self): | ||
if falcon.queryCombinedDeviceControlPolicies(parameters={"limit":1})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
@pytest.mark.skipif(falcon.queryCombinedDeviceControlPolicies(parameters={"limit":1})["status_code"] == 429, reason="API rate limit reached") | ||
def serviceDeviceControlPolicies_queryCombinedDeviceControlPolicyMembers(self): | ||
if falcon.queryCombinedDeviceControlPolicyMembers(parameters={"id": falcon.queryCombinedDeviceControlPolicies(parameters={"limit":1})["body"]["resources"][0]["id"]})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
def test_queryDeviceControlPolicies(self): | ||
assert self.serviceDeviceControlPolicies_queryDeviceControlPolicies() == True | ||
|
||
def test_queryDeviceControlPolicyMembers(self): | ||
assert self.serviceDeviceControlPolicies_queryDeviceControlPolicyMembers() == True | ||
|
||
def test_getDeviceControlPolicies(self): | ||
assert self.serviceDeviceControlPolicies_getDeviceControlPolicies() == True | ||
|
||
def test_queryCombinedDeviceControlPolicies(self): | ||
assert self.serviceDeviceControlPolicies_queryCombinedDeviceControlPolicies() == True | ||
|
||
def test_queryCombinedDeviceControlPolicyMembers(self): | ||
assert self.serviceDeviceControlPolicies_queryCombinedDeviceControlPolicyMembers() == True | ||
|
||
def test_logout(self): | ||
assert auth.serviceRevoke() == True |
This file contains 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,49 @@ | ||
# test_event_streams.py | ||
# This class tests the event_streams service class | ||
|
||
import json | ||
import os | ||
import sys | ||
import datetime | ||
import requests | ||
import pytest | ||
# Authentication via the test_authorization.py | ||
from tests import test_authorization as Authorization | ||
|
||
#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 event_streams as FalconStream | ||
|
||
auth = Authorization.TestAuthorization() | ||
auth.serviceAuth() | ||
falcon = FalconStream.Event_Streams(access_token=auth.token) | ||
AllowedResponses = [200, 429] #Adding rate-limiting as an allowed response for now | ||
appId = "pytest-event_streams-unit-test" | ||
class TestEventStreams: | ||
|
||
def serviceStream_listAvailableStreamsOAuth2(self): | ||
if falcon.listAvailableStreamsOAuth2(parameters={"appId":appId})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
@pytest.mark.skipif(falcon.listAvailableStreamsOAuth2(parameters={"appId":appId})["status_code"] == 429, reason="API rate limit reached") | ||
def serviceStream_refreshActiveStreamSession(self): | ||
avail = falcon.listAvailableStreamsOAuth2(parameters={"appId":appId}) | ||
t1 = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S +0000') | ||
headers = {'Authorization': 'Token %s' % (avail["body"]["resources"][0]["sessionToken"]["token"]), 'Date': t1, 'Connection': 'Keep-Alive'} | ||
stream = requests.get(avail["body"]["resources"][0]["dataFeedURL"], headers=headers, stream=True) | ||
with stream: | ||
if falcon.refreshActiveStreamSession(parameters={"appId": appId, "action_name":"refresh_active_stream_session"}, partition=0)["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
def test_listAvailableStreamsOAuth2(self): | ||
assert self.serviceStream_listAvailableStreamsOAuth2() == True | ||
|
||
def test_refreshActiveStreamSession(self): | ||
assert self.serviceStream_refreshActiveStreamSession() == True | ||
|
||
def test_logout(self): | ||
assert auth.serviceRevoke() == True |
This file contains 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,52 @@ | ||
# test_falconx_sandbox.py | ||
# This class tests the falconx_sandbox service class | ||
|
||
import json | ||
import os | ||
import sys | ||
import pytest | ||
# Authentication via the test_authorization.py | ||
from tests import test_authorization as Authorization | ||
|
||
#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 falconx_sandbox as FalconXSandbox | ||
|
||
auth = Authorization.TestAuthorization() | ||
auth.serviceAuth() | ||
falcon = FalconXSandbox.FalconX_Sandbox(access_token=auth.token) | ||
AllowedResponses = [200, 429] #Adding rate-limiting as an allowed response for now | ||
|
||
class TestFalconX: | ||
|
||
def serviceFalconX_QueryReports(self): | ||
if falcon.QueryReports(parameters={"limit":1})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
def serviceFalconX_QuerySubmissions(self): | ||
if falcon.QuerySubmissions(parameters={"limit":1})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
@pytest.mark.skipif(falcon.QueryReports(parameters={"limit":1})["status_code"] == 429, reason="API rate limit reached") | ||
def serviceFalconX_GetSummaryReports(self): | ||
if falcon.GetSummaryReports(ids=falcon.QueryReports(parameters={"limit":1})["body"]["resources"])["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
def test_QueryReports(self): | ||
assert self.serviceFalconX_QueryReports() == True | ||
|
||
def test_QuerySubmissions(self): | ||
assert self.serviceFalconX_QuerySubmissions() == True | ||
|
||
def test_GetSummaryReports(self): | ||
assert self.serviceFalconX_GetSummaryReports() == True | ||
|
||
def test_logout(self): | ||
assert auth.serviceRevoke() == True |
This file contains 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,33 @@ | ||
# test_firewall_management.py | ||
# This class tests the firewall_management service class | ||
|
||
import json | ||
import os | ||
import sys | ||
# Authentication via the test_authorization.py | ||
from tests import test_authorization as Authorization | ||
#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 firewall_management as FalconFirewall | ||
|
||
auth = Authorization.TestAuthorization() | ||
auth.serviceAuth() | ||
falcon = FalconFirewall.Firewall_Management(access_token=auth.token) | ||
AllowedResponses = [200, 429] #Adding rate-limiting as an allowed response for now | ||
|
||
class TestFirewallManagement: | ||
|
||
def serviceFirewall_query_rules(self): | ||
if falcon.query_rules(parameters={"limit":1})["status_code"] in AllowedResponses: | ||
return True | ||
else: | ||
return False | ||
|
||
# def test_query_rules(self): | ||
# assert self.serviceFirewall_query_rules() == True | ||
|
||
def test_logout(self): | ||
assert auth.serviceRevoke() == True | ||
|
||
#TODO: My current API key can't hit this API. Pending additional unit testing for now. |
Oops, something went wrong.