mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: verify presence of 'sso url' before enabling 'enable sso'
This commit is contained in:
@@ -1615,6 +1615,7 @@ en:
|
|||||||
enable_sso_disabled: "You must first enable 'enable sso' before enabling this setting."
|
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."
|
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."
|
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:
|
search:
|
||||||
within_post: "#%{post_number} by %{username}"
|
within_post: "#%{post_number} by %{username}"
|
||||||
|
@@ -291,6 +291,7 @@ login:
|
|||||||
enable_sso:
|
enable_sso:
|
||||||
client: true
|
client: true
|
||||||
default: false
|
default: false
|
||||||
|
validator: "EnableSsoValidator"
|
||||||
sso_allows_all_return_paths: false
|
sso_allows_all_return_paths: false
|
||||||
enable_sso_provider: false
|
enable_sso_provider: false
|
||||||
verbose_sso_logging: 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
|
Reference in New Issue
Block a user