Skip to content

Commit

Permalink
Fix to reduce test flakiness in test_authorization.py (#28)
Browse files Browse the repository at this point in the history
* 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

Co-authored-by: Shawn Wells <shawn.d.wells@gmail.com>
  • Loading branch information
jshcodes and shawndwells authored Dec 24, 2020
1 parent abf0000 commit 85d5782
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions tests/test_authorization.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# A valid CrowdStrike Falcon API key is required to run these tests.
# You can store these values in your environment (this is the preferred method).
# Example:
# export DEBUG_API_ID=CLIENT_ID_GOES_HERE
# export DEBUG_API_SECRET=CLIENT_SECRET_GOES_HERE
#
# You may also store these values locally in a configuration file.
# DO NOT SUBMIT A COMMIT OR A PR THAT INCLUDES YOUR CONFIGURATION FILE.
# API client ID & secret should be stored in tests/test.config in JSON format.
# {
# "falcon_client_id": "CLIENT_ID_GOES_HERE",
# "falcon_client_secret": "CLIENT_SECRET_GOES_HERE"
# }

import json
import os
import sys
Expand All @@ -13,51 +21,62 @@
from falconpy import api_complete as FalconSDK
from falconpy import oauth2 as FalconAuth


# The TestAuthorization class tests authentication and deauthentication
# for both the Uber and Service classes.
class TestAuthorization():
def getConfig(self):
#Grab our config parameters
try:
if "DEBUG_API_ID" in os.environ and "DEBUG_API_SECRET" in os.environ:
self.config = {}
self.config["falcon_client_id"] = os.getenv("DEBUG_API_ID")
self.config["falcon_client_secret"] = os.getenv("DEBUG_API_SECRET")
except:
with open('%s/test.config' % os.path.dirname(os.path.abspath(__file__)), 'r') as file_config:
self.config = json.loads(file_config.read())
return True
else:
cur_path = os.path.dirname(os.path.abspath(__file__))
if os.path.exists('%s/test.config' % cur_path):
with open('%s/test.config' % cur_path, 'r') as file_config:
self.config = json.loads(file_config.read())
return True
else:
return False

def uberAuth(self):
self.getConfig()
self.falcon = FalconSDK.APIHarness(creds={
"client_id": self.config["falcon_client_id"],
"client_secret": self.config["falcon_client_secret"]
}
)
self.falcon.authenticate()
if self.falcon.authenticated:
return True
status = self.getConfig()
if status:
self.falcon = FalconSDK.APIHarness(creds={
"client_id": self.config["falcon_client_id"],
"client_secret": self.config["falcon_client_secret"]
}
)
self.falcon.authenticate()
if self.falcon.authenticated:
return True
else:
return False
else:
return False

def uberRevoke(self):
return self.falcon.deauthenticate()

def serviceAuth(self):
self.getConfig()
self.authorization = FalconAuth.OAuth2(creds={
'client_id': self.config["falcon_client_id"],
'client_secret': self.config["falcon_client_secret"]
})
status = self.getConfig()
if status:
self.authorization = FalconAuth.OAuth2(creds={
'client_id': self.config["falcon_client_id"],
'client_secret': self.config["falcon_client_secret"]
})

try:
self.token = self.authorization.token()['body']['access_token']
try:
self.token = self.authorization.token()['body']['access_token']

except:
self.token = False

except:
self.token = False

if self.token:
return True
if self.token:
return True
else:
return False
else:
return False

Expand Down

0 comments on commit 85d5782

Please sign in to comment.