Skip to content

Commit ffed02d

Browse files
committed
Metadata AuthnRequestsSigned and WantsAssertionsSigned + added MetadataTest
1 parent ce1fc7f commit ffed02d

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

lib/onelogin/ruby-saml/metadata.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,17 @@ def generate(settings)
4848
"index" => 0
4949
}
5050
end
51+
5152
# With OpenSSO, it might be required to also include
5253
# <md:RoleDescriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:query="urn:oasis:names:tc:SAML:metadata:ext:query" xsi:type="query:AttributeQueryDescriptorType" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"/>
5354
# <md:XACMLAuthzDecisionQueryDescriptor WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"/>
5455

55-
meta_doc << REXML::XMLDecl.new
56+
meta_doc << REXML::XMLDecl.new("1.0", "UTF-8")
5657
ret = ""
5758
# pretty print the XML so IdP administrators can easily see what the SP supports
5859
meta_doc.write(ret, 1)
5960

60-
Logging.debug "Generated metadata:\n#{ret}"
61-
62-
ret
61+
return ret
6362
end
6463
end
6564
end

test/metadata_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
2+
3+
class MetadataTest < Test::Unit::TestCase
4+
5+
should "should generate Service Provider Metadata" do
6+
settings = OneLogin::RubySaml::Settings.new
7+
settings.issuer = "https://example.com"
8+
settings.name_identifier_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
9+
settings.assertion_consumer_service_url = "https://foo.example/saml/consume"
10+
11+
xml_text = OneLogin::RubySaml::Metadata.new.generate(settings)
12+
13+
# assert correct xml declaration
14+
start = "<?xml version='1.0' encoding='UTF-8'?>\n<md:EntityDescriptor"
15+
assert xml_text[0..start.length-1] == start
16+
17+
# assert xml_text can be parsed into an xml doc
18+
xml_doc = REXML::Document.new(xml_text)
19+
20+
assert_equal "https://example.com", REXML::XPath.first(xml_doc, "//md:EntityDescriptor").attribute("entityID").value
21+
22+
spsso_descriptor = REXML::XPath.first(xml_doc, "//md:SPSSODescriptor")
23+
assert_equal "urn:oasis:names:tc:SAML:2.0:protocol", spsso_descriptor.attribute("protocolSupportEnumeration").value
24+
assert_equal "false", spsso_descriptor.attribute("AuthnRequestsSigned").value
25+
assert_equal "false", spsso_descriptor.attribute("WantAssertionsSigned").value
26+
27+
assert_equal "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", REXML::XPath.first(xml_doc, "//md:NameIDFormat").text.strip
28+
29+
acs = REXML::XPath.first(xml_doc, "//md:AssertionConsumerService")
30+
assert_equal "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST", acs.attribute("Binding").value
31+
assert_equal "https://foo.example/saml/consume", acs.attribute("Location").value
32+
end
33+
34+
end

0 commit comments

Comments
 (0)