Skip to content

Commit ec2ccd7

Browse files
Merge pull request #704 from canderson90/fix-601-default-nameformat
Set the default attribute NameFormat to NAME_FORMAT_UNSPECIFIED
2 parents 745e0dd + b7a77f7 commit ec2ccd7

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/saml2/saml.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,11 @@ def __init__(self,
10981098
self.name_format = name_format
10991099
self.friendly_name = friendly_name
11001100

1101+
# when consuming such elements, default to NAME_FORMAT_UNSPECIFIED as NameFormat
1102+
def harvest_element_tree(self, tree):
1103+
tree.attrib.setdefault('NameFormat', NAME_FORMAT_UNSPECIFIED)
1104+
SamlBase.harvest_element_tree(self, tree)
1105+
11011106

11021107
def attribute_type__from_string(xml_string):
11031108
return saml2.create_class_from_xml_string(AttributeType_, xml_string)

tests/remote_data/InCommon-metadata-export.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?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">
1+
<?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">
22
<md:Extensions xmlns:mdrpi="urn:oasis:names:tc:SAML:metadata:rpi">
33
<mdrpi:PublicationInfo creationInstant="2019-11-26T19:37:52Z" publisher="https://incommon.org"/>
44
</md:Extensions>

tests/remote_data/metadata.aaitest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?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">
1+
<?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">
22
<!--
33
This metadata file is generated for the AAI Test federation,
44
which is for development and testing purposes only!

tests/test_20_assertion.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
from saml2.argtree import add_path
33
from saml2.authn_context import pword
44
from saml2.mdie import to_dict
5-
from saml2 import md, assertion
5+
from saml2 import md, assertion, create_class_from_xml_string
66
from saml2.saml import Attribute
77
from saml2.saml import Issuer
88
from saml2.saml import NAMEID_FORMAT_ENTITY
99
from saml2.saml import NAME_FORMAT_URI
10+
from saml2.saml import NAME_FORMAT_UNSPECIFIED
1011
from saml2.saml import AttributeValue
1112
from saml2.saml import NameID
1213
from saml2.saml import NAMEID_FORMAT_TRANSIENT
@@ -942,6 +943,21 @@ def test_assertion_with_authn_instant():
942943
assert msg.authn_statement[0].authn_instant == "2009-02-13T23:31:30Z"
943944

944945

946+
def test_attribute_producer_should_default_to_uri():
947+
attr = Attribute()
948+
assert attr.name_format == NAME_FORMAT_URI
949+
950+
951+
def test_attribute_consumer_should_default_to_unspecified():
952+
attr_str = """
953+
<saml:Attribute Name="uid" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
954+
<saml:AttributeValue xsi:type="xs:string">test</saml:AttributeValue>
955+
</saml:Attribute>
956+
"""
957+
attr = create_class_from_xml_string(Attribute, attr_str)
958+
assert attr.name_format == NAME_FORMAT_UNSPECIFIED
959+
960+
945961
if __name__ == "__main__":
946962
test_assertion_2()
947963

0 commit comments

Comments
 (0)