-
Notifications
You must be signed in to change notification settings - Fork 941
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1536 from eval/refactor-smtp-tls-starttls
SMTP: refactor and accept starttls :always and :auto
- Loading branch information
Showing
4 changed files
with
155 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,24 +5,10 @@ | |
RSpec.describe "SMTP Delivery Method" do | ||
|
||
before(:each) do | ||
MockSMTP.reset | ||
|
||
# Reset all defaults back to original state | ||
Mail.defaults do | ||
delivery_method :smtp, { :address => "localhost", | ||
:port => 25, | ||
:domain => 'localhost.localdomain', | ||
:user_name => nil, | ||
:password => nil, | ||
:authentication => nil, | ||
:enable_starttls => nil, | ||
:enable_starttls_auto => true, | ||
:openssl_verify_mode => nil, | ||
:tls => nil, | ||
:ssl => nil, | ||
:open_timeout => nil, | ||
:read_timeout => nil | ||
} | ||
end | ||
MockSMTP.clear_deliveries | ||
Mail.defaults { delivery_method :smtp, {} } | ||
end | ||
|
||
describe "general usage" do | ||
|
@@ -207,7 +193,7 @@ def redefine_verify_none(new_value) | |
|
||
message.deliver! | ||
|
||
expect(MockSMTP.security).to eq :enable_starttls_auto | ||
expect(MockSMTP.starttls).to eq :auto | ||
end | ||
|
||
it 'should allow forcing STARTTLS' do | ||
|
@@ -216,19 +202,70 @@ def redefine_verify_none(new_value) | |
to '[email protected]' | ||
subject 'Re: No way!' | ||
body 'Yeah sure' | ||
delivery_method :smtp, { :address => "localhost", | ||
:port => 25, | ||
:domain => 'localhost.localdomain', | ||
:user_name => nil, | ||
:password => nil, | ||
:authentication => nil, | ||
:enable_starttls => true } | ||
delivery_method :smtp, { :enable_starttls => true } | ||
end | ||
|
||
message.deliver! | ||
|
||
expect(MockSMTP.starttls).to eq :always | ||
end | ||
|
||
it 'should allow forcing STARTTLS via enable_starttls: :always (overriding :enable_starttls_auto)' do | ||
message = Mail.new do | ||
from '[email protected]' | ||
to '[email protected]' | ||
subject 'Re: No way!' | ||
body 'Yeah sure' | ||
delivery_method :smtp, { :enable_starttls => :always, | ||
:enable_starttls_auto => true } | ||
end | ||
|
||
message.deliver! | ||
|
||
expect(MockSMTP.security).to eq :enable_starttls | ||
expect(MockSMTP.starttls).to eq :always | ||
end | ||
|
||
it 'should allow detecting STARTTLS via enable_starttls: :auto (overriding :enable_starttls_auto)' do | ||
message = Mail.new do | ||
from '[email protected]' | ||
to '[email protected]' | ||
subject 'Re: No way!' | ||
body 'Yeah sure' | ||
delivery_method :smtp, { :enable_starttls => :auto, | ||
:enable_starttls_auto => false } | ||
end | ||
|
||
message.deliver! | ||
|
||
expect(MockSMTP.starttls).to eq :auto | ||
end | ||
|
||
it 'should allow disabling automatic STARTTLS' do | ||
message = Mail.new do | ||
from '[email protected]' | ||
to '[email protected]' | ||
subject 'Re: No way!' | ||
body 'Yeah sure' | ||
delivery_method :smtp, { :enable_starttls => false } | ||
end | ||
|
||
message.deliver! | ||
|
||
expect(MockSMTP.starttls).to eq false | ||
end | ||
|
||
it 'raises when setting STARTTLS with tls' do | ||
message = Mail.new do | ||
from '[email protected]' | ||
to '[email protected]' | ||
subject 'Re: No way!' | ||
body 'Yeah sure' | ||
delivery_method :smtp, { :tls => true, :enable_starttls => :always } | ||
end | ||
|
||
expect { | ||
message.deliver! | ||
}.to raise_error(ArgumentError, /:enable_starttls and :tls are mutually exclusive/) | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters