Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Always return attribute values as lists #5

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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