A platform for community discussion. Free, open, simple.
FIX: actually disable SMTP starttls if the user is attempting to disable it
Michael Brown2354eb34199b
diff --git a/app/models/problem_check.rb b/app/models/problem_check.rbindex 1b4750c6d4e..9e2f1dc2ba1 100644--- a/app/models/problem_check.rb+++ b/app/models/problem_check.rb@@ -83,6 +83,7 @@ class ProblemCheckProblemCheck::S3UploadConfig,ProblemCheck::SidekiqCheck,ProblemCheck::SubfolderEndsInSlash,+ ProblemCheck::StarttlsDisabled,ProblemCheck::TranslationOverrides,ProblemCheck::TwitterConfig,ProblemCheck::TwitterLogin,diff --git a/app/services/email_settings_validator.rb b/app/services/email_settings_validator.rbindex 9c75d5bde9b..c23c45d82e5 100644--- a/app/services/email_settings_validator.rb+++ b/app/services/email_settings_validator.rb@@ -116,7 +116,12 @@ class EmailSettingsValidatorssl_context = Net::SMTP.default_ssl_contextssl_context.verify_mode = openssl_verify_mode if openssl_verify_mode- smtp.enable_starttls_auto(ssl_context) if enable_starttls_auto+ if enable_starttls_auto+ # starttls is automatic, but we might need to change the context+ smtp.enable_starttls_auto(ssl_context)+ else+ smtp.disable_starttls+ endsmtp.enable_tls(ssl_context) if enable_tlssmtp.open_timeout = 5diff --git a/app/services/problem_check/starttls_disabled.rb b/app/services/problem_check/starttls_disabled.rbnew file mode 100644index 00000000000..f38427900d8--- /dev/null+++ b/app/services/problem_check/starttls_disabled.rb@@ -0,0 +1,13 @@+# frozen_string_literal: true++class ProblemCheck::StarttlsDisabled < ProblemCheck+ self.priority = "high"++ def call+ if GlobalSetting.smtp_enable_start_tls+ no_problem+ else+ problem+ end+ end+enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex c591c61163a..f45cddba6ad 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1713,6 +1713,7 @@ en:category_style_deprecated: "Your Discourse is currently using a deprecated category style which will be removed before the final beta release of Discourse 3.2. Please refer to <a href='https://meta.discourse.org/t/282441'>Moving to a Single Category Style Site Setting</a> for instructions on how to keep your selected category style."maxmind_db_configuration: 'The server has been configured to use MaxMind databases for reverse IP lookups but a valid MaxMind account ID has not been configured which may result in MaxMind databases failing to download in the future. <a href="https://meta.discourse.org/t/configure-maxmind-for-reverse-ip-lookups/173941" target="_blank">See this guide to learn more</a>.'admin_sidebar_deprecation: "The old admin layout is deprecated in favour of the new <a href='https://meta.discourse.org/t/-/289281'>sidebar layout</a> and will be removed in the next release. You can <a href='%{base_path}/admin/config/navigation?filter=admin%20sidebar'>configure</a> the new sidebar layout now to opt in before that."+ starttls_disabled: "The outgoing email configuration has STARTTLS disabled. This is almost never necessary. Consider removing <pre>DISCOURSE_SMTP_ENABLE_START_TLS=false</pre> from your environment. Please refer to <a href='https://meta.discourse.org/t/387286'>this topic</a> for more details."back_from_logster_text: "Back to site"site_settings:diff --git a/spec/services/email_settings_validator_spec.rb b/spec/services/email_settings_validator_spec.rbindex e7387889f6e..e3dd9ab77db 100644--- a/spec/services/email_settings_validator_spec.rb+++ b/spec/services/email_settings_validator_spec.rb@@ -161,6 +161,7 @@ RSpec.describe EmailSettingsValidator doobj.stubs(:start).returns(true)obj.stubs(:finish).returns(true)obj.stubs(:enable_tls).returns(true)+ obj.stubs(:disable_starttls).returns(true)obj.stubs(:enable_starttls_auto).returns(true)obj.stubs(:open_timeout=)obj.stubs(:read_timeout=)diff --git a/spec/services/problem_check/starttls_disabled_spec.rb b/spec/services/problem_check/starttls_disabled_spec.rbnew file mode 100644index 00000000000..854f89fb767--- /dev/null+++ b/spec/services/problem_check/starttls_disabled_spec.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true++RSpec.describe ProblemCheck::StarttlsDisabled do+ subject(:check) { described_class.new }++ describe ".call" do+ context "with STARTTLS enabled" do+ before { GlobalSetting.stubs(:smtp_enable_start_tls).returns(true) }+ it { expect(check).to be_chill_about_it }+ end++ context "with STARTTLS disabled" do+ before { GlobalSetting.stubs(:smtp_enable_start_tls).returns(false) }+ it do+ expect(check).to have_a_problem.with_priority("high").with_message(+ I18n.t("dashboard.problem.#{check.identifier}"),+ )+ end+ end+ end+end