|
8 | 8 | import re
|
9 | 9 | import sys
|
10 | 10 | from functools import partial
|
| 11 | +from iso3166 import countries |
11 | 12 |
|
12 | 13 | import six
|
13 | 14 |
|
@@ -587,30 +588,47 @@ def assert_declared(cls, error_signal):
|
587 | 588 | return (lambda x: x is not None,
|
588 | 589 | partial(error_signal, message="be declared"))
|
589 | 590 |
|
| 591 | + @staticmethod |
| 592 | + def validate_node_country_format(node_country): |
| 593 | + try: |
| 594 | + return countries.get(node_country).alpha2 == node_country |
| 595 | + except KeyError: |
| 596 | + return False |
| 597 | + |
590 | 598 |
|
591 | 599 | class eIDASSPConfig(SPConfig, eIDASConfig):
|
| 600 | + def get_endpoint_element(self, element): |
| 601 | + return getattr(self, "_sp_endpoints", {}).get(element, None) |
| 602 | + |
592 | 603 | def validate(self):
|
593 | 604 | validators = [
|
594 | 605 | RuleValidator(
|
595 | 606 | "single_logout_service",
|
596 |
| - self._sp_endpoints.get("single_logout_service"), |
| 607 | + self.get_endpoint_element("single_logout_service"), |
597 | 608 | *self.assert_not_declared(should_warning)
|
598 | 609 | ),
|
599 | 610 | RuleValidator(
|
600 | 611 | "artifact_resolution_service",
|
601 |
| - self._sp_endpoints.get("artifact_resolution_service"), |
| 612 | + self.get_endpoint_element("artifact_resolution_service"), |
602 | 613 | *self.assert_not_declared(should_warning)
|
603 | 614 | ),
|
604 | 615 | RuleValidator(
|
605 | 616 | "manage_name_id_service",
|
606 |
| - self._sp_endpoints.get("manage_name_id_service"), |
| 617 | + self.get_endpoint_element("manage_name_id_service"), |
607 | 618 | *self.assert_not_declared(should_warning)
|
608 | 619 | ),
|
609 | 620 | RuleValidator(
|
610 | 621 | "KeyDescriptor",
|
611 | 622 | self.cert_file or self.encryption_keypairs,
|
612 | 623 | *self.assert_declared(must_error)
|
613 |
| - ) |
| 624 | + ), |
| 625 | + RuleValidator( |
| 626 | + "node_country", |
| 627 | + getattr(self, "_sp_node_country", None), |
| 628 | + self.validate_node_country_format, |
| 629 | + partial(must_error, |
| 630 | + message="be declared in ISO 3166-1 alpha-2 format") |
| 631 | + ), |
614 | 632 | ]
|
615 | 633 |
|
616 | 634 | for validator in validators:
|
|
0 commit comments