diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-15 00:08:48 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-15 00:08:48 +0000 |
commit | b69f406585ff64b1c5140ebba775cc754fabb358 (patch) | |
tree | 9af7dfeb0c3f0f8db189a6e18c6be398a7729e2d /spec/initializers | |
parent | 866ca4e49ff74ffadf8e6f6ff663a168489c2aba (diff) | |
download | gitlab-ce-b69f406585ff64b1c5140ebba775cc754fabb358.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/initializers')
-rw-r--r-- | spec/initializers/lograge_spec.rb | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/spec/initializers/lograge_spec.rb b/spec/initializers/lograge_spec.rb index 7c61d034ac9..15165c6db98 100644 --- a/spec/initializers/lograge_spec.rb +++ b/spec/initializers/lograge_spec.rb @@ -5,16 +5,37 @@ require 'spec_helper' describe 'lograge', type: :request do let(:headers) { { 'X-Request-ID' => 'new-correlation-id' } } - context 'for API requests' do - subject { get("/api/v4/endpoint", params: {}, headers: headers) } + let(:large_params) do + half_limit = Gitlab::Utils::LogLimitedArray::MAXIMUM_ARRAY_LENGTH / 2 + + { + a: 'a', + b: 'b' * half_limit, + c: 'c' * half_limit, + d: 'd' + } + end + + let(:limited_params) do + large_params.slice(:a, :b).map { |k, v| { key: k.to_s, value: v } } + ['...'] + end + context 'for API requests' do it 'logs to api_json log' do # we assert receiving parameters by grape logger expect_any_instance_of(Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp).to receive(:call) .with(anything, anything, anything, a_hash_including("correlation_id" => "new-correlation-id")) .and_call_original - subject + get("/api/v4/endpoint", params: {}, headers: headers) + end + + it 'limits param size' do + expect(Lograge.formatter).to receive(:call) + .with(a_hash_including(params: limited_params)) + .and_call_original + + get("/api/v4/endpoint", params: large_params, headers: headers) end end @@ -67,6 +88,14 @@ describe 'lograge', type: :request do subject end + + it 'limits param size' do + expect(Lograge.formatter).to receive(:call) + .with(a_hash_including(params: limited_params)) + .and_call_original + + get("/", params: large_params, headers: headers) + end end context 'with a log subscriber' do |