Skip to content

Commit

Permalink
feat: handling CRITICAL errors when checks are loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Sep 28, 2021
1 parent ac12ec3 commit 13015fe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/spid_sp_test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


BASE_DIR = Path(__file__).resolve().parent
__version__ = "0.9.21"
__version__ = "0.9.22"
__name__ = "spid_sp_test"
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -139,7 +139,7 @@ def handle_init_errors(self, method, description, traceback=""):
test_id=[],
)
self.is_ok(method)
sys.exit(1)
raise Exception(traceback)

# maybe useful .. one day ?!
# idp_server = self.idp()
Expand Down
28 changes: 17 additions & 11 deletions src/spid_sp_test/authn_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,24 @@ def __init__(

self.logger = logger
self.metadata = metadata
self.authn_request_url = authn_request_url
self.production = production
self.authn_plugin = authn_plugin
self.request_method = request_method
self.request_body = request_body
self.request_content_type = request_content_type
self.xsds_files = xsds_files or self.xsds_files
self.xsds_files_path = xsds_files_path or f"{BASE_DIR}/xsd"

def load(self):
try:
self.authn_request = get_authn_request(
authn_request_url,
verify_ssl=production,
authn_plugin=authn_plugin,
request_method=request_method,
request_body=request_body,
request_content_type=request_content_type,
self.authn_request_url,
verify_ssl=self.production,
authn_plugin=self.authn_plugin,
request_method=self.request_method,
request_body=self.request_body,
request_content_type=self.request_content_type,
)
except binascii.Error as exp:
_msg = "Base64 decode of AuthnRequest MUST be correct"
Expand All @@ -225,9 +234,6 @@ def __init__(

self.relay_state = self.authn_request.get("RelayState") or ""

self.xsds_files = xsds_files or self.xsds_files
self.xsds_files_path = xsds_files_path or f"{BASE_DIR}/xsd"

try:
self.md = etree.fromstring(self.metadata)
del_ns(self.md)
Expand All @@ -239,14 +245,14 @@ def __init__(
_method = f"Error parsing AuthnRequest: {self.authn_request_decoded}"
self.handle_init_errors(
method = _method,
description = f"{e}"
description = f"{e}",
traceback=e
)

# binding detection
self.IS_HTTP_REDIRECT = self.authn_request.get("Signature")
# HTTP-REDIRECT params
self.params = {"RelayState": self.relay_state}
self.production = production

def idp(self):
idp_config = copy.deepcopy(SAML2_IDP_CONFIG)
Expand Down
14 changes: 12 additions & 2 deletions src/spid_sp_test/bin/spid_sp_test
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ if __name__ == '__main__':
data_md = dict(metadata_url=args.metadata_url,
production=args.production)
metadata_check = _cls(**data_md)
selective_run(metadata_check, profile, args.list)
try:
metadata_check.load()
selective_run(metadata_check, profile, args.list)
except Exception as e:
logger.critical(f"Errors occourred during Check, {_cls}: {e}")
args.authn_url = 0
tests_done.append(metadata_check)

else:
Expand All @@ -324,7 +329,12 @@ if __name__ == '__main__':
request_content_type = args.request_content_type
)
authn_check = _cls(**data_ac)
selective_run(authn_check, profile, args.list)
try:
authn_check.load()
selective_run(authn_check, profile, args.list)
except Exception as e:
logger.critical(f"Errors occourred during Check, {_cls}: {e}")
args.test_response = 0
tests_done.append(authn_check)

# Responses
Expand Down
4 changes: 3 additions & 1 deletion src/spid_sp_test/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ def __init__(
self.metadata = self.get(metadata_url)
self.xsds_files_path = xsds_files_path or f"{BASE_DIR}/xsd"

def load(self):
try:
self.doc = etree.fromstring(self.metadata)
except Exception as e:
_method = f"Error parsing Metadata: {self.metadata_url}"
self.handle_init_errors(
method = _method,
description = f"{e}"
description = f"{e}",
traceback=e
)
# clean up namespace (otherwise xpath doesn't work ...)
del_ns(self.doc)
Expand Down

0 comments on commit 13015fe

Please sign in to comment.