mirror of
https://github.com/discourse/discourse.git
synced 2025-03-28 09:25:44 +08:00
FIX: verify presence of 'sso url' before enabling 'enable sso'
This commit is contained in:
parent
a7a0cba45b
commit
0514ac4ee2
@ -1615,6 +1615,7 @@ en:
|
||||
enable_sso_disabled: "You must first enable 'enable sso' before enabling this setting."
|
||||
staged_users_disabled: "You must first enable 'staged users' before enabling this setting."
|
||||
reply_by_email_disabled: "You must first enable 'reply by email' before enabling this setting."
|
||||
sso_url_is_empty: "You must set a 'sso url' before enabling this setting."
|
||||
|
||||
search:
|
||||
within_post: "#%{post_number} by %{username}"
|
||||
|
@ -291,6 +291,7 @@ login:
|
||||
enable_sso:
|
||||
client: true
|
||||
default: false
|
||||
validator: "EnableSsoValidator"
|
||||
sso_allows_all_return_paths: false
|
||||
enable_sso_provider: false
|
||||
verbose_sso_logging: false
|
||||
|
14
lib/validators/enable_sso_validator.rb
Normal file
14
lib/validators/enable_sso_validator.rb
Normal file
@ -0,0 +1,14 @@
|
||||
class EnableSsoValidator
|
||||
def initialize(opts = {})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(val)
|
||||
return true if val == 'f'
|
||||
SiteSetting.sso_url.present?
|
||||
end
|
||||
|
||||
def error_message
|
||||
I18n.t('site_settings.errors.sso_url_is_empty')
|
||||
end
|
||||
end
|
48
spec/components/validators/enable_sso_validator_spec.rb
Normal file
48
spec/components/validators/enable_sso_validator_spec.rb
Normal file
@ -0,0 +1,48 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EnableSsoValidator do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#valid_value?' do
|
||||
describe "when 'sso url' is empty" do
|
||||
before do
|
||||
SiteSetting.sso_url = ""
|
||||
end
|
||||
|
||||
describe 'when val is false' do
|
||||
it 'should be valid' do
|
||||
expect(subject.valid_value?('f')).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when value is true' do
|
||||
it 'should not be valid' do
|
||||
expect(subject.valid_value?('t')).to eq(false)
|
||||
|
||||
expect(subject.error_message).to eq(I18n.t(
|
||||
'site_settings.errors.sso_url_is_empty'
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when 'sso url' is present" do
|
||||
before do
|
||||
SiteSetting.sso_url = "https://www.example.com/sso"
|
||||
end
|
||||
|
||||
describe 'when value is false' do
|
||||
it 'should be valid' do
|
||||
expect(subject.valid_value?('f')).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when value is true' do
|
||||
it 'should be valid' do
|
||||
expect(subject.valid_value?('t')).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user