Commit fc4c0f2

mo <mo@mokhan.ca>
2017-11-16 00:36:47
disable compression by default.
1 parent 6a12d13
lib/saml/kit/authentication_request.rb
@@ -74,8 +74,8 @@ module Saml
         to_xml
       end
 
-      def serialize
-        Saml::Kit::Content.serialize(to_xml)
+      def serialize(compress: false)
+        Saml::Kit::Content.serialize(to_xml, compress: compress)
       end
 
       def response_for(user)
lib/saml/kit/content.rb
@@ -1,8 +1,8 @@
 module Saml
   module Kit
     class Content
-      def self.serialize(xml)
-        encode(deflate(xml))
+      def self.serialize(xml, compress: false)
+        compress ? encode(deflate(xml)) : encode(xml)
       end
 
       def self.deserialize(xml)
lib/saml/kit/logout_response.rb
@@ -45,8 +45,8 @@ module Saml
         @xml_hash
       end
 
-      def serialize
-        Saml::Kit::Content.serialize(to_xml)
+      def serialize(compress: false)
+        Saml::Kit::Content.serialize(to_xml, compress: compress)
       end
 
       def to_xml
lib/saml/kit/response.rb
@@ -76,8 +76,8 @@ module Saml
         @xml_hash
       end
 
-      def serialize
-        Saml::Kit::Content.serialize(to_xml)
+      def serialize(compress: false)
+        Saml::Kit::Content.serialize(to_xml, compress: compress)
       end
 
       def certificate
lib/saml/kit/url_builder.rb
@@ -20,7 +20,7 @@ module Saml
 
       def build_payload(saml_document, relay_state)
         {
-          saml_document.query_string_parameter => Content.serialize(saml_document.to_xml),
+          saml_document.query_string_parameter => Content.serialize(saml_document.to_xml, compress: true),
           'RelayState' => relay_state,
           'SigAlg' => Saml::Kit::Namespaces::SHA256,
         }.map do |(key, value)|
spec/saml/authentication_request_spec.rb
@@ -182,6 +182,11 @@ RSpec.describe Saml::Kit::AuthenticationRequest do
 
     it 'returns a compressed and base64 encoded document' do
       expected_value = Base64.strict_encode64(Zlib::Deflate.deflate(subject.to_xml, 9)[2..-5])
+      expect(subject.serialize(compress: true)).to eql(expected_value)
+    end
+
+    it 'returns a base64 encoded document' do
+      expected_value = Base64.strict_encode64(subject.to_xml)
       expect(subject.serialize).to eql(expected_value)
     end
   end
spec/saml/logout_response_spec.rb
@@ -34,6 +34,11 @@ RSpec.describe Saml::Kit::LogoutResponse do
 
     it 'returns a compressed and base64 encoded document' do
       expected_value = Base64.strict_encode64(Zlib::Deflate.deflate(subject.to_xml, 9)[2..-5])
+      expect(subject.serialize(compress: true)).to eql(expected_value)
+    end
+
+    it 'returns a base64 encoded document' do
+      expected_value = Base64.strict_encode64(subject.to_xml)
       expect(subject.serialize).to eql(expected_value)
     end
   end
spec/saml/response_spec.rb
@@ -245,6 +245,15 @@ RSpec.describe Saml::Kit::Response do
       subject = described_class.new(xml)
 
       expected_value = Base64.strict_encode64(Zlib::Deflate.deflate(xml, 9)[2..-5])
+      expect(subject.serialize(compress: true)).to eql(expected_value)
+    end
+
+    it 'returns a base64 encoded document' do
+      builder = described_class::Builder.new(user, request)
+      xml = builder.to_xml
+      subject = described_class.new(xml)
+
+      expected_value = Base64.strict_encode64(xml)
       expect(subject.serialize).to eql(expected_value)
     end
   end