summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-09-12 21:23:49 +0000
committerRobert Speicher <robert@gitlab.com>2018-09-12 21:23:49 +0000
commitf45985a27727c98c8c5c4a879fe4fea974a06cc1 (patch)
treeda94b1b536fcdb228eafb8808af59453a225f52d
parentd2cc536d6aa79f697ff70d74fc13bbeb36fd43dc (diff)
parent8d0767c5cab3a30f4b25ac0dbc22dacfb70a7aed (diff)
downloadgitlab-ce-f45985a27727c98c8c5c4a879fe4fea974a06cc1.tar.gz
Merge branch 'sh-strip-sentry-dsn' into 'master'
Strip whitespace from Sentry URL Closes #49621 See merge request gitlab-org/gitlab-ce!21703
-rw-r--r--app/models/application_setting.rb6
-rw-r--r--spec/models/application_setting_spec.rb30
2 files changed, 36 insertions, 0 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index d8536c5512d..645adddb000 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -219,6 +219,7 @@ class ApplicationSetting < ActiveRecord::Base
validate :terms_exist, if: :enforce_terms?
before_validation :ensure_uuid!
+ before_validation :strip_sentry_values
before_save :ensure_runners_registration_token
before_save :ensure_health_check_access_token
@@ -382,6 +383,11 @@ class ApplicationSetting < ActiveRecord::Base
super(levels.map { |level| Gitlab::VisibilityLevel.level_value(level) })
end
+ def strip_sentry_values
+ sentry_dsn.strip! if sentry_dsn.present?
+ clientside_sentry_dsn.strip! if clientside_sentry_dsn.present?
+ end
+
def performance_bar_allowed_group
Group.find_by_id(performance_bar_allowed_group_id)
end
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index 483cc546423..9647c1b9f63 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -305,6 +305,36 @@ describe ApplicationSetting do
end
end
+ describe 'setting Sentry DSNs' do
+ context 'server DSN' do
+ it 'strips leading and trailing whitespace' do
+ subject.update(sentry_dsn: ' http://test ')
+
+ expect(subject.sentry_dsn).to eq('http://test')
+ end
+
+ it 'handles nil values' do
+ subject.update(sentry_dsn: nil)
+
+ expect(subject.sentry_dsn).to be_nil
+ end
+ end
+
+ context 'client-side DSN' do
+ it 'strips leading and trailing whitespace' do
+ subject.update(clientside_sentry_dsn: ' http://test ')
+
+ expect(subject.clientside_sentry_dsn).to eq('http://test')
+ end
+
+ it 'handles nil values' do
+ subject.update(clientside_sentry_dsn: nil)
+
+ expect(subject.clientside_sentry_dsn).to be_nil
+ end
+ end
+ end
+
describe '#disabled_oauth_sign_in_sources=' do
before do
allow(Devise).to receive(:omniauth_providers).and_return([:github])