Commit 5dba72c
Changed files (4)
spec
lib/saml/kit/identity_provider_metadata.rb
@@ -13,17 +13,11 @@ module Saml
end
def single_sign_on_services
- xpath = "/md:EntityDescriptor/md:#{name}/md:SingleSignOnService"
- find_all(xpath).map do |item|
- binding = item.attribute("Binding").value
- location = item.attribute("Location").value
- binding_for(binding, location)
- end
+ services('SingleSignOnService')
end
def single_sign_on_service_for(binding:)
- binding = Saml::Kit::Namespaces.binding_for(binding)
- single_sign_on_services.find { |x| x.binding?(binding) }
+ service_for(binding: binding, type: 'SingleSignOnService')
end
def attributes
lib/saml/kit/metadata.rb
@@ -53,17 +53,25 @@ module Saml
certificates.find_all { |x| x[:use] == :signing }
end
- def single_logout_services
- find_all("/md:EntityDescriptor/md:#{name}/md:SingleLogoutService").map do |item|
+ def services(type)
+ find_all("/md:EntityDescriptor/md:#{name}/md:#{type}").map do |item|
binding = item.attribute("Binding").value
location = item.attribute("Location").value
binding_for(binding, location)
end
end
- def single_logout_service_for(binding:)
+ def service_for(binding:, type:)
binding = Saml::Kit::Namespaces.binding_for(binding)
- single_logout_services.find { |x| x.binding?(binding) }
+ services(type).find { |x| x.binding?(binding) }
+ end
+
+ def single_logout_services
+ services('SingleLogoutService')
+ end
+
+ def single_logout_service_for(binding:)
+ service_for(binding: binding, type: 'SingleLogoutService')
end
def matches?(fingerprint, use: :signing)
lib/saml/kit/service_provider_metadata.rb
@@ -6,12 +6,11 @@ module Saml
end
def assertion_consumer_services
- find_all("/md:EntityDescriptor/md:#{name}/md:AssertionConsumerService").map do |item|
- {
- binding: item.attribute("Binding").value,
- location: item.attribute("Location").value,
- }
- end
+ services('AssertionConsumerService')
+ end
+
+ def assertion_consumer_services_for(binding:)
+ service_for(binding: binding, type: 'AssertionConsumerService')
end
def want_assertions_signed
spec/saml/service_provider_metadata_spec.rb
@@ -78,7 +78,7 @@ RSpec.describe Saml::Kit::ServiceProviderMetadata do
end
it 'returns each acs url and binding' do
- expect(subject.assertion_consumer_services).to match_array([
+ expect(subject.assertion_consumer_services.map(&:to_h)).to match_array([
{ location: acs_post_url, binding: Saml::Kit::Namespaces::POST },
{ location: acs_redirect_url, binding: Saml::Kit::Namespaces::HTTP_REDIRECT },
])