Commit 45858e25 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'rp-do-not-symbolize-keys-in-yaml-loader' into 'master'

New method Gitlab::Config::Loader::Yaml#load_raw!

See merge request gitlab-org/gitlab!34263
parents 95c3aee2 09ebe6f4
......@@ -21,11 +21,15 @@ module Gitlab
hash? && !too_big?
end
def load!
def load_raw!
raise DataTooLargeError, 'The parsed YAML is too big' if too_big?
raise Loader::FormatError, 'Invalid configuration format' unless hash?
@config.deep_symbolize_keys
@config
end
def load!
@symbolized_config ||= load_raw!.deep_symbolize_keys
end
private
......
......@@ -5,6 +5,16 @@ require 'spec_helper'
describe Gitlab::Config::Loader::Yaml do
let(:loader) { described_class.new(yml) }
let(:yml) do
<<~YAML
image: 'ruby:2.7'
texts:
nested_key: 'value1'
more_text:
more_nested_key: 'value2'
YAML
end
context 'when yaml syntax is correct' do
let(:yml) { 'image: ruby:2.7' }
......@@ -61,6 +71,15 @@ describe Gitlab::Config::Loader::Yaml do
expect(loader).not_to be_valid
end
end
describe '#load_raw!' do
it 'raises error' do
expect { loader.load_raw! }.to raise_error(
Gitlab::Config::Loader::FormatError,
'Invalid configuration format'
)
end
end
end
# Prevent Billion Laughs attack: https://gitlab.com/gitlab-org/gitlab-foss/issues/56018
......@@ -123,4 +142,32 @@ describe Gitlab::Config::Loader::Yaml do
end
end
end
describe '#load_raw!' do
it 'loads keys as strings' do
expect(loader.load_raw!).to eq(
'image' => 'ruby:2.7',
'texts' => {
'nested_key' => 'value1',
'more_text' => {
'more_nested_key' => 'value2'
}
}
)
end
end
describe '#load!' do
it 'symbolizes keys' do
expect(loader.load!).to eq(
image: 'ruby:2.7',
texts: {
nested_key: 'value1',
more_text: {
more_nested_key: 'value2'
}
}
)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment