Skip to content

Commit

Permalink
feat: Always return attribute values as lists
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
sebn committed Dec 4, 2023
1 parent 77d1b75 commit bb9aa0b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/esaml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,11 @@ decode_assertion_attributes(Xml) ->
case [X#xmlAttribute.value || X <- AttrElem#xmlElement.attributes, X#xmlAttribute.name =:= 'Name'] of
[Name] ->
case xmerl_xpath:string("saml:AttributeValue/text()", AttrElem, [{namespace, Ns}]) of
[#xmlText{value = Value}] ->
[{common_attrib_map(Name), Value} | [{Name, Value} | In]];
[] ->
In;
List ->
if (length(List) > 0) ->
Value = [X#xmlText.value || X <- List, element(1, X) =:= xmlText],
[{common_attrib_map(Name), Value} | [{Name, Value} | In]];
true ->
In
end
Value = [X#xmlText.value || X <- List, element(1, X) =:= xmlText],
[{common_attrib_map(Name), Value} | [{Name, Value} | In]]
end;
_ -> In
end
Expand Down Expand Up @@ -660,7 +656,7 @@ decode_attributes_test() ->
{Doc, _} = xmerl_scan:string("<saml:Assertion xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" Version=\"2.0\" IssueInstant=\"test\"><saml:Subject><saml:NameID>foobar</saml:NameID><saml:SubjectConfirmation Method=\"urn:oasis:names:tc:SAML:2.0:cm:bearer\"><saml:SubjectConfirmationData Recipient=\"foobar123\" /></saml:SubjectConfirmation></saml:Subject><saml:AttributeStatement><saml:Attribute Name=\"urn:oid:0.9.2342.19200300.100.1.3\"><saml:AttributeValue>[email protected]</saml:AttributeValue></saml:Attribute><saml:Attribute Name=\"foo\"><saml:AttributeValue>george</saml:AttributeValue><saml:AttributeValue>bar</saml:AttributeValue></saml:Attribute><saml:Attribute Name=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\"><saml:AttributeValue>[email protected]</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>", [{namespace_conformant, true}]),
Assertion = decode_assertion(Doc),
{ok, #esaml_assertion{attributes = Attrs}} = Assertion,
[{emailaddress, "[email protected]"}, {foo, ["george", "bar"]}, {mail, "[email protected]"}, {"foo",["george","bar"]}, {"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "[email protected]"}, {"urn:oid:0.9.2342.19200300.100.1.3", "[email protected]"}] = lists:sort(Attrs).
[{emailaddress, ["[email protected]"]}, {foo, ["george", "bar"]}, {mail, ["[email protected]"]}, {"foo",["george","bar"]}, {"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", ["[email protected]"]}, {"urn:oid:0.9.2342.19200300.100.1.3", ["[email protected]"]}] = lists:sort(Attrs).

decode_solicited_in_response_to_test() ->
{Doc, _} = xmerl_scan:string("<samlp:Response xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" Version=\"2.0\" IssueInstant=\"2013-01-01T01:01:01Z\"><saml:Issuer>foo</saml:Issuer><samlp:Status><samlp:StatusCode Value=\"urn:oasis:names:tc:SAML:2.0:status:Success\" /></samlp:Status><saml:Assertion Version=\"2.0\" IssueInstant=\"test\"><saml:Issuer>foo</saml:Issuer><saml:Subject><saml:NameID>foobar</saml:NameID><saml:SubjectConfirmation Method=\"urn:oasis:names:tc:SAML:2.0:cm:bearer\"><saml:SubjectConfirmationData Recipient=\"foobar123\" InResponseTo=\"_1234567890\" /></saml:SubjectConfirmation></saml:Subject><saml:Conditions NotBefore=\"before\" NotOnOrAfter=\"notafter\"><saml:AudienceRestriction><saml:Audience>foobaraudience</saml:Audience></saml:AudienceRestriction></saml:Conditions></saml:Assertion></samlp:Response>", [{namespace_conformant, true}]),
Expand Down

0 comments on commit bb9aa0b

Please sign in to comment.