Skip to content

Commit 684523a

Browse files
authored
Merge pull request #360 from rebeckag/flatten-nested-attributes
Flatten eduPersonTargetedID when converting it.
2 parents 17e6883 + 9c416a0 commit 684523a

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

src/saml2/attribute_converter.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,14 +377,17 @@ def ava_from(self, attribute, allow_unknown=False):
377377
ext = extension_elements_to_elements(value.extension_elements,
378378
[saml])
379379
for ex in ext:
380-
cval = {}
381-
for key, (name, typ, mul) in ex.c_attributes.items():
382-
exv = getattr(ex, name)
383-
if exv:
384-
cval[name] = exv
385-
if ex.text:
386-
cval["value"] = ex.text.strip()
387-
val.append({ex.c_tag: cval})
380+
if attr == "eduPersonTargetedID" and ex.text:
381+
val.append(ex.text.strip())
382+
else:
383+
cval = {}
384+
for key, (name, typ, mul) in ex.c_attributes.items():
385+
exv = getattr(ex, name)
386+
if exv:
387+
cval[name] = exv
388+
if ex.text:
389+
cval["value"] = ex.text.strip()
390+
val.append({ex.c_tag: cval})
388391
elif not value.text:
389392
val.append('')
390393
else:

tests/test_44_authnresp.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,65 @@ def test_verify_w_authn(self):
131131
session_info = self.ar.session_info()
132132
assert session_info["authn_info"] == authn_info
133133

134+
def test_unpack_nested_eptid(self):
135+
authn_response_xml = """<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
136+
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
137+
ID="CORTO54673f841c5297dd3614527d38e217332f9e3000"
138+
Version="2.0"
139+
IssueInstant="2016-09-23T14:00:45Z"
140+
Destination="https://sp.example.com/acs/post"
141+
InResponseTo="id-Wnv7CMQO1pFJoRWgi"
142+
>
143+
<saml:Issuer>https://idp.example.com</saml:Issuer>
144+
<samlp:Status>
145+
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
146+
</samlp:Status>
147+
<saml:Assertion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
148+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
149+
ID="CORTOadad7cb5e1237cf30fa7ab49544c15eec582854e"
150+
Version="2.0"
151+
IssueInstant="2016-09-23T14:00:45Z"
152+
>
153+
<saml:Issuer>https://idp.example.com</saml:Issuer>
154+
<saml:Subject>
155+
<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">b8e734571d9adb0e6444a5b49a22f4206df24d88</saml:NameID>
156+
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
157+
<saml:SubjectConfirmationData Recipient="https://sp.example.com/acs/post"
158+
InResponseTo="id-Wnv7CMQO1pFJoRWgi"
159+
/>
160+
</saml:SubjectConfirmation>
161+
</saml:Subject>
162+
<saml:Conditions NotBefore="2016-09-23T14:00:44Z">
163+
<saml:AudienceRestriction>
164+
<saml:Audience>https://sp.example.com</saml:Audience>
165+
</saml:AudienceRestriction>
166+
</saml:Conditions>
167+
<saml:AuthnStatement AuthnInstant="2016-09-23T13:55:40Z"
168+
SessionIndex="_9f1148918f12525c6cad9aea29bc557afab2cb8c33"
169+
>
170+
<saml:AuthnContext>
171+
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
172+
<saml:AuthenticatingAuthority>https://idp.example.com</saml:AuthenticatingAuthority>
173+
</saml:AuthnContext>
174+
</saml:AuthnStatement>
175+
<saml:AttributeStatement>
176+
<saml:Attribute Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10"
177+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
178+
>
179+
<saml:AttributeValue>
180+
<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">b8e734571d9adb0e6444a5b49a22f4206df24d88</saml:NameID>
181+
</saml:AttributeValue>
182+
</saml:Attribute>
183+
</saml:AttributeStatement>
184+
</saml:Assertion>
185+
</samlp:Response>"""
186+
187+
resp = authn_response(self.conf, "https://sp.example.com/acs/post", asynchop=False, allow_unsolicited=True)
188+
resp.loads(authn_response_xml, False)
189+
resp.parse_assertion()
190+
ava = resp.get_identity()
191+
assert ava["eduPersonTargetedID"] == ["b8e734571d9adb0e6444a5b49a22f4206df24d88"]
192+
134193
if __name__ == "__main__":
135194
t = TestAuthnResponse()
136195
t.setup_class()

0 commit comments

Comments
 (0)