Commit 00ca0d9

mo <mo@mokhan.ca>
2017-12-08 19:11:09
add spec for composite metadata.
1 parent da60950
Changed files (3)
lib/saml/kit/bindings/binding.rb
@@ -25,6 +25,22 @@ module Saml
           { binding: binding, location: location }
         end
 
+        def ==(other)
+          self.to_s == other.to_s
+        end
+
+        def eql?(other)
+          self == other
+        end
+
+        def hash
+          to_s.hash
+        end
+
+        def to_s
+          "#{location}#{binding}"
+        end
+
         protected
 
         def saml_param_from(params)
spec/saml/composite_metadata_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+RSpec.describe Saml::Kit::CompositeMetadata do
+  subject { described_class.new(xml) }
+  let(:post_binding) { Saml::Kit::Bindings::HTTP_POST  }
+  let(:redirect_binding) { Saml::Kit::Bindings::HTTP_REDIRECT }
+  let(:sign_on_service) { FFaker::Internet.uri("https") }
+  let(:xml) do
+    <<-XML
+<EntityDescriptor xmlns="#{Saml::Kit::Namespaces::METADATA}" ID="#{Saml::Kit::Id.generate}" entityID="#{FFaker::Internet.uri("https")}">
+  <SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true" protocolSupportEnumeration="#{Saml::Kit::Namespaces::PROTOCOL}">
+    <SingleLogoutService Binding="#{post_binding}" Location="#{FFaker::Internet.uri("https")}"/>
+    <NameIDFormat>#{Saml::Kit::Namespaces::PERSISTENT}</NameIDFormat>
+    <AssertionConsumerService Binding="#{post_binding}" Location="#{FFaker::Internet.uri("https")}" index="0" isDefault="true"/>
+  </SPSSODescriptor>
+  <IDPSSODescriptor WantAuthnRequestsSigned="true" protocolSupportEnumeration="#{Saml::Kit::Namespaces::PROTOCOL}">
+    <SingleLogoutService Binding="#{post_binding}" Location="#{FFaker::Internet.uri("https")}"/>
+    <NameIDFormat>#{Saml::Kit::Namespaces::PERSISTENT}</NameIDFormat>
+    <SingleSignOnService Binding="#{post_binding}" Location="#{sign_on_service}"/>
+    <SingleSignOnService Binding="#{redirect_binding}" Location="#{sign_on_service}"/>
+  </IDPSSODescriptor>
+  <Organization>
+    <OrganizationName xml:lang="en">Acme, Inc</OrganizationName>
+    <OrganizationDisplayName xml:lang="en">Acme, Inc</OrganizationDisplayName>
+    <OrganizationURL xml:lang="en">http://localhost:5000/</OrganizationURL>
+  </Organization>
+  <ContactPerson contactType="technical">
+    <Company>mailto:hi@example.com</Company>
+  </ContactPerson>
+</EntityDescriptor>
+    XML
+  end
+
+  describe "#single_sign_on_services" do
+    it 'returns the single sign on services from the idp' do
+      expect(subject.single_sign_on_services).to match_array([
+        Saml::Kit::Bindings::HttpPost.new(location: sign_on_service),
+        Saml::Kit::Bindings::HttpRedirect.new(location: sign_on_service),
+      ])
+    end
+  end
+end
spec/saml/http_post_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+RSpec.describe Saml::Kit::Bindings::HttpPost do
+  describe "equality" do
+    let(:location) { FFaker::Internet.uri("https") }
+    subject { Saml::Kit::Bindings::HttpPost.new(location: location) }
+
+    it 'is referentially equal' do
+      expect(subject).to eql(subject)
+    end
+
+    it 'is equal by value' do
+      expect(subject).to eql(
+        Saml::Kit::Bindings::HttpPost.new(location: location)
+      )
+    end
+
+    it 'is not equal' do
+      expect(subject).to_not eql(
+        Saml::Kit::Bindings::HttpPost.new(
+          location: FFaker::Internet.uri("https")
+        )
+      )
+    end
+  end
+end