Skip to content

Commit ce52a31

Browse files
authored
Merge pull request SAML-Toolkits#363 from treehouse/requested-attribute-multiple
Allow for multiple RequestedAttribute AttributeValues
2 parents 889aee0 + 08e8c62 commit ce52a31

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,3 +614,5 @@ settings.attribute_consuming_service.configure do
614614
add_attribute :name => "Another Attribute", :name_format => "Name Format", :friendly_name => "Friendly Name", :attribute_value => "Attribute Value"
615615
end
616616
```
617+
618+
The `attribute_value` option additionally accepts an array of possible values.

lib/onelogin/ruby-saml/metadata.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ def generate(settings, pretty_print=false)
8989
"FriendlyName" => attribute[:friendly_name]
9090
}
9191
unless attribute[:attribute_value].nil?
92-
sp_attr_val = sp_req_attr.add_element "saml:AttributeValue"
93-
sp_attr_val.text = attribute[:attribute_value]
92+
Array(attribute[:attribute_value]).each do |value|
93+
sp_attr_val = sp_req_attr.add_element "saml:AttributeValue"
94+
sp_attr_val.text = value.to_str
95+
end
9496
end
9597
end
9698
end

test/metadata_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,34 @@ class MetadataTest < Minitest::Test
132132
end
133133
end
134134

135+
describe "when attribute service is configured with multiple attribute values" do
136+
let(:attr_svc) { REXML::XPath.first(xml_doc, "//md:AttributeConsumingService") }
137+
let(:req_attr) { REXML::XPath.first(xml_doc, "//md:RequestedAttribute") }
138+
139+
before do
140+
settings.attribute_consuming_service.configure do
141+
service_name "Test Service"
142+
add_attribute(:name => "Name", :name_format => "Name Format", :friendly_name => "Friendly Name", :attribute_value => ["Attribute Value One", "Attribute Value Two"])
143+
end
144+
end
145+
146+
it "generates attribute service" do
147+
assert_equal "true", attr_svc.attribute("isDefault").value
148+
assert_equal "1", attr_svc.attribute("index").value
149+
assert_equal REXML::XPath.first(xml_doc, "//md:ServiceName").text.strip, "Test Service"
150+
151+
assert_equal "Name", req_attr.attribute("Name").value
152+
assert_equal "Name Format", req_attr.attribute("NameFormat").value
153+
assert_equal "Friendly Name", req_attr.attribute("FriendlyName").value
154+
155+
attribute_values = REXML::XPath.match(xml_doc, "//saml:AttributeValue").map(&:text)
156+
assert_equal "Attribute Value One", attribute_values[0]
157+
assert_equal "Attribute Value Two", attribute_values[1]
158+
159+
assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
160+
end
161+
end
162+
135163
describe "when attribute service is configured" do
136164
let(:attr_svc) { REXML::XPath.first(xml_doc, "//md:AttributeConsumingService") }
137165
let(:req_attr) { REXML::XPath.first(xml_doc, "//md:RequestedAttribute") }

0 commit comments

Comments
 (0)