diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-08 07:06:57 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-08 07:06:57 +0000 |
commit | a7c02f1f88a8a05335ab5112e6765fb844512ae5 (patch) | |
tree | 53a744559b70b472515a77a81bff265d9b806ea2 /test/net/smtp/test_smtp.rb | |
parent | 1e95b41a880f3e4a4f41603719d56701a8ec31ea (diff) | |
download | ruby-a7c02f1f88a8a05335ab5112e6765fb844512ae5.tar.gz |
* lib/net/smtp.rb (getok, get_response): raise an ArgumentError when
CR or LF is included in a line, because they are not allowed in
RFC5321.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55324 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/net/smtp/test_smtp.rb')
-rw-r--r-- | test/net/smtp/test_smtp.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb index 0edb3419d5..3bcceb6fc5 100644 --- a/test/net/smtp/test_smtp.rb +++ b/test/net/smtp/test_smtp.rb @@ -6,6 +6,8 @@ require 'test/unit' module Net class TestSMTP < Test::Unit::TestCase class FakeSocket + attr_reader :write_io + def initialize out = "250 OK\n" @write_io = StringIO.new @read_io = StringIO.new out @@ -51,5 +53,50 @@ module Net assert smtp.rset end + + def test_mailfrom + sock = FakeSocket.new + smtp = Net::SMTP.new 'localhost', 25 + smtp.instance_variable_set :@socket, sock + assert smtp.mailfrom("foo@example.com").success? + assert_equal "MAIL FROM:<foo@example.com>\r\n", sock.write_io.string + end + + def test_rcptto + sock = FakeSocket.new + smtp = Net::SMTP.new 'localhost', 25 + smtp.instance_variable_set :@socket, sock + assert smtp.rcptto("foo@example.com").success? + assert_equal "RCPT TO:<foo@example.com>\r\n", sock.write_io.string + end + + def test_auth_plain + sock = FakeSocket.new + smtp = Net::SMTP.new 'localhost', 25 + smtp.instance_variable_set :@socket, sock + assert smtp.auth_plain("foo", "bar").success? + assert_equal "AUTH PLAIN AGZvbwBiYXI=\r\n", sock.write_io.string + end + + def test_crlf_injection + smtp = Net::SMTP.new 'localhost', 25 + smtp.instance_variable_set :@socket, FakeSocket.new + + assert_raise(ArgumentError) do + smtp.mailfrom("foo\r\nbar") + end + + assert_raise(ArgumentError) do + smtp.mailfrom("foo\rbar") + end + + assert_raise(ArgumentError) do + smtp.mailfrom("foo\nbar") + end + + assert_raise(ArgumentError) do + smtp.rcptto("foo\r\nbar") + end + end end end |