diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-11 22:05:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-11 22:05:37 +0300 |
commit | c2f9f40e8892d316a27702eb5dbcabbe756efd0c (patch) | |
tree | 9010111802c50ebcad804e7b2e3f472ca87214ca /spec/initializers/rails_yaml_safe_load_spec.rb | |
parent | 5dc5e2c78f8ee966db96ffe31887a90bce650437 (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-ee
Diffstat (limited to 'spec/initializers/rails_yaml_safe_load_spec.rb')
-rw-r--r-- | spec/initializers/rails_yaml_safe_load_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/initializers/rails_yaml_safe_load_spec.rb b/spec/initializers/rails_yaml_safe_load_spec.rb new file mode 100644 index 00000000000..8cf6a3676e0 --- /dev/null +++ b/spec/initializers/rails_yaml_safe_load_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Rails YAML safe load' do + let(:unsafe_load) { false } + + let(:klass) do + Class.new(ActiveRecord::Base) do + self.table_name = 'issues' + + serialize :description + end + end + + let(:instance) { klass.new(description: data) } + + context 'with default permitted classes' do + let(:data) do + { + 'time' => Time.now, + 'date' => Date.today, + 'number' => 1, + 'hashie-array' => Hashie::Array.new([1, 2]), + 'array' => [5, 6] + } + end + + it 'deserializes data' do + instance.save! + + expect(klass.find(instance.id).description).to eq(data) + end + + context 'with unpermitted classes' do + let(:data) { { 'test' => create(:user) } } + + it 'throws an exception' do + expect { instance.save! }.to raise_error(Psych::DisallowedClass) + end + end + end +end |