Commit 3058900

mo <mo@mokhan.ca>
2017-11-06 03:31:53
add spec for when service provider is not known.
1 parent c79026e
Changed files (2)
lib/saml/kit/authentication_request.rb
@@ -55,6 +55,7 @@ module Saml
       private
 
       def registered_acs_url
+        return if provider.nil?
         acs_urls = provider.assertion_consumer_services
         return acs_urls.first[:location] if acs_urls.any?
       end
@@ -69,6 +70,7 @@ module Saml
 
       def must_be_registered
         return unless login_request?
+        return if provider.nil?
         return if provider.matches?(fingerprint, use: "signing")
 
         errors[:base] << error_message(:invalid)
spec/saml/authentication_request_spec.rb
@@ -85,6 +85,12 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
       expect(described_class.new(xml)).to be_invalid
     end
 
+    it 'is invalid when the service provider is not known' do
+      allow(registry).to receive(:metadata_for).and_return(nil)
+      builder = described_class::Builder.new
+      expect(described_class.new(builder.to_xml)).to be_invalid
+    end
+
     it 'is invalid when an assertion consumer service url is not provided' do
       allow(service_provider_metadata).to receive(:matches?).and_return(true)
       allow(service_provider_metadata).to receive(:assertion_consumer_services).and_return([])