Skip to content

Commit 2711b0f

Browse files
author
Josh Wetzel
committed
Use to_s for requested attribute value
1 parent b3ac5bd commit 2711b0f

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

lib/onelogin/ruby-saml/metadata.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ module OneLogin
88
module RubySaml
99

1010
# SAML2 Metadata. XML Metadata Builder
11-
#
11+
#
1212
class Metadata
1313

1414
# Return SP metadata based on the settings.
1515
# @param settings [OneLogin::RubySaml::Settings|nil] Toolkit settings
16-
# @param pretty_print [Boolean] Pretty print or not the response
16+
# @param pretty_print [Boolean] Pretty print or not the response
1717
# (No pretty print if you gonna validate the signature)
1818
# @return [String] XML Metadata of the Service Provider
1919
#
@@ -83,7 +83,7 @@ def generate(settings, pretty_print=false)
8383
if settings.attribute_consuming_service.configured?
8484
sp_acs = sp_sso.add_element "md:AttributeConsumingService", {
8585
"isDefault" => "true",
86-
"index" => settings.attribute_consuming_service.index
86+
"index" => settings.attribute_consuming_service.index
8787
}
8888
srv_name = sp_acs.add_element "md:ServiceName", {
8989
"xml:lang" => "en"
@@ -92,14 +92,14 @@ def generate(settings, pretty_print=false)
9292
settings.attribute_consuming_service.attributes.each do |attribute|
9393
sp_req_attr = sp_acs.add_element "md:RequestedAttribute", {
9494
"NameFormat" => attribute[:name_format],
95-
"Name" => attribute[:name],
95+
"Name" => attribute[:name],
9696
"FriendlyName" => attribute[:friendly_name],
9797
"isRequired" => attribute[:is_required] || false
9898
}
9999
unless attribute[:attribute_value].nil?
100100
Array(attribute[:attribute_value]).each do |value|
101101
sp_attr_val = sp_req_attr.add_element "saml:AttributeValue"
102-
sp_attr_val.text = value.to_str
102+
sp_attr_val.text = value.to_s
103103
end
104104
end
105105
end
@@ -121,7 +121,7 @@ def generate(settings, pretty_print=false)
121121
# pretty print the XML so IdP administrators can easily see what the SP supports
122122
if pretty_print
123123
meta_doc.write(ret, 1)
124-
else
124+
else
125125
ret = meta_doc.to_s
126126
end
127127

test/metadata_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MetadataTest < Minitest::Test
3232
assert_equal "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", REXML::XPath.first(xml_doc, "//md:NameIDFormat").text.strip
3333

3434
assert_equal "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST", acs.attribute("Binding").value
35-
assert_equal "https://foo.example/saml/consume", acs.attribute("Location").value
35+
assert_equal "https://foo.example/saml/consume", acs.attribute("Location").value
3636

3737
assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
3838
end
@@ -225,7 +225,7 @@ class MetadataTest < Minitest::Test
225225
before do
226226
settings.attribute_consuming_service.configure do
227227
service_name "Test Service"
228-
add_attribute(:name => "Name", :name_format => "Name Format", :friendly_name => "Friendly Name", :attribute_value => ["Attribute Value One", "Attribute Value Two"])
228+
add_attribute(:name => 'Name', :name_format => 'Name Format', :friendly_name => 'Friendly Name', :attribute_value => ['Attribute Value One', false])
229229
end
230230
end
231231

@@ -240,20 +240,20 @@ class MetadataTest < Minitest::Test
240240

241241
attribute_values = REXML::XPath.match(xml_doc, "//saml:AttributeValue").map(&:text)
242242
assert_equal "Attribute Value One", attribute_values[0]
243-
assert_equal "Attribute Value Two", attribute_values[1]
243+
assert_equal 'false', attribute_values[1]
244244

245245
assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
246246
end
247247
end
248248

249249
describe "when attribute service is configured" do
250-
let(:attr_svc) { REXML::XPath.first(xml_doc, "//md:AttributeConsumingService") }
251-
let(:req_attr) { REXML::XPath.first(xml_doc, "//md:RequestedAttribute") }
250+
let(:attr_svc) { REXML::XPath.first(xml_doc, '//md:AttributeConsumingService') }
251+
let(:req_attr) { REXML::XPath.first(xml_doc, '//md:RequestedAttribute') }
252252

253253
before do
254254
settings.attribute_consuming_service.configure do
255255
service_name "Test Service"
256-
add_attribute(:name => "Name", :name_format => "Name Format", :friendly_name => "Friendly Name", :attribute_value => "Attribute Value")
256+
add_attribute(:name => 'active', :name_format => 'format', :friendly_name => 'Active', :attribute_value => true)
257257
end
258258
end
259259

@@ -262,10 +262,10 @@ class MetadataTest < Minitest::Test
262262
assert_equal "1", attr_svc.attribute("index").value
263263
assert_equal REXML::XPath.first(xml_doc, "//md:ServiceName").text.strip, "Test Service"
264264

265-
assert_equal "Name", req_attr.attribute("Name").value
266-
assert_equal "Name Format", req_attr.attribute("NameFormat").value
267-
assert_equal "Friendly Name", req_attr.attribute("FriendlyName").value
268-
assert_equal "Attribute Value", REXML::XPath.first(xml_doc, "//saml:AttributeValue").text.strip
265+
assert_equal 'active', req_attr.attribute('Name').value
266+
assert_equal 'format', req_attr.attribute('NameFormat').value
267+
assert_equal 'Active', req_attr.attribute('FriendlyName').value
268+
assert_equal 'true', REXML::XPath.first(xml_doc, '//saml:AttributeValue').text.strip
269269

270270
assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
271271
end
@@ -303,7 +303,7 @@ class MetadataTest < Minitest::Test
303303
assert_match %r[<ds:SignatureMethod Algorithm='http://www.w3.org/2000/09/xmldsig#rsa-sha1'/>], xml_text
304304
assert_match %r[<ds:DigestMethod Algorithm='http://www.w3.org/2000/09/xmldsig#sha1'/>], xml_text
305305
signed_metadata = XMLSecurity::SignedDocument.new(xml_text)
306-
assert signed_metadata.validate_document(ruby_saml_cert_fingerprint, false)
306+
assert signed_metadata.validate_document(ruby_saml_cert_fingerprint, false)
307307

308308
assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
309309
end
@@ -321,7 +321,7 @@ class MetadataTest < Minitest::Test
321321

322322
signed_metadata_2 = XMLSecurity::SignedDocument.new(xml_text)
323323

324-
assert signed_metadata_2.validate_document(ruby_saml_cert_fingerprint, false)
324+
assert signed_metadata_2.validate_document(ruby_saml_cert_fingerprint, false)
325325

326326
assert validate_xml!(xml_text, "saml-schema-metadata-2.0.xsd")
327327
end

0 commit comments

Comments
 (0)