discourse/spec/services/site_settings_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
describe SiteSettingsTask do
before do
Discourse::Application.load_tasks
end
describe 'export' do
it 'creates a hash of all site settings' do
sso_url = "https://somewhere.over.com"
FEATURE: Rename 'Discourse SSO' to DiscourseConnect (#11978) The 'Discourse SSO' protocol is being rebranded to DiscourseConnect. This should help to reduce confusion when 'SSO' is used in the generic sense. This commit aims to: - Rename `sso_` site settings. DiscourseConnect specific ones are prefixed `discourse_connect_`. Generic settings are prefixed `auth_` - Add (server-side-only) backwards compatibility for the old setting names, with deprecation notices - Copy `site_settings` database records to the new names - Rename relevant translation keys - Update relevant translations This commit does **not** aim to: - Rename any Ruby classes or methods. This might be done in a future commit - Change any URLs. This would break existing integrations - Make any changes to the protocol. This would break existing integrations - Change any functionality. Further normalization across DiscourseConnect and other auth methods will be done separately The risks are: - There is no backwards compatibility for site settings on the client-side. Accessing auth-related site settings in Javascript is fairly rare, and an error on the client side would not be security-critical. - If a plugin is monkey-patching parts of the auth process, changes to locale keys could cause broken error messages. This should also be unlikely. The old site setting names remain functional, so security-related overrides will remain working. A follow-up commit will be made with a post-deploy migration to delete the old `site_settings` rows.
2021-02-08 18:04:33 +08:00
SiteSetting.discourse_connect_url = sso_url
SiteSetting.enable_discourse_connect = true
hash = SiteSettingsTask.export_to_hash
expect(hash).to eq(
FEATURE: Rename 'Discourse SSO' to DiscourseConnect (#11978) The 'Discourse SSO' protocol is being rebranded to DiscourseConnect. This should help to reduce confusion when 'SSO' is used in the generic sense. This commit aims to: - Rename `sso_` site settings. DiscourseConnect specific ones are prefixed `discourse_connect_`. Generic settings are prefixed `auth_` - Add (server-side-only) backwards compatibility for the old setting names, with deprecation notices - Copy `site_settings` database records to the new names - Rename relevant translation keys - Update relevant translations This commit does **not** aim to: - Rename any Ruby classes or methods. This might be done in a future commit - Change any URLs. This would break existing integrations - Make any changes to the protocol. This would break existing integrations - Change any functionality. Further normalization across DiscourseConnect and other auth methods will be done separately The risks are: - There is no backwards compatibility for site settings on the client-side. Accessing auth-related site settings in Javascript is fairly rare, and an error on the client side would not be security-critical. - If a plugin is monkey-patching parts of the auth process, changes to locale keys could cause broken error messages. This should also be unlikely. The old site setting names remain functional, so security-related overrides will remain working. A follow-up commit will be made with a post-deploy migration to delete the old `site_settings` rows.
2021-02-08 18:04:33 +08:00
"enable_discourse_connect" => "true",
"discourse_connect_url" => sso_url
)
end
end
describe 'import' do
it 'updates site settings' do
yml = "title: Test"
log, counts = SiteSettingsTask.import(yml)
expect(log[0]).to eq "Changed title FROM: Discourse TO: Test"
expect(counts[:updated]).to eq 1
expect(SiteSetting.title).to eq "Test"
end
it "updates hidden settings" do
original_default_theme_id = SiteSetting.default_theme_id.inspect
2020-06-22 14:50:17 +08:00
yml = "default_theme_id: 999999999"
log, counts = SiteSettingsTask.import(yml)
expect(log[0]).to eq "Changed default_theme_id FROM: #{original_default_theme_id} TO: 999999999"
2020-06-22 14:50:17 +08:00
expect(counts[:updated]).to eq(1)
expect(SiteSetting.default_theme_id).to eq(999999999)
end
it "won't update a setting that doesn't exist" do
yml = "fake_setting: foo"
log, counts = SiteSettingsTask.import(yml)
expect(log[0]).to eq "NOT FOUND: existing site setting not found for fake_setting"
expect(counts[:not_found]).to eq 1
end
it "will log that an error has occurred" do
yml = "min_password_length: 0"
log, counts = SiteSettingsTask.import(yml)
expect(log[0]).to eq "ERROR: min_password_length: Value must be between 8 and 500."
expect(counts[:errors]).to eq 1
expect(SiteSetting.min_password_length).to eq 10
end
end
end