Skip to content

Commit 8518822

Browse files
committedFeb 11, 2020
Fix validator report printing and filtering
- Prints the errors that happened during validation (was only printing a message not the actual errors) - Sets all validators to return True/False instead of values. This ensures consistency for the validators structure and also solves issues were when there were errors/warnings printed out validators that weren't returning True/False as values were also printed as errors in the report (specifically the KeyDescriptor check and the application identifier format check)
1 parent 651284d commit 8518822

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed
 

‎src/saml2/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,11 @@ def validate_node_country_format(node_country):
606606

607607
@staticmethod
608608
def validate_application_identifier_format(application_identifier):
609-
if not application_identifier:
609+
pattern_match = re.search(r"([a-zA-Z0-9])+:([a-zA-Z0-9():_\-])+:([0-9])+"
610+
r"(\.([0-9])+){1,2}", application_identifier)
611+
if not application_identifier or pattern_match:
610612
return True
611-
612-
return re.search(r"([a-zA-Z0-9])+:([a-zA-Z0-9():_\-])+:([0-9])+"
613-
r"(\.([0-9])+){1,2}", application_identifier)
613+
return False
614614

615615
@staticmethod
616616
def get_type_contact_person(contacts, ctype):
@@ -652,7 +652,7 @@ def warning_validators(self):
652652
def error_validators(self):
653653
return {
654654
"KeyDescriptor MUST be declared":
655-
self.cert_file or self.encryption_keypairs,
655+
not_empty(self.cert_file or self.encryption_keypairs),
656656
"node_country MUST be declared in ISO 3166-1 alpha-2 format":
657657
self.validate_node_country_format(self.get_node_country()),
658658
"application_identifier MUST be in the form <vendor name>:<software "
@@ -674,7 +674,7 @@ def validate(self):
674674
)
675675

676676
if not all(self.error_validators.values()):
677-
error = "Configuration validation errors occurred:".format(
677+
error = "Configuration validation errors occurred {}:".format(
678678
[msg for msg, check in self.error_validators.items()
679679
if check is not True])
680680
logger.error(error)

0 commit comments

Comments
 (0)