Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse SLO endpoint as array from SP metadata #184

Open
wants to merge 6 commits into
base: v1.0.0-saml_lib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/saml_idp/incoming_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ def single_logout_services
xpath(
"//md:SPSSODescriptor/md:SingleLogoutService",
md: metadata_namespace
).reduce({}) do |hash, el|
hash[el["Binding"].to_s.split(":").last] = el["Location"]
hash
).reduce([]) do |array, el|
props = el["Binding"].to_s.match /urn:oasis:names:tc:SAML:(?<version>\S+):bindings:(?<name>\S+)/
array << { binding: props[:name], location: el["Location"], default: !!el["isDefault"], response_location: el["ResponseLocation"] }
end
end
hashable :single_logout_services
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/saml_idp/incoming_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ module SamlIdp
</md:EntityDescriptor>
eos

metadata_with_slo = <<-eos
<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
validUntil="2022-07-18T04:35:53Z"
cacheDuration="PT604800S"
entityID="http://sp.example.com/saml">
<md:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location="https://test/logout" />
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="http://sp.example.com/saml/acs"
index="1" />

</md:SPSSODescriptor>
</md:EntityDescriptor>
eos

metadata_5 = <<-eos
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="test" entityID="https://test-saml.com/saml">
<md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
Expand Down Expand Up @@ -99,6 +117,17 @@ module SamlIdp
expect(metadata.sign_authn_request).to eq(false)
end

it 'should parse single logout url as array' do
metadata = SamlIdp::IncomingMetadata.new(metadata_with_slo)
expect(metadata.single_logout_services).to be_a(Array)
expect(metadata.single_logout_services.size).to eq(1)
expect(metadata.single_logout_services).to include(
hash_including(binding: "HTTP-Redirect"),
hash_including(location: "https://test/logout"),
hash_including(default: false)
)
end

it 'should properly set unspecified_certificate when present' do
metadata = SamlIdp::IncomingMetadata.new(metadata_5)
expect(metadata.unspecified_certificate).to eq('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnht3GR...')
Expand Down