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