Commit 838b4726 authored by Marius Bobin's avatar Marius Bobin

Validate attributes length

parent d55be96c
...@@ -539,13 +539,13 @@ class ApplicationSetting < ApplicationRecord ...@@ -539,13 +539,13 @@ class ApplicationSetting < ApplicationRecord
validates :sentry_enabled, validates :sentry_enabled,
inclusion: { in: [true, false], message: _('must be a boolean value') } inclusion: { in: [true, false], message: _('must be a boolean value') }
validates :sentry_dsn, validates :sentry_dsn,
addressable_url: true, presence: true, addressable_url: true, presence: true, length: { maximum: 255 },
if: :sentry_enabled? if: :sentry_enabled?
validates :sentry_clientside_dsn, validates :sentry_clientside_dsn,
addressable_url: true, allow_blank: true, addressable_url: true, allow_blank: true, length: { maximum: 255 },
if: :sentry_enabled? if: :sentry_enabled?
validates :sentry_environment, validates :sentry_environment,
presence: true, presence: true, length: { maximum: 255 },
if: :sentry_enabled? if: :sentry_enabled?
attr_encrypted :asset_proxy_secret_key, attr_encrypted :asset_proxy_secret_key,
......
...@@ -180,18 +180,39 @@ RSpec.describe ApplicationSetting do ...@@ -180,18 +180,39 @@ RSpec.describe ApplicationSetting do
end end
context 'Sentry validations' do context 'Sentry validations' do
before do context 'when Sentry is enabled' do
setting.sentry_enabled = true before do
setting.sentry_enabled = true
end
it { is_expected.to allow_value(false).for(:sentry_enabled) }
it { is_expected.not_to allow_value(nil).for(:sentry_enabled) }
it { is_expected.to allow_value('http://example.com').for(:sentry_dsn) }
it { is_expected.not_to allow_value("http://#{'a' * 255}.com").for(:sentry_dsn) }
it { is_expected.not_to allow_value('example').for(:sentry_dsn) }
it { is_expected.not_to allow_value(nil).for(:sentry_dsn) }
it { is_expected.to allow_value('http://example.com').for(:sentry_clientside_dsn) }
it { is_expected.to allow_value(nil).for(:sentry_clientside_dsn) }
it { is_expected.not_to allow_value('example').for(:sentry_clientside_dsn) }
it { is_expected.not_to allow_value("http://#{'a' * 255}.com").for(:sentry_clientside_dsn) }
it { is_expected.to allow_value('production').for(:sentry_environment) }
it { is_expected.not_to allow_value(nil).for(:sentry_environment) }
it { is_expected.not_to allow_value('a' * 256).for(:sentry_environment) }
end end
it { is_expected.to allow_value(false).for(:sentry_enabled) } context 'when Sentry is disabled' do
it { is_expected.not_to allow_value(nil).for(:sentry_enabled) } before do
it { is_expected.to allow_value('http://example.com').for(:sentry_dsn) } setting.sentry_enabled = false
it { is_expected.not_to allow_value('example').for(:sentry_dsn) } end
it { is_expected.to allow_value('http://example.com').for(:sentry_clientside_dsn) }
it { is_expected.not_to allow_value('example').for(:sentry_clientside_dsn) } it { is_expected.not_to allow_value(nil).for(:sentry_enabled) }
it { is_expected.to allow_value('production').for(:sentry_environment) } it { is_expected.to allow_value(nil).for(:sentry_dsn) }
it { is_expected.not_to allow_value(nil).for(:sentry_environment) } it { is_expected.to allow_value(nil).for(:sentry_clientside_dsn) }
it { is_expected.to allow_value(nil).for(:sentry_environment) }
end
end 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