summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kanakarakis <ivan.kanak@gmail.com>2020-09-29 15:48:31 +0300
committerGitHub <noreply@github.com>2020-09-29 15:48:31 +0300
commitec2ccd72beb12ab1f81c63c46953aaa764142209 (patch)
tree8216cd98540bf3fc9aa85a369ff005af047068db
parent745e0dd16982d4d34a2af10849c0de0fd283b3b5 (diff)
parentb7a77f79441c61adfbce5aa111aefa3f52a34365 (diff)
downloadpysaml2-ec2ccd72beb12ab1f81c63c46953aaa764142209.tar.gz
Merge pull request #704 from canderson90/fix-601-default-nameformat
Set the default attribute NameFormat to NAME_FORMAT_UNSPECIFIED
-rw-r--r--src/saml2/saml.py5
-rw-r--r--tests/remote_data/InCommon-metadata-export.xml2
-rw-r--r--tests/remote_data/metadata.aaitest.xml2
-rw-r--r--tests/test_20_assertion.py18
4 files changed, 24 insertions, 3 deletions
diff --git a/src/saml2/saml.py b/src/saml2/saml.py
index 9753def0..52e7429b 100644
--- a/src/saml2/saml.py
+++ b/src/saml2/saml.py
@@ -1098,6 +1098,11 @@ class AttributeType_(SamlBase):
self.name_format = name_format
self.friendly_name = friendly_name
+ # when consuming such elements, default to NAME_FORMAT_UNSPECIFIED as NameFormat
+ def harvest_element_tree(self, tree):
+ tree.attrib.setdefault('NameFormat', NAME_FORMAT_UNSPECIFIED)
+ SamlBase.harvest_element_tree(self, tree)
+
def attribute_type__from_string(xml_string):
return saml2.create_class_from_xml_string(AttributeType_, xml_string)
diff --git a/tests/remote_data/InCommon-metadata-export.xml b/tests/remote_data/InCommon-metadata-export.xml
index d67e6afa..5ac71b11 100644
--- a/tests/remote_data/InCommon-metadata-export.xml
+++ b/tests/remote_data/InCommon-metadata-export.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:shibmd="urn:mace:shibboleth:metadata:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="_20191126T193752" validUntil="9999-01-01T00:00:00Z">
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:shibmd="urn:mace:shibboleth:metadata:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="_20191126T193752" validUntil="3001-01-01T00:00:00Z">
<md:Extensions xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi">
<mdrpi:PublicationInfo creationInstant="2019-11-26T19:37:52Z" publisher="https://incommon.org"/>
</md:Extensions>
diff --git a/tests/remote_data/metadata.aaitest.xml b/tests/remote_data/metadata.aaitest.xml
index 2c5b8824..6f1ec013 100644
--- a/tests/remote_data/metadata.aaitest.xml
+++ b/tests/remote_data/metadata.aaitest.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi" xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui" xmlns:shibmd="urn:mace:shibboleth:metadata:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="AAITest-20191127170144" Name="urn:mace:switch.ch:aaitest" validUntil="9999-01-01T00:00:00Z" xsi:schemaLocation="urn:oasis:names:tc:SAML:2.0:metadata saml-schema-metadata-2.0.xsd urn:mace:shibboleth:metadata:1.0 shibboleth-metadata-1.0.xsd http://www.w3.org/2000/09/xmldsig# xmldsig-core-schema.xsd">
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><EntitiesDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi" xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui" xmlns:shibmd="urn:mace:shibboleth:metadata:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="AAITest-20191127170144" Name="urn:mace:switch.ch:aaitest" validUntil="3001-01-01T00:00:00Z" xsi:schemaLocation="urn:oasis:names:tc:SAML:2.0:metadata saml-schema-metadata-2.0.xsd urn:mace:shibboleth:metadata:1.0 shibboleth-metadata-1.0.xsd http://www.w3.org/2000/09/xmldsig# xmldsig-core-schema.xsd">
<!--
This metadata file is generated for the AAI Test federation,
which is for development and testing purposes only!
diff --git a/tests/test_20_assertion.py b/tests/test_20_assertion.py
index bb4dbb73..f617e516 100644
--- a/tests/test_20_assertion.py
+++ b/tests/test_20_assertion.py
@@ -2,11 +2,12 @@
from saml2.argtree import add_path
from saml2.authn_context import pword
from saml2.mdie import to_dict
-from saml2 import md, assertion
+from saml2 import md, assertion, create_class_from_xml_string
from saml2.saml import Attribute
from saml2.saml import Issuer
from saml2.saml import NAMEID_FORMAT_ENTITY
from saml2.saml import NAME_FORMAT_URI
+from saml2.saml import NAME_FORMAT_UNSPECIFIED
from saml2.saml import AttributeValue
from saml2.saml import NameID
from saml2.saml import NAMEID_FORMAT_TRANSIENT
@@ -942,6 +943,21 @@ def test_assertion_with_authn_instant():
assert msg.authn_statement[0].authn_instant == "2009-02-13T23:31:30Z"
+def test_attribute_producer_should_default_to_uri():
+ attr = Attribute()
+ assert attr.name_format == NAME_FORMAT_URI
+
+
+def test_attribute_consumer_should_default_to_unspecified():
+ attr_str = """
+ <saml:Attribute Name="uid" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <saml:AttributeValue xsi:type="xs:string">test</saml:AttributeValue>
+ </saml:Attribute>
+ """
+ attr = create_class_from_xml_string(Attribute, attr_str)
+ assert attr.name_format == NAME_FORMAT_UNSPECIFIED
+
+
if __name__ == "__main__":
test_assertion_2()