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

Validate attributes length

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