mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-02 21:27:59 +08:00
RFC5735 prescribes networks for use in tests and documentation and we should use those instead of sending connection attempts to Australia every time our test suite runs.
43 lines
1.5 KiB
Ruby
43 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "SMTP Settings Integration" do
|
|
before do
|
|
@original_action_mailer_smtp_settings = ActionMailer::Base.smtp_settings
|
|
@original_action_mailer_delivery_method = ActionMailer::Base.delivery_method
|
|
ActionMailer::Base.delivery_method = :smtp
|
|
end
|
|
|
|
after do
|
|
ActionMailer::Base.smtp_settings = @original_action_mailer_smtp_settings
|
|
ActionMailer::Base.delivery_method = @original_action_mailer_delivery_method
|
|
end
|
|
|
|
it "should disable starttls_auto when tls is enabled" do
|
|
global_setting :smtp_address, "localhost"
|
|
global_setting :smtp_port, 465
|
|
global_setting :smtp_force_tls, true
|
|
|
|
expect(GlobalSetting.smtp_settings[:enable_starttls_auto]).to be_falsey
|
|
end
|
|
|
|
it "should leave starttls_auto enabled when tls is not enabled" do
|
|
global_setting :smtp_address, "localhost"
|
|
global_setting :smtp_port, 587
|
|
global_setting :smtp_force_tls, false
|
|
|
|
expect(GlobalSetting.smtp_settings[:enable_starttls_auto]).to be_truthy
|
|
end
|
|
|
|
it "should attempt to send out an email without raising any SMTP argument errors" do
|
|
global_setting :smtp_address, "192.0.2.1"
|
|
global_setting :smtp_port, 12_345
|
|
global_setting :smtp_open_timeout, 0.00001
|
|
|
|
ActionMailer::Base.smtp_settings = GlobalSetting.smtp_settings
|
|
|
|
message = TestMailer.send_test("some_email")
|
|
expect do Email::Sender.new(message, :test_message).send end.to raise_error { |err|
|
|
expect(err).to be_a(Net::OpenTimeout).or be_a(Errno::ENETUNREACH).or be_a(Errno::ECONNREFUSED)
|
|
}
|
|
end
|
|
end
|