Commit 348e261

mo <mo.khan@gmail.com>
2017-11-18 23:10:03
return instance of binding from logout services.
1 parent 1e37c81
saml-kit/lib/saml/kit/identity_provider_metadata.rb
@@ -23,9 +23,7 @@ module Saml
 
       def single_sign_on_service_for(binding:)
         binding = Saml::Kit::Namespaces.binding_for(binding)
-        single_sign_on_services.find do |item|
-          item.binding?(binding)
-        end
+        single_sign_on_services.find { |x| x.binding?(binding) }
       end
 
       def attributes
@@ -39,17 +37,6 @@ module Saml
 
       private
 
-      def binding_for(binding, location)
-        case binding
-        when Namespaces::HTTP_REDIRECT
-          Saml::Kit::HttpRedirectBinding.new(location: location)
-        when Namespaces::POST
-          Saml::Kit::HttpPostBinding.new(location: location)
-        else
-          Saml::Kit::Binding.new(binding: binding, location: location)
-        end
-      end
-
       class Builder
         attr_accessor :id, :organization_name, :organization_url, :contact_email, :entity_id, :attributes, :name_id_formats
         attr_accessor :want_authn_requests_signed, :sign
saml-kit/lib/saml/kit/metadata.rb
@@ -55,19 +55,15 @@ module Saml
 
       def single_logout_services
         find_all("/md:EntityDescriptor/md:#{name}/md:SingleLogoutService").map do |item|
-          {
-            binding: item.attribute("Binding").value,
-            location: item.attribute("Location").value,
-          }
+          binding = item.attribute("Binding").value
+          location = item.attribute("Location").value
+          binding_for(binding, location)
         end
       end
 
       def single_logout_service_for(binding:)
         binding = Saml::Kit::Namespaces.binding_for(binding)
-        result = single_logout_services.find do |item|
-          item[:binding] == binding
-        end
-        return result[:location] if result
+        single_logout_services.find { |x| x.binding?(binding) }
       end
 
       def matches?(fingerprint, use: :signing)
@@ -151,6 +147,17 @@ module Saml
         end
         result
       end
+
+      def binding_for(binding, location)
+        case binding
+        when Namespaces::HTTP_REDIRECT
+          Saml::Kit::HttpRedirectBinding.new(location: location)
+        when Namespaces::POST
+          Saml::Kit::HttpPostBinding.new(location: location)
+        else
+          Saml::Kit::Binding.new(binding: binding, location: location)
+        end
+      end
     end
   end
 end
saml-kit/spec/saml/identity_provider_metadata_spec.rb
@@ -53,7 +53,7 @@ RSpec.describe Saml::Kit::IdentityProviderMetadata do
     end
     it do
       location = "https://www.example.com/adfs/ls/"
-      expect(subject.single_logout_services).to match_array([
+      expect(subject.single_logout_services.map(&:to_h)).to match_array([
         { location: location, binding: Saml::Kit::Namespaces::HTTP_REDIRECT },
         { location: location, binding: Saml::Kit::Namespaces::HTTP_POST },
       ])
@@ -178,8 +178,8 @@ RSpec.describe Saml::Kit::IdentityProviderMetadata do
     end
 
     it 'returns the location for the matching binding' do
-      expect(subject.single_logout_service_for(binding: :post)).to eql(post_url)
-      expect(subject.single_logout_service_for(binding: :http_redirect)).to eql(redirect_url)
+      expect(subject.single_logout_service_for(binding: :post).location).to eql(post_url)
+      expect(subject.single_logout_service_for(binding: :http_redirect).location).to eql(redirect_url)
     end
 
     it 'returns nil if the binding is not available' do
saml-kit/spec/saml/service_provider_metadata_spec.rb
@@ -85,7 +85,7 @@ RSpec.describe Saml::Kit::ServiceProviderMetadata do
     end
 
     it 'returns each logout url and binding' do
-      expect(subject.single_logout_services).to match_array([
+      expect(subject.single_logout_services.map(&:to_h)).to match_array([
         { location: logout_post_url, binding: Saml::Kit::Namespaces::POST },
         { location: logout_redirect_url, binding: Saml::Kit::Namespaces::HTTP_REDIRECT },
       ])