2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-23 03:00:49 -05:00
|
|
|
RSpec.describe EnableSsoValidator do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:validator) { described_class.new }
|
2017-12-23 03:00:49 -05:00
|
|
|
|
|
|
|
describe "#valid_value?" do
|
|
|
|
describe "when 'sso url' is empty" do
|
2021-02-08 05:04:33 -05:00
|
|
|
before { SiteSetting.discourse_connect_url = "" }
|
2017-12-23 03:00:49 -05:00
|
|
|
|
|
|
|
describe "when val is false" do
|
|
|
|
it "should be valid" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(validator.valid_value?("f")).to eq(true)
|
2017-12-23 03:00:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when value is true" do
|
|
|
|
it "should not be valid" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(validator.valid_value?("t")).to eq(false)
|
2017-12-23 03:00:49 -05:00
|
|
|
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(validator.error_message).to eq(
|
2021-02-08 05:04:33 -05:00
|
|
|
I18n.t("site_settings.errors.discourse_connect_url_is_empty"),
|
2017-12-23 03:00:49 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when 'sso url' is present" do
|
2021-02-08 05:04:33 -05:00
|
|
|
before { SiteSetting.discourse_connect_url = "https://www.example.com/sso" }
|
2017-12-23 03:00:49 -05:00
|
|
|
|
|
|
|
describe "when value is false" do
|
|
|
|
it "should be valid" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(validator.valid_value?("f")).to eq(true)
|
2017-12-23 03:00:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when value is true" do
|
|
|
|
it "should be valid" do
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(validator.valid_value?("t")).to eq(true)
|
2017-12-23 03:00:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-25 13:49:36 -04:00
|
|
|
describe "when 2FA is enforced" do
|
|
|
|
before { SiteSetting.discourse_connect_url = "https://www.example.com/sso" }
|
|
|
|
|
|
|
|
it "should be invalid" do
|
|
|
|
SiteSetting.enforce_second_factor = "all"
|
|
|
|
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(validator.valid_value?("t")).to eq(false)
|
2022-04-25 13:49:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be valid" do
|
|
|
|
SiteSetting.enforce_second_factor = "no"
|
|
|
|
|
2023-06-21 10:00:19 -04:00
|
|
|
expect(validator.valid_value?("t")).to eq(true)
|
2022-04-25 13:49:36 -04:00
|
|
|
end
|
|
|
|
end
|
2017-12-23 03:00:49 -05:00
|
|
|
end
|
|
|
|
end
|