Commit 4ebfdd6

mo <mo@mokhan.ca>
2017-11-16 18:56:25
exclude the RelayState when absent.
1 parent 0f26c47
Changed files (2)
lib
saml
spec
lib/saml/kit/binding.rb
@@ -24,8 +24,8 @@ module Saml
           document = builder.build
           saml_params = {
             document.query_string_parameter => Base64.strict_encode64(document.to_xml),
-            'RelayState' => relay_state,
           }
+          saml_params['RelayState'] = relay_state if relay_state.present?
           [location, saml_params]
         else
           []
spec/saml/binding_spec.rb
@@ -62,6 +62,14 @@ RSpec.describe Saml::Kit::Binding do
         expect(xml['LogoutResponse']['Destination']).to eql(location)
         expect(xml['LogoutResponse']['Signature']).to be_present
       end
+
+      it 'excludes the RelayState when blank' do
+        builder = Saml::Kit::AuthenticationRequest::Builder.new
+        url, saml_params = subject.serialize(builder)
+
+        expect(url).to eql(location)
+        expect(saml_params.keys).to_not include('RelayState')
+      end
     end
 
     it 'ignores other bindings' do