Commit e99257b

mokha <mokha@cisco.com>
2019-01-11 19:59:24
do not re-encode a base64 encoded value
1 parent be537d2
Changed files (2)
lib
scim
spec
lib/scim/kit/v2.rb
@@ -36,7 +36,9 @@ module Scim
         complex: 'complex'
       }.freeze
       COERCION = {
-        binary: ->(x) { Base64.strict_encode64(x) },
+        binary: lambda { |x|
+          VALIDATIONS[:binary].call(x) ? x : Base64.strict_encode64(x)
+        },
         boolean: lambda { |x|
           return true if x == 'true'
           return false if x == 'false'
spec/scim/kit/v2/attribute_type_spec.rb
@@ -157,6 +157,7 @@ RSpec.describe Scim::Kit::V2::AttributeType do
     let(:uri) { FFaker::Internet.uri('https') }
 
     specify { expect(described_class.new(name: :x, type: :binary).coerce(raw_image)).to eql(image) }
+    specify { expect(described_class.new(name: :x, type: :binary).coerce(image)).to eql(image) }
 
     specify { expect(described_class.new(name: :x, type: :boolean).coerce(true)).to be(true) }
     specify { expect(described_class.new(name: :x, type: :boolean).coerce('true')).to be(true) }