Skip to content

Commit 5780b9d

Browse files
committed
Fixes onelogin#112 by extracting all Attribute values into single array
1 parent 02c6903 commit 5780b9d

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

lib/onelogin/ruby-saml/response.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def sessionindex
4949
end
5050
end
5151

52-
# A hash of alle the attributes with the response. Assuming there is only one value for each key
52+
# A hash of all the attributes with the response.
53+
# Multiple values will be returned in the AttributeValue#values array
5354
def attributes
5455
@attr_statements ||= begin
5556
result = {}
@@ -63,6 +64,11 @@ def attributes
6364

6465
# Set up a string-like wrapper for the values array
6566
attr_value = AttributeValue.new(values.first, values)
67+
# Merge values if the Attribute has already been seen
68+
if result[name]
69+
attr_value.values += result[name].values
70+
end
71+
6672
result[name] = attr_value
6773
end
6874

test/response_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ class RubySamlTest < Test::Unit::TestCase
239239
response = OneLogin::RubySaml::Response.new(fixture(:response_with_multiple_attribute_values))
240240
assert_equal ['value1', 'value2'], response.attributes[:another_value].values
241241
end
242+
243+
should "return last of multiple values when multiple Attribute tags in XML" do
244+
response = OneLogin::RubySaml::Response.new(fixture(:response_with_multiple_attribute_values))
245+
assert_equal 'role2', response.attributes[:role]
246+
end
247+
248+
should "return all of multiple values in reverse order when multiple Attribute tags in XML" do
249+
response = OneLogin::RubySaml::Response.new(fixture(:response_with_multiple_attribute_values))
250+
assert_equal ['role2', 'role1'], response.attributes[:role].values
251+
end
242252
end
243253
end
244254

test/responses/response_with_multiple_attribute_values.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
<saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">value1</saml:AttributeValue>
4747
<saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">value2</saml:AttributeValue>
4848
</saml:Attribute>
49+
<saml:Attribute Name="role">
50+
<saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">role1</saml:AttributeValue>
51+
</saml:Attribute>
52+
<saml:Attribute Name="role">
53+
<saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">role2</saml:AttributeValue>
54+
</saml:Attribute>
4955
</saml:AttributeStatement>
5056
</saml:Assertion>
5157
</samlp:Response>

0 commit comments

Comments
 (0)