Skip to content

Commit

Permalink
Merge pull request #179 from Pathgather/parse-entity-id
Browse files Browse the repository at this point in the history
Add support for setting the entity ID and name ID format when parsing metadata
  • Loading branch information
pitbulk committed Mar 18, 2015
2 parents 267d373 + 006a80e commit 20e4853
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/onelogin/ruby-saml/idp_metadata_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def parse(idp_metadata)
@document = REXML::Document.new(idp_metadata)

OneLogin::RubySaml::Settings.new.tap do |settings|

settings.idp_entity_id = idp_entity_id
settings.name_identifier_format = idp_name_id_format
settings.idp_sso_target_url = single_signon_service_url
settings.idp_slo_target_url = single_logout_service_url
settings.idp_cert_fingerprint = fingerprint
Expand Down Expand Up @@ -65,6 +66,16 @@ def get_idp_metadata(url, validate_cert)
meta_text
end

def idp_entity_id
node = REXML::XPath.first(document, "/md:EntityDescriptor/@entityID", { "md" => METADATA })
node.value if node
end

def idp_name_id_format
node = REXML::XPath.first(document, "/md:EntityDescriptor/md:IDPSSODescriptor/md:NameIDFormat", { "md" => METADATA })
node.text if node
end

def single_signon_service_url
node = REXML::XPath.first(document, "/md:EntityDescriptor/md:IDPSSODescriptor/md:SingleSignOnService/@Location", { "md" => METADATA })
node.value if node
Expand Down
4 changes: 4 additions & 0 deletions test/idp_metadata_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ class MockResponse

settings = idp_metadata_parser.parse(idp_metadata)

assert_equal "https://example.hello.com/access/saml/idp.xml", settings.idp_entity_id
assert_equal "https://example.hello.com/access/saml/login", settings.idp_sso_target_url
assert_equal "F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72", settings.idp_cert_fingerprint
assert_equal "https://example.hello.com/access/saml/logout", settings.idp_slo_target_url
assert_equal "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified", settings.name_identifier_format
end
end

Expand All @@ -35,9 +37,11 @@ class MockResponse
idp_metadata_parser = OneLogin::RubySaml::IdpMetadataParser.new
settings = idp_metadata_parser.parse_remote(@url)

assert_equal "https://example.hello.com/access/saml/idp.xml", settings.idp_entity_id
assert_equal "https://example.hello.com/access/saml/login", settings.idp_sso_target_url
assert_equal "F1:3C:6B:80:90:5A:03:0E:6C:91:3E:5D:15:FA:DD:B0:16:45:48:72", settings.idp_cert_fingerprint
assert_equal "https://example.hello.com/access/saml/logout", settings.idp_slo_target_url
assert_equal "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified", settings.name_identifier_format
assert_equal OpenSSL::SSL::VERIFY_PEER, @http.verify_mode
end

Expand Down

0 comments on commit 20e4853

Please sign in to comment.