diff options
Diffstat (limited to 'spec/support/shared_examples/lib/sentry/client_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/lib/sentry/client_shared_examples.rb | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/spec/support/shared_examples/lib/sentry/client_shared_examples.rb b/spec/support/shared_examples/lib/sentry/client_shared_examples.rb index d73c7b6848d..1c0e0061385 100644 --- a/spec/support/shared_examples/lib/sentry/client_shared_examples.rb +++ b/spec/support/shared_examples/lib/sentry/client_shared_examples.rb @@ -43,7 +43,7 @@ RSpec.shared_examples 'maps Sentry exceptions' do |http_method| } exceptions.each do |exception, message| - context "#{exception}" do + context exception do before do stub_request( http_method || :get, @@ -58,3 +58,50 @@ RSpec.shared_examples 'maps Sentry exceptions' do |http_method| end end end + +# Expects to following variables: +# - subject +# - sentry_api_response +# - sentry_url, token - only if enabled_by_default: false +RSpec.shared_examples 'Sentry API response size limit' do |enabled_by_default: false| + let(:invalid_deep_size) { instance_double(Gitlab::Utils::DeepSize, valid?: false) } + + before do + allow(Gitlab::Utils::DeepSize) + .to receive(:new) + .with(sentry_api_response, any_args) + .and_return(invalid_deep_size) + end + + if enabled_by_default + it 'raises an exception when response is too large' do + expect { subject }.to raise_error(ErrorTracking::SentryClient::ResponseInvalidSizeError, + 'Sentry API response is too big. Limit is 1 MB.') + end + else + context 'when guarded by feature flag' do + let(:client) do + ErrorTracking::SentryClient.new(sentry_url, token, validate_size_guarded_by_feature_flag: feature_flag) + end + + context 'with feature flag enabled' do + let(:feature_flag) { true } + + it 'raises an exception when response is too large' do + expect { subject }.to raise_error(ErrorTracking::SentryClient::ResponseInvalidSizeError, + 'Sentry API response is too big. Limit is 1 MB.') + end + end + + context 'with feature flag disabled' do + let(:feature_flag) { false } + + it 'does not check the limit and thus not raise' do + expect { subject }.not_to raise_error + + expect(Gitlab::Utils::DeepSize).not_to have_received(:new) + end + end + end + end +end |