1require 'net/smtp' 2require 'minitest/autorun' 3 4module Net 5 class SMTP 6 class TestResponse < MiniTest::Unit::TestCase 7 def test_capabilities 8 res = Response.parse("250-ubuntu-desktop\n250-PIPELINING\n250-SIZE 10240000\n250-VRFY\n250-ETRN\n250-STARTTLS\n250-ENHANCEDSTATUSCODES\n250 DSN\n") 9 10 capabilities = res.capabilities 11 %w{ PIPELINING SIZE VRFY STARTTLS ENHANCEDSTATUSCODES DSN}.each do |str| 12 assert capabilities.key?(str), str 13 end 14 end 15 16 def test_capabilities_default 17 res = Response.parse("250-ubuntu-desktop\n250-PIPELINING\n250 DSN\n") 18 assert_equal [], res.capabilities['PIPELINING'] 19 end 20 21 def test_capabilities_value 22 res = Response.parse("250-ubuntu-desktop\n250-SIZE 1234\n250 DSN\n") 23 assert_equal ['1234'], res.capabilities['SIZE'] 24 end 25 26 def test_capabilities_multi 27 res = Response.parse("250-ubuntu-desktop\n250-SIZE 1 2 3\n250 DSN\n") 28 assert_equal %w{1 2 3}, res.capabilities['SIZE'] 29 end 30 31 def test_bad_string 32 res = Response.parse("badstring") 33 assert_equal({}, res.capabilities) 34 end 35 36 def test_success? 37 res = Response.parse("250-ubuntu-desktop\n250-SIZE 1 2 3\n250 DSN\n") 38 assert res.success? 39 assert !res.continue? 40 end 41 42 # RFC 2821, Section 4.2.1 43 def test_continue? 44 res = Response.parse("3yz-ubuntu-desktop\n250-SIZE 1 2 3\n250 DSN\n") 45 assert !res.success? 46 assert res.continue? 47 end 48 49 def test_status_type_char 50 res = Response.parse("3yz-ubuntu-desktop\n250-SIZE 1 2 3\n250 DSN\n") 51 assert_equal '3', res.status_type_char 52 53 res = Response.parse("250-ubuntu-desktop\n250-SIZE 1 2 3\n250 DSN\n") 54 assert_equal '2', res.status_type_char 55 end 56 57 def test_message 58 res = Response.parse("250-ubuntu-desktop\n250-SIZE 1 2 3\n250 DSN\n") 59 assert_equal "250-ubuntu-desktop\n", res.message 60 end 61 62 def test_server_busy_exception 63 res = Response.parse("400 omg busy") 64 assert_equal Net::SMTPServerBusy, res.exception_class 65 res = Response.parse("410 omg busy") 66 assert_equal Net::SMTPServerBusy, res.exception_class 67 end 68 69 def test_syntax_error_exception 70 res = Response.parse("500 omg syntax error") 71 assert_equal Net::SMTPSyntaxError, res.exception_class 72 73 res = Response.parse("501 omg syntax error") 74 assert_equal Net::SMTPSyntaxError, res.exception_class 75 end 76 77 def test_authentication_exception 78 res = Response.parse("530 omg auth error") 79 assert_equal Net::SMTPAuthenticationError, res.exception_class 80 81 res = Response.parse("531 omg auth error") 82 assert_equal Net::SMTPAuthenticationError, res.exception_class 83 end 84 85 def test_fatal_error 86 res = Response.parse("510 omg fatal error") 87 assert_equal Net::SMTPFatalError, res.exception_class 88 89 res = Response.parse("511 omg fatal error") 90 assert_equal Net::SMTPFatalError, res.exception_class 91 end 92 93 def test_default_exception 94 res = Response.parse("250 omg fatal error") 95 assert_equal Net::SMTPUnknownError, res.exception_class 96 end 97 end 98 end 99end 100