Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/concerns/sensitive_serializable_hash_spec.rb')
-rw-r--r--spec/models/concerns/sensitive_serializable_hash_spec.rb26
1 files changed, 24 insertions, 2 deletions
diff --git a/spec/models/concerns/sensitive_serializable_hash_spec.rb b/spec/models/concerns/sensitive_serializable_hash_spec.rb
index c864ecb4eec..3c9199ce18f 100644
--- a/spec/models/concerns/sensitive_serializable_hash_spec.rb
+++ b/spec/models/concerns/sensitive_serializable_hash_spec.rb
@@ -4,11 +4,15 @@ require 'spec_helper'
RSpec.describe SensitiveSerializableHash do
describe '.prevent_from_serialization' do
- let(:test_class) do
+ let(:base_class) do
Class.new do
include ActiveModel::Serialization
include SensitiveSerializableHash
+ end
+ end
+ let(:test_class) do
+ Class.new(base_class) do
attr_accessor :name, :super_secret
prevent_from_serialization :super_secret
@@ -19,6 +23,12 @@ RSpec.describe SensitiveSerializableHash do
end
end
+ let(:another_class) do
+ Class.new(base_class) do
+ prevent_from_serialization :sub_secret
+ end
+ end
+
let(:model) { test_class.new }
it 'does not include the field in serializable_hash' do
@@ -30,6 +40,11 @@ RSpec.describe SensitiveSerializableHash do
expect(model.serializable_hash(unsafe_serialization_hash: true)).to include('super_secret')
end
end
+
+ it 'does not change parent class attributes_exempt_from_serializable_hash' do
+ expect(test_class.attributes_exempt_from_serializable_hash).to contain_exactly(:super_secret)
+ expect(another_class.attributes_exempt_from_serializable_hash).to contain_exactly(:sub_secret)
+ end
end
describe '#serializable_hash' do
@@ -56,6 +71,9 @@ RSpec.describe SensitiveSerializableHash do
attributes.each do |attribute|
expect(model.attributes).to include(attribute) # double-check the attribute does exist
+ # Do not expect binary columns to appear in JSON
+ next if klass.columns_hash[attribute]&.type == :binary
+
expect(model.serializable_hash(unsafe_serialization_hash: true)).to include(attribute)
expect(model.to_json(unsafe_serialization_hash: true)).to include(attribute)
expect(model.as_json(unsafe_serialization_hash: true)).to include(attribute)
@@ -65,8 +83,12 @@ RSpec.describe SensitiveSerializableHash do
end
end
- it_behaves_like 'attr_encrypted attribute', WebHook, 'token' do
+ context 'for a web hook' do
let_it_be(:model) { create(:system_hook) }
+
+ it_behaves_like 'attr_encrypted attribute', WebHook, 'token'
+ it_behaves_like 'attr_encrypted attribute', WebHook, 'url'
+ it_behaves_like 'attr_encrypted attribute', WebHook, 'url_variables'
end
it_behaves_like 'attr_encrypted attribute', Ci::InstanceVariable, 'value' do