2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-23 03:00:49 -05:00
|
|
|
RSpec.describe EnableSsoValidator do
|
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
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
|
|
|
|
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(
|
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
|
|
|
|
|
2019-04-02 10:26:27 -04:00
|
|
|
describe "when invite_only is set" do
|
|
|
|
before do
|
|
|
|
SiteSetting.invite_only = true
|
2021-02-08 05:04:33 -05:00
|
|
|
SiteSetting.discourse_connect_url = "https://example.com/sso"
|
2019-04-02 10:26:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows a false value" do
|
|
|
|
expect(subject.valid_value?("f")).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't allow true" do
|
|
|
|
expect(subject.valid_value?("t")).to eq(false)
|
|
|
|
expect(subject.error_message).to eq(
|
2021-02-08 05:04:33 -05:00
|
|
|
I18n.t("site_settings.errors.discourse_connect_invite_only"),
|
2019-04-02 10:26:27 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-23 03:00:49 -05:00
|
|
|
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
|
|
|
|
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
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
expect(subject.valid_value?("t")).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be valid" do
|
|
|
|
SiteSetting.enforce_second_factor = "no"
|
|
|
|
|
|
|
|
expect(subject.valid_value?("t")).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2017-12-23 03:00:49 -05:00
|
|
|
end
|
|
|
|
end
|