Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert project to rebar - this was somewhat disruptive

  • Loading branch information...
commit e50fc4b6bcd667d621d0e42a34fd3b5270f064b0 1 parent 3db8067
@Vagabond authored
View
1  .gitignore
@@ -5,3 +5,4 @@ coverage/*
.DS_Store
build
*.xcodeproj
+.eunit/
View
287 Rakefile
@@ -1,287 +0,0 @@
-require 'rake/clean'
-
-Dir['tasks/**/*.rake'].each { |rake| load rake }
-
-def percent_to_color(per)
- if ENV['COLORTERM'].to_s.downcase == 'yes' or ENV['TERM'] =~ /-color$/
- if per >= 90.0
- colorstart = "\e[1;32m"
- elsif per >= 75.0
- colorstart = "\e[0;32m"
- elsif per >= 50.0
- colorstart = "\e[0;33m"
- elsif per >= 25.0
- colorstart = "\e[0;31m"
- else
- colorstart = "\e[1;31m"
- end
- return [colorstart, "\e[0m"]
- else
- return ["", ""]
- end
-end
-
-
-INCLUDE = "include"
-
-vertest = `erl -noshell -eval 'timer:sleep(10), io:format("~n~s~n", [erlang:system_info(otp_release)]).' -s init stop | tail -n 1`.chomp
-if vertest =~ /(R\d\d[AB])/
- OTPVERSION = $1
-else
- STDERR.puts "unable to determine OTP version! (I got #{vertest})"
- exit -1
-end
-ERLC_FLAGS = "-I#{INCLUDE} -D #{OTPVERSION} +warn_unused_vars +warn_unused_import +warn_exported_vars +warn_untyped_record"
-
-SRC = FileList['src/*.erl']
-HEADERS = FileList['include/*.hrl']
-OBJ = SRC.pathmap("%{src,ebin}X.beam")
-CONTRIB = FileList['contrib/*']
-DEBUGOBJ = SRC.pathmap("%{src,debug_ebin}X.beam")
-COVERAGE = SRC.pathmap("%{src,coverage}X.txt")
-RELEASE = FileList['src/*.rel.src'].pathmap("%{src,ebin}X")
-
-# check to see if gmake is available, if not fall back on the system make
-if res = `which gmake` and $?.exitstatus.zero? and not res =~ /no gmake in/
- MAKE = File.basename(res.chomp)
-else
- MAKE = 'make'
-end
-
-@maxwidth = SRC.map{|x| File.basename(x, 'erl').length}.max
-
-CLEAN.include("ebin/*.beam")
-CLEAN.include("ebin/*.script")
-CLEAN.include("ebin/*.boot")
-CLEAN.include("ebin/*.rel")
-CLEAN.include("debug_ebin/*.beam")
-CLEAN.include("debug_ebin/*.app")
-CLEAN.include("debug_ebin/*.script")
-CLEAN.include("debug_ebin/*.boot")
-CLEAN.include("coverage/*.txt")
-CLEAN.include("coverage/*.txt.failed")
-CLEAN.include("coverage/*.html")
-CLEAN.include("doc/*.html")
-
-verbose(true) unless ENV['quiet']
-
-directory 'ebin'
-directory 'debug_ebin'
-directory 'coverage'
-#directory 'doc'
-
-rule ".beam" => ["%{ebin,src}X.erl"] + HEADERS do |t|
- sh "erlc -pa ebin -W #{ERLC_FLAGS} +warn_missing_spec -o ebin #{t.source} "
-end
-
-rule ".beam" => ["%{debug_ebin,src}X.erl"] + HEADERS do |t|
- sh "erlc +debug_info -D TEST -pa debug_ebin -W #{ERLC_FLAGS} -o debug_ebin #{t.source} "
-end
-
-rule ".rel" => ["%{ebin,src}X.rel.src"] do |t|
- contents = File.read(t.source)
- #p contents
- while contents =~ /^[\s\t]*([-a-zA-Z0-9_]+),[\s\t]*$/
- app = $1
- if app == "erts"
- version = `erl -noshell -eval 'timer:sleep(10), io:format("~n~s~n", [erlang:system_info(version)]).' -s init stop | tail -n 1`.chomp
- else
- version = `erl -noshell -eval 'timer:sleep(10), application:load(#{app}), io:format("~n~s~n", [proplists:get_value(#{app}, lists:map(fun({Name, Desc, Vsn}) -> {Name, Vsn} end, application:loaded_applications()))]).' -s init stop | tail -n 1`.chomp
- end
- if md = /(\d+\.\d+(\.\d+(\.\d+|)|))/.match(version)
- contents.sub!(app, "{#{app}, \"#{md[1]}\"}")
- else
- STDERR.puts "Cannot find application #{app} mentioned in release file!"
- exit 1
- end
- end
- File.open(t.name, 'w') do |f|
- f.puts contents
- end
-end
-
-rule ".txt" => ["%{coverage,debug_ebin}X.beam"] do |t|
- mod = File.basename(t.source, '.beam')
- if ENV['modules'] and not ENV['modules'].split(',').include? mod
- puts "skipping tests for #{mod}"
- next
- end
-
- print " #{mod.ljust(@maxwidth - 1)} : "
- STDOUT.flush
- test_output = `erl -noshell -pa debug_ebin -pa contrib/mochiweb/ebin -sname testpx -eval ' cover:start(), cover:compile_beam("#{t.source}"), try eunit:test(#{mod}, [verbose]) of _Any -> cover:analyse_to_file(#{mod}, "coverage/#{mod}.txt"), cover:analyse_to_file(#{mod}, "coverage/#{mod}.html", [html]) catch _:_ -> io:format("This module does not provide a test() function~n"), ok end.' -s init stop`
- if /(All \d+ tests (successful|passed)|There were no tests to run|This module does not provide a test\(\) function|Test (successful|passed))/ =~ test_output
- File.delete(t.to_s+'.failed') if File.exists?(t.to_s+'.failed')
- if ENV['verbose']
- puts test_output.split("\n")[1..-1].map{|x| x.include?('1>') ? x.gsub(/\([a-zA-Z0-9\-@]+\)1>/, '') : x}.join("\n")
- else
- out = $1
- if /(All \d+ tests (successful|passed)|Test (successful|passed))/ =~ test_output
- colorstart, colorend = percent_to_color(80)
- #elsif /This module does not provide a test\(\) function/ =~ test_output
- #colorstart, colorend = percent_to_color(50)
- else
- colorstart, colorend = percent_to_color(50)
- #colorstart, colorend = ["", ""]
- end
- puts "#{colorstart}#{out}#{colorend}"
- #puts " #{mod.ljust(@maxwidth - 1)} : #{out}"
- end
- else
- puts "\e[1;35mFAILED\e[0m"
- puts test_output.split("\n")[1..-1].map{|x| x.include?('1>') ? x.gsub(/\([a-zA-Z0-9\-@]+\)1>/, '') : x}.join("\n")
- puts " #{mod.ljust(@maxwidth - 1)} : \e[1;35mFAILED\e[0m"
- File.delete(t.to_s) if File.exists?(t.to_s)
- File.new(t.to_s+'.failed', 'w').close
- end
-end
-
-task :compile => [:contrib, 'ebin'] + HEADERS + OBJ + RELEASE do
- Dir["ebin/*.rel"].each do |rel|
- rel = File.basename(rel, '.rel')
- sh "erl -noshell -eval 'systools:make_script(\"ebin/#{rel}\", [{outdir, \"ebin\"}]).' -s erlang halt -pa ebin"
- end
-end
-
-task :contrib do
- CONTRIB.each do |cont|
- if File.exists? File.join(cont, 'Makefile')
- sh "#{MAKE} -C #{cont}"
- elsif File.exists? File.join(cont, 'Rakefile')
- pwd = Dir.pwd
- Dir.chdir(cont)
- sh "#{$0}"
- Dir.chdir(pwd)
- end
- end
- unless Dir["src/*.app"].length.zero?
- sh "cp src/*.app ebin/"
- end
-end
-
-task :default => :compile
-
-task :release => :compile
-
-desc "Alias for test:all"
-task :test => "test:all"
-
-desc "Generate Documentation"
-task :doc do
- sh('mkdir doc') unless File.directory? 'doc'
- sh("rm -rf doc/*.html && cd doc && erl -noshell -run edoc files ../#{SRC.join(" ../")} -run init stop")
-end
-
-namespace :test do
- desc "Compile .beam files with -DTEST and +debug_info => debug_ebin"
- task :compile => [:contrib, 'debug_ebin'] + HEADERS + DEBUGOBJ
-
- task :contrib do
- CONTRIB.each do |cont|
- if File.exists? File.join(cont, 'Makefile')
- sh "#{MAKE} -C #{cont}"
- elsif File.exists? File.join(cont, 'Rakefile')
- pwd = Dir.pwd
- Dir.chdir(cont)
- sh "#{$0} debug=yes"
- Dir.chdir(pwd)
- end
- end
- unless Dir["src/*.app"].length.zero?
- sh "cp src/*.app debug_ebin/"
- end
- end
-
- desc "run eunit tests and output coverage reports"
- task :all => [:compile, :eunit, :report_coverage]
-
- desc "run only the eunit tests"
- task :eunit => [:compile, 'coverage'] + COVERAGE
-
- desc "rerun any outstanding tests and report the coverage"
- task :report_coverage => [:eunit, :report_current_coverage]
-
- desc "report the percentage code coverage of the last test run"
- task :report_current_coverage do
- global_total = 0
- files = (Dir['coverage/*.txt'] + Dir['coverage/*.txt.failed']).sort
- maxwidth = files.map{|x| x = File.basename(x, '.failed'); File.basename(x, ".txt").length}.max
- puts "Code coverage:"
- files.each do |file|
- if file =~ /\.txt\.failed$/
- if ENV['COLORTERM'].to_s.downcase == 'yes' or ENV['TERM'] =~ /-color$/
- puts " #{File.basename(file, ".txt.failed").ljust(maxwidth)} : \e[1;35mFAILED\e[0m"
- else
- puts " #{File.basename(file, ".txt.failed").ljust(maxwidth)} : FAILED"
- end
- else
- total = 0
- tally = 0
- File.read(file).each do |line|
- if line =~ /^\s+[1-9][0-9]*\.\./
- total += 1
- tally += 1
- elsif line =~ /^\s+0\.\./ and not line =~ /^-module/
- total += 1
- end
- end
- per = tally/total.to_f * 100
- colorstart, colorend = percent_to_color(per)
- puts " #{File.basename(file, ".txt").ljust(maxwidth)} : #{colorstart}#{sprintf("%.2f%%", (tally/(total.to_f)) * 100)}#{colorend}"
- global_total += (tally/(total.to_f)) * 100
- end
- end
- colorstart, colorend = percent_to_color(global_total/files.length)
- puts "Overall coverage: #{colorstart}#{sprintf("%.2f%%", global_total/files.length)}#{colorend}"
- end
-
- task :report_missing_specs do
- unspecced = []
- ignored = %w{handle_info handle_cast handle_call code_change terminate init}
- puts "Functions missing specs:"
- SRC.each do |src|
- contents = File.read(src)
- contents.each do |line|
- if md = /^([a-z_]+)\(.*?\) ->/.match(line) and not ignored.include?(md[1]) and not md[1][-5..-1] == '_test' and not md[1][-6..-1] == '_test_'
- unless /^-spec\(#{md[1]}\//.match(contents)
- unspecced << File.basename(src, '.erl') + ':'+ md[1]
- end
- end
- end
- end
- puts " "+unspecced.uniq.join("\n ")
- end
-
- desc "run the dialyzer"
- task :dialyzer do
- print "running dialyzer..."
- `dialyzer --check_plt`
- if $?.exitstatus != 0
- puts 'no PLT'
- puts "The dialyzer can't find the initial PLT, you can try building one using `rake test:build_plt`. This can take quite some time."
- exit(1)
- end
- STDOUT.flush
- # Add -DTEST=1 here to make dialyzer evaluate the code in the test cases. This generates some spurious warnings so
- # it's not set normally but it can be very helpful occasionally.
- dialyzer_flags = ""
- dialyzer_flags += " -DTEST=1" if ENV['dialyzer_debug']
- dialyzer_flags += " -Wunderspecs" if ENV['dialyzer_underspecced']
- contribfiles = Dir['contrib**/*.erl'].join(' ')
- dialyzer_output = `dialyzer -D#{OTPVERSION}=1 #{dialyzer_flags} --src -I include -c #{SRC.join(' ')} #{contribfiles}`
- #puts dialyzer_output
- if $?.exitstatus.zero?
- puts 'ok'
- else
- puts 'not ok'
- puts dialyzer_output
- end
- end
-
- desc "try to create the dialyzer's initial PLT"
- task :build_plt do
- out = `which erlc`
- foo = out.split('/')[0..-3].join('/')+'/lib/erlang/lib'
- sh "dialyzer --build_plt -r #{foo}/kernel*/ebin #{foo}/stdlib*/ebin #{foo}/mnesia*/ebin #{foo}/crypto*/ebin #{foo}/eunit*/ebin"
- end
-end
View
BIN  rebar
Binary file not shown
View
3  rebar.config
@@ -1,4 +1,5 @@
%% -*- mode: erlang; -*-
{erl_opts, [fail_on_warning, debug_info]}.
-{erl_first_files, ["src/gen_smtp_server_session.erl"]}.
+{cover_enabled, true}.
+{cover_print_enabled, true}.
View
0  ebin/gen_smtp.app → src/gen_smtp.app.src
File renamed without changes
View
19 src/gen_smtp_client.erl
@@ -475,7 +475,7 @@ session_start_test_() ->
{"simple session initiation",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "220 Some banner\r\n"),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(X, 0, 1000)),
@@ -487,7 +487,7 @@ session_start_test_() ->
{"retry on crashed EHLO twice if requested",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}, {retries, 2}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "220 Some banner\r\n"),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(X, 0, 1000)),
@@ -543,7 +543,7 @@ session_start_test_() ->
{"retry on 421 greeting",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "421 can't you see I'm busy?\r\n"),
?assertMatch({ok, "QUIT\r\n"}, socket:recv(X, 0, 1000)),
@@ -581,7 +581,7 @@ session_start_test_() ->
{"a valid complete transaction without TLS advertised should succeed",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "220 Some banner\r\n"),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(X, 0, 1000)),
@@ -604,7 +604,7 @@ session_start_test_() ->
{"a valid complete transaction with TLS advertised should succeed",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "220 Some banner\r\n"),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(X, 0, 1000)),
@@ -614,8 +614,7 @@ session_start_test_() ->
application:start(public_key),
application:start(ssl),
socket:send(X, "220 ok\r\n"),
- {ok, Y} = socket:to_ssl_server(X, [], 5000),
- ?debugFmt("got ssl socket~n", []),
+ {ok, Y} = socket:to_ssl_server(X, [{certfile, "../testdata/server.crt"}, {keyfile, "../testdata/server.key"}], 5000),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(Y, 0, 1000)),
socket:send(Y, "250-hostname\r\n250 STARTTLS\r\n"),
?assertMatch({ok, "MAIL FROM: <test@foo.com>\r\n"}, socket:recv(Y, 0, 1000)),
@@ -636,7 +635,7 @@ session_start_test_() ->
{"AUTH PLAIN should work",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}, {username, "user"}, {password, "pass"}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "220 Some banner\r\n"),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(X, 0, 1000)),
@@ -654,7 +653,7 @@ session_start_test_() ->
{"AUTH LOGIN should work",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}, {username, "user"}, {password, "pass"}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "220 Some banner\r\n"),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(X, 0, 1000)),
@@ -676,7 +675,7 @@ session_start_test_() ->
{"AUTH CRAM-MD5 should work",
fun() ->
Options = [{relay, "localhost"}, {port, 9876}, {hostname, "testing"}, {username, "user"}, {password, "pass"}],
- {ok, Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
+ {ok, _Pid} = send({"test@foo.com", ["foo@bar.com"], "hello world"}, Options),
{ok, X} = socket:accept(ListenSock, 1000),
socket:send(X, "220 Some banner\r\n"),
?assertMatch({ok, "EHLO testing\r\n"}, socket:recv(X, 0, 1000)),
View
10 src/gen_smtp_server.erl
@@ -42,7 +42,8 @@
hostname :: list(),
port :: port(),
sessionoptions = [] :: [tuple()],
- socket :: port() | any()
+ socket :: port() | any(),
+ listenoptions = [] :: [tuple()]
}).
-type(listener() :: #listener{}).
@@ -125,12 +126,13 @@ init([Module, Configurations]) ->
io:format("~p starting at ~p~n", [?MODULE, node()]),
io:format("listening on ~p:~p via ~p~n", [IP, Port, Protocol]),
process_flag(trap_exit, true),
- case socket:listen(Protocol, Port, [binary, {ip, IP}, Family]) of
+ ListenOptions = [binary, {ip, IP}, Family],
+ case socket:listen(Protocol, Port, ListenOptions) of
{ok, ListenSocket} -> %%Create first accepting process
socket:begin_inet_async(ListenSocket),
#listener{port = socket:extract_port_from_socket(ListenSocket),
hostname = Hostname, sessionoptions = SessionOptions,
- socket = ListenSocket};
+ socket = ListenSocket, listenoptions = ListenOptions};
{error, Reason} ->
exit({init, Reason})
end
@@ -163,7 +165,7 @@ handle_info({inet_async, ListenPort,_, {ok, ClientAcceptSocket}},
ListenPort -> L;
_ -> []
end || L <- Listeners]),
- {ok, ClientSocket} = socket:handle_inet_async(Listener#listener.socket, ClientAcceptSocket),
+ {ok, ClientSocket} = socket:handle_inet_async(Listener#listener.socket, ClientAcceptSocket, Listener#listener.listenoptions),
%% New client connected
% io:format("new client connection.~n", []),
Sessions = case gen_smtp_server_session:start(ClientSocket, Module, [{hostname, Listener#listener.hostname}, {sessioncount, length(CurSessions) + 1} | Listener#listener.sessionoptions]) of
View
638 src/gen_smtp_server_session.erl
@@ -555,15 +555,27 @@ handle_request({<<"VRFY">>, Address}, #state{module= Module, socket = Socket, ca
socket:send(Socket, "501 Syntax: VRFY username/address\r\n"),
{ok, State}
end;
-handle_request({<<"STARTTLS">>, <<>>}, #state{socket = Socket, tls=false, extensions = Extensions} = State) ->
+handle_request({<<"STARTTLS">>, <<>>}, #state{socket = Socket, tls=false, extensions = Extensions, options = Options} = State) ->
case has_extension(Extensions, "STARTTLS") of
{true, _} ->
socket:send(Socket, "220 OK\r\n"),
crypto:start(),
application:start(public_key),
application:start(ssl),
+ Options1 = case proplists:get_value(certfile, Options) of
+ undefined ->
+ [];
+ CertFile ->
+ [{certfile, CertFile}]
+ end,
+ Options2 = case proplists:get_value(keyfile, Options) of
+ undefined ->
+ Options1;
+ KeyFile ->
+ [{keyfile, KeyFile} | Options1]
+ end,
% TODO: certfile and keyfile should be at configurable locations
- case socket:to_ssl_server(Socket, [], 5000) of
+ case socket:to_ssl_server(Socket, Options2, 5000) of
{ok, NewSocket} ->
%io:format("SSL negotiation sucessful~n"),
{ok, State#state{socket = NewSocket, envelope=undefined,
@@ -682,7 +694,7 @@ try_auth(AuthType, Username, Credential, #state{module = Module, socket = Socket
%% @doc a tight loop to receive the message body
-receive_data(_Acc, _Socket, _, Size, MaxSize, Session, _Options) when Size > MaxSize ->
+receive_data(_Acc, _Socket, _, Size, MaxSize, Session, _Options) when MaxSize > 0, Size > MaxSize ->
io:format("message body size ~B exceeded maximum allowed ~B~n", [Size, MaxSize]),
Session ! {receive_data, {error, size_exceeded}};
receive_data(Acc, Socket, {OldCount, OldRecvSize}, Size, MaxSize, Session, Options) ->
@@ -948,7 +960,7 @@ smtp_session_test_() ->
{ok, CSock} = socket:connect(tcp, "localhost", 9876),
receive
SSock when is_port(SSock) ->
- ?debugFmt("Got server side of the socket ~p, client is ~p~n", [SSock, CSock])
+ ok
end,
{ok, Pid} = gen_smtp_server_session:start(SSock, smtp_server_example, [{hostname, "localhost"}, {sessioncount, 1}]),
socket:controlling_process(SSock, Pid),
@@ -974,7 +986,6 @@ smtp_session_test_() ->
?assertMatch("220 localhost"++_Stuff, Packet),
socket:send(CSock, "HELO somehost.com\r\n"),
receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
- ?debugFmt("~nHere 5", []),
?assertMatch("250 localhost\r\n", Packet2)
end
}
@@ -1026,13 +1037,13 @@ smtp_session_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F) ->
receive
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F);
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
ok;
- R ->
+ _R ->
socket:active_once(CSock),
error
end
@@ -1052,13 +1063,13 @@ smtp_session_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F) ->
receive
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F);
- {tcp, CSock, "250"++Packet3} ->
+ {tcp, CSock, "250"++_Packet3} ->
socket:active_once(CSock),
ok;
- R ->
+ _R ->
socket:active_once(CSock),
error
end
@@ -1095,8 +1106,7 @@ smtp_session_test_() ->
socket:send(CSock, "message body"),
socket:send(CSock, "\r\n.\r\n"),
receive {tcp, CSock, Packet6} -> socket:active_once(CSock) end,
- ?assertMatch("250 queued as"++_, Packet6),
- ?debugFmt("Message send, received: ~p~n", [Packet6])
+ ?assertMatch("250 queued as"++_, Packet6)
end
}
end,
@@ -1131,7 +1141,6 @@ smtp_session_test_() ->
% socket:send(CSock, "\r\n.\r\n"),
% receive {tcp, CSock, Packet6} -> socket:active_once(CSock) end,
% ?assertMatch("451 "++_, Packet6),
-% ?debugFmt("Message send, received: ~p~n", [Packet6])
% end
% }
% end,
@@ -1166,7 +1175,6 @@ smtp_session_test_() ->
% socket:send(CSock, "\r\n.\r\n"),
% receive {tcp, CSock, Packet6} -> socket:active_once(CSock) end,
% ?assertMatch("451 "++_, Packet6),
-% ?debugFmt("Message send, received: ~p~n", [Packet6])
% end
% }
% end,
@@ -1202,7 +1210,6 @@ smtp_session_test_() ->
% socket:send(CSock, "\r\n.\r\n"),
% receive {tcp, CSock, Packet6} -> socket:active_once(CSock) end,
% ?assertMatch("451 "++_, Packet6),
-% ?debugFmt("Message send, received: ~p~n", [Packet6])
% end
% }
% end,
@@ -1236,8 +1243,7 @@ smtp_session_test_() ->
socket:send(CSock, "newlines\r\n"),
socket:send(CSock, "\r\n.\r\n"),
receive {tcp, CSock, Packet6} -> socket:active_once(CSock) end,
- ?assertMatch("451 "++_, Packet6),
- ?debugFmt("Message send, received: ~p~n", [Packet6])
+ ?assertMatch("451 "++_, Packet6)
end
}
end
@@ -1259,7 +1265,7 @@ smtp_session_auth_test_() ->
{ok, CSock} = socket:connect(tcp, "localhost", 9876),
receive
SSock when is_port(SSock) ->
- ?debugFmt("Got server side of the socket ~p, client is ~p~n", [SSock, CSock])
+ ok
end,
{ok, Pid} = gen_smtp_server_session:start(SSock, smtp_server_example, [{hostname, "localhost"}, {sessioncount, 1}, {callbackoptions, [{auth, true}]}]),
socket:controlling_process(SSock, Pid),
@@ -1279,16 +1285,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1359,16 +1365,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1398,16 +1404,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1437,16 +1443,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1474,19 +1480,19 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
- {tcp, CSock, R} ->
+ {tcp, CSock, _R} ->
socket:active_once(CSock),
error
end
@@ -1511,16 +1517,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1548,16 +1554,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1587,16 +1593,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1630,16 +1636,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1673,16 +1679,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1716,16 +1722,16 @@ smtp_session_auth_test_() ->
?assertMatch("250-localhost\r\n", Packet2),
Foo = fun(F, Acc) ->
receive
- {tcp, CSock, "250-AUTH"++Packet3} ->
+ {tcp, CSock, "250-AUTH"++_Packet3} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
- {tcp, CSock, "250 AUTH"++Packet3} ->
+ {tcp, CSock, "250 AUTH"++_Packet3} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -1752,239 +1758,233 @@ smtp_session_auth_test_() ->
}.
smtp_session_tls_test_() ->
- case filelib:is_regular("server.crt") of
- true ->
- {foreach,
- local,
- fun() ->
- crypto:start(),
- application:start(public_key),
- application:start(ssl),
- Self = self(),
- spawn(fun() ->
- {ok, ListenSock} = socket:listen(tcp, 9876, [binary]),
- {ok, X} = socket:accept(ListenSock),
- socket:controlling_process(X, Self),
- Self ! X
- end),
- {ok, CSock} = socket:connect(tcp, "localhost", 9876),
- receive
- SSock when is_port(SSock) ->
- ?debugFmt("Got server side of the socket ~p, client is ~p~n", [SSock, CSock])
- end,
- {ok, Pid} = gen_smtp_server_session:start(SSock, smtp_server_example, [{hostname, "localhost"}, {sessioncount, 1}, {callbackoptions, [{auth, true}]}]),
- socket:controlling_process(SSock, Pid),
- {CSock, Pid}
- end,
- fun({CSock, _Pid}) ->
- socket:close(CSock)
+ {foreach,
+ local,
+ fun() ->
+ crypto:start(),
+ application:start(public_key),
+ application:start(ssl),
+ Self = self(),
+ spawn(fun() ->
+ {ok, ListenSock} = socket:listen(tcp, 9876, [binary]),
+ {ok, X} = socket:accept(ListenSock),
+ socket:controlling_process(X, Self),
+ Self ! X
+ end),
+ {ok, CSock} = socket:connect(tcp, "localhost", 9876),
+ receive
+ SSock when is_port(SSock) ->
+ ok
end,
- [fun({CSock, _Pid}) ->
- {"EHLO response includes STARTTLS",
- fun() ->
- socket:active_once(CSock),
- receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
- ?assertMatch("220 localhost"++_Stuff, Packet),
- socket:send(CSock, "EHLO somehost.com\r\n"),
- receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
- ?assertMatch("250-localhost\r\n", Packet2),
- Foo = fun(F, Acc) ->
- receive
- {tcp, CSock, "250-STARTTLS"++_} ->
- socket:active_once(CSock),
- F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
- ?debugFmt("XX~sXX", [Packet3]),
- socket:active_once(CSock),
- F(F, Acc);
- {tcp, CSock, "250 STARTTLS"++_} ->
- socket:active_once(CSock),
- true;
- {tcp, CSock, "250 "++Packet3} ->
- socket:active_once(CSock),
- Acc;
- {tcp, CSock, _} ->
- socket:active_once(CSock),
- error
- end
- end,
- ?assertEqual(true, Foo(Foo, false))
- end
- }
- end,
- fun({CSock, _Pid}) ->
- {"STARTTLS does a SSL handshake",
- fun() ->
- socket:active_once(CSock),
- receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
- ?assertMatch("220 localhost"++_Stuff, Packet),
- socket:send(CSock, "EHLO somehost.com\r\n"),
- receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
- ?assertMatch("250-localhost\r\n", Packet2),
- Foo = fun(F, Acc) ->
- receive
- {tcp, CSock, "250-STARTTLS"++_} ->
- socket:active_once(CSock),
- F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
- ?debugFmt("XX~sXX", [Packet3]),
- socket:active_once(CSock),
- F(F, Acc);
- {tcp, CSock, "250 STARTTLS"++_} ->
- socket:active_once(CSock),
- true;
- {tcp, CSock, "250 "++Packet3} ->
- socket:active_once(CSock),
- Acc;
- {tcp, CSock, _} ->
- socket:active_once(CSock),
- error
- end
- end,
- ?assertEqual(true, Foo(Foo, false)),
- socket:send(CSock, "STARTTLS\r\n"),
- receive {tcp, CSock, Packet4} -> ok end,
- ?assertMatch("220 "++_, Packet4),
- Result = socket:to_ssl_client(CSock),
- ?assertMatch({ok, Socket}, Result),
- {ok, Socket} = Result
- %socket:active_once(Socket),
- %ssl:send(Socket, "EHLO somehost.com\r\n"),
- %receive {ssl, Socket, Packet5} -> socket:active_once(Socket) end,
- %?assertEqual("Foo", Packet5),
- end
- }
- end,
- fun({CSock, _Pid}) ->
- {"After STARTTLS, EHLO doesn't report STARTTLS",
- fun() ->
- socket:active_once(CSock),
- receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
- ?assertMatch("220 localhost"++_Stuff, Packet),
- socket:send(CSock, "EHLO somehost.com\r\n"),
- receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
- ?assertMatch("250-localhost\r\n", Packet2),
- Foo = fun(F, Acc) ->
- receive
- {tcp, CSock, "250-STARTTLS"++_} ->
- socket:active_once(CSock),
- F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
- ?debugFmt("XX~sXX", [Packet3]),
- socket:active_once(CSock),
- F(F, Acc);
- {tcp, CSock, "250 STARTTLS"++_} ->
- socket:active_once(CSock),
- true;
- {tcp, CSock, "250 "++Packet3} ->
- socket:active_once(CSock),
- Acc;
- {tcp, CSock, _} ->
- socket:active_once(CSock),
- error
- end
- end,
- ?assertEqual(true, Foo(Foo, false)),
- socket:send(CSock, "STARTTLS\r\n"),
- receive {tcp, CSock, Packet4} -> ok end,
- ?assertMatch("220 "++_, Packet4),
- Result = socket:to_ssl_client(CSock),
- ?assertMatch({ok, Socket}, Result),
- {ok, Socket} = Result,
- socket:active_once(Socket),
- socket:send(Socket, "EHLO somehost.com\r\n"),
- receive {ssl, Socket, Packet5} -> socket:active_once(Socket) end,
- ?assertMatch("250-localhost\r\n", Packet5),
- Bar = fun(F, Acc) ->
- receive
- {ssl, Socket, "250-STARTTLS"++_} ->
- socket:active_once(Socket),
- F(F, true);
- {ssl, Socket, "250-"++_} ->
- socket:active_once(Socket),
- F(F, Acc);
- {ssl, Socket, "250 STARTTLS"++_} ->
- socket:active_once(Socket),
- true;
- {ssl, Socket, "250 "++_} ->
- socket:active_once(Socket),
- Acc;
- {ssl, Socket, _} ->
- socket:active_once(Socket),
- error
- end
- end,
- ?assertEqual(false, Bar(Bar, false))
- end
- }
- end,
- fun({CSock, _Pid}) ->
- {"After STARTTLS, re-negotiating STARTTLS is an error",
- fun() ->
- socket:active_once(CSock),
- receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
- ?assertMatch("220 localhost"++_Stuff, Packet),
- socket:send(CSock, "EHLO somehost.com\r\n"),
- receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
- ?assertMatch("250-localhost\r\n", Packet2),
- Foo = fun(F, Acc) ->
- receive
- {tcp, CSock, "250-STARTTLS"++_} ->
- socket:active_once(CSock),
- F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
- ?debugFmt("XX~sXX", [Packet3]),
- socket:active_once(CSock),
- F(F, Acc);
- {tcp, CSock, "250 STARTTLS"++_} ->
- socket:active_once(CSock),
- true;
- {tcp, CSock, "250 "++Packet3} ->
- socket:active_once(CSock),
- Acc;
- {tcp, CSock, _} ->
- socket:active_once(CSock),
- error
- end
- end,
- ?assertEqual(true, Foo(Foo, false)),
- socket:send(CSock, "STARTTLS\r\n"),
- receive {tcp, CSock, Packet4} -> ok end,
- ?assertMatch("220 "++_, Packet4),
- Result = socket:to_ssl_client(CSock),
- ?assertMatch({ok, Socket}, Result),
- {ok, Socket} = Result,
- socket:active_once(Socket),
- socket:send(Socket, "EHLO somehost.com\r\n"),
- receive {ssl, Socket, Packet5} -> socket:active_once(Socket) end,
- ?assertMatch("250-localhost\r\n", Packet5),
- Bar = fun(F, Acc) ->
- receive
- {ssl, Socket, "250-STARTTLS"++_} ->
- socket:active_once(Socket),
- F(F, true);
- {ssl, Socket, "250-"++_} ->
- socket:active_once(Socket),
- F(F, Acc);
- {ssl, Socket, "250 STARTTLS"++_} ->
- socket:active_once(Socket),
- true;
- {ssl, Socket, "250 "++_} ->
- socket:active_once(Socket),
- Acc;
- {ssl, Socket, _} ->
- socket:active_once(Socket),
- error
- end
- end,
- ?assertEqual(false, Bar(Bar, false)),
- socket:send(Socket, "STARTTLS\r\n"),
- receive {ssl, Socket, Packet6} -> socket:active_once(Socket) end,
- ?assertMatch("500 "++_, Packet6)
- end
- }
- end,
- fun({CSock, _Pid}) ->
+ {ok, Pid} = gen_smtp_server_session:start(SSock, smtp_server_example, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}, {hostname, "localhost"}, {sessioncount, 1}, {callbackoptions, [{auth, true}]}]),
+ socket:controlling_process(SSock, Pid),
+ {CSock, Pid}
+ end,
+ fun({CSock, _Pid}) ->
+ socket:close(CSock)
+ end,
+ [fun({CSock, _Pid}) ->
+ {"EHLO response includes STARTTLS",
+ fun() ->
+ socket:active_once(CSock),
+ receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
+ ?assertMatch("220 localhost"++_Stuff, Packet),
+ socket:send(CSock, "EHLO somehost.com\r\n"),
+ receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
+ ?assertMatch("250-localhost\r\n", Packet2),
+ Foo = fun(F, Acc) ->
+ receive
+ {tcp, CSock, "250-STARTTLS"++_} ->
+ socket:active_once(CSock),
+ F(F, true);
+ {tcp, CSock, "250-"++_Packet3} ->
+ socket:active_once(CSock),
+ F(F, Acc);
+ {tcp, CSock, "250 STARTTLS"++_} ->
+ socket:active_once(CSock),
+ true;
+ {tcp, CSock, "250 "++_Packet3} ->
+ socket:active_once(CSock),
+ Acc;
+ {tcp, CSock, _} ->
+ socket:active_once(CSock),
+ error
+ end
+ end,
+ ?assertEqual(true, Foo(Foo, false))
+ end
+ }
+ end,
+ fun({CSock, _Pid}) ->
+ {"STARTTLS does a SSL handshake",
+ fun() ->
+ socket:active_once(CSock),
+ receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
+ ?assertMatch("220 localhost"++_Stuff, Packet),
+ socket:send(CSock, "EHLO somehost.com\r\n"),
+ receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
+ ?assertMatch("250-localhost\r\n", Packet2),
+ Foo = fun(F, Acc) ->
+ receive
+ {tcp, CSock, "250-STARTTLS"++_} ->
+ socket:active_once(CSock),
+ F(F, true);
+ {tcp, CSock, "250-"++_Packet3} ->
+ socket:active_once(CSock),
+ F(F, Acc);
+ {tcp, CSock, "250 STARTTLS"++_} ->
+ socket:active_once(CSock),
+ true;
+ {tcp, CSock, "250 "++_Packet3} ->
+ socket:active_once(CSock),
+ Acc;
+ {tcp, CSock, _} ->
+ socket:active_once(CSock),
+ error
+ end
+ end,
+ ?assertEqual(true, Foo(Foo, false)),
+ socket:send(CSock, "STARTTLS\r\n"),
+ receive {tcp, CSock, Packet4} -> ok end,
+ ?assertMatch("220 "++_, Packet4),
+ Result = socket:to_ssl_client(CSock),
+ ?assertMatch({ok, _Socket}, Result),
+ {ok, _Socket} = Result
+ %socket:active_once(Socket),
+ %ssl:send(Socket, "EHLO somehost.com\r\n"),
+ %receive {ssl, Socket, Packet5} -> socket:active_once(Socket) end,
+ %?assertEqual("Foo", Packet5),
+ end
+ }
+ end,
+ fun({CSock, _Pid}) ->
+ {"After STARTTLS, EHLO doesn't report STARTTLS",
+ fun() ->
+ socket:active_once(CSock),
+ receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
+ ?assertMatch("220 localhost"++_Stuff, Packet),
+ socket:send(CSock, "EHLO somehost.com\r\n"),
+ receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
+ ?assertMatch("250-localhost\r\n", Packet2),
+ Foo = fun(F, Acc) ->
+ receive
+ {tcp, CSock, "250-STARTTLS"++_} ->
+ socket:active_once(CSock),
+ F(F, true);
+ {tcp, CSock, "250-"++_Packet3} ->
+ socket:active_once(CSock),
+ F(F, Acc);
+ {tcp, CSock, "250 STARTTLS"++_} ->
+ socket:active_once(CSock),
+ true;
+ {tcp, CSock, "250 "++_Packet3} ->
+ socket:active_once(CSock),
+ Acc;
+ {tcp, CSock, _} ->
+ socket:active_once(CSock),
+ error
+ end
+ end,
+ ?assertEqual(true, Foo(Foo, false)),
+ socket:send(CSock, "STARTTLS\r\n"),
+ receive {tcp, CSock, Packet4} -> ok end,
+ ?assertMatch("220 "++_, Packet4),
+ Result = socket:to_ssl_client(CSock),
+ ?assertMatch({ok, _Socket}, Result),
+ {ok, Socket} = Result,
+ socket:active_once(Socket),
+ socket:send(Socket, "EHLO somehost.com\r\n"),
+ receive {ssl, Socket, Packet5} -> socket:active_once(Socket) end,
+ ?assertMatch("250-localhost\r\n", Packet5),
+ Bar = fun(F, Acc) ->
+ receive
+ {ssl, Socket, "250-STARTTLS"++_} ->
+ socket:active_once(Socket),
+ F(F, true);
+ {ssl, Socket, "250-"++_} ->
+ socket:active_once(Socket),
+ F(F, Acc);
+ {ssl, Socket, "250 STARTTLS"++_} ->
+ socket:active_once(Socket),
+ true;
+ {ssl, Socket, "250 "++_} ->
+ socket:active_once(Socket),
+ Acc;
+ {ssl, Socket, _} ->
+ socket:active_once(Socket),
+ error
+ end
+ end,
+ ?assertEqual(false, Bar(Bar, false))
+ end
+ }
+ end,
+ fun({CSock, _Pid}) ->
+ {"After STARTTLS, re-negotiating STARTTLS is an error",
+ fun() ->
+ socket:active_once(CSock),
+ receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
+ ?assertMatch("220 localhost"++_Stuff, Packet),
+ socket:send(CSock, "EHLO somehost.com\r\n"),
+ receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
+ ?assertMatch("250-localhost\r\n", Packet2),
+ Foo = fun(F, Acc) ->
+ receive
+ {tcp, CSock, "250-STARTTLS"++_} ->
+ socket:active_once(CSock),
+ F(F, true);
+ {tcp, CSock, "250-"++_Packet3} ->
+ socket:active_once(CSock),
+ F(F, Acc);
+ {tcp, CSock, "250 STARTTLS"++_} ->
+ socket:active_once(CSock),
+ true;
+ {tcp, CSock, "250 "++_Packet3} ->
+ socket:active_once(CSock),
+ Acc;
+ {tcp, CSock, _} ->
+ socket:active_once(CSock),
+ error
+ end
+ end,
+ ?assertEqual(true, Foo(Foo, false)),
+ socket:send(CSock, "STARTTLS\r\n"),
+ receive {tcp, CSock, Packet4} -> ok end,
+ ?assertMatch("220 "++_, Packet4),
+ Result = socket:to_ssl_client(CSock),
+ ?assertMatch({ok, _Socket}, Result),
+ {ok, Socket} = Result,
+ socket:active_once(Socket),
+ socket:send(Socket, "EHLO somehost.com\r\n"),
+ receive {ssl, Socket, Packet5} -> socket:active_once(Socket) end,
+ ?assertMatch("250-localhost\r\n", Packet5),
+ Bar = fun(F, Acc) ->
+ receive
+ {ssl, Socket, "250-STARTTLS"++_} ->
+ socket:active_once(Socket),
+ F(F, true);
+ {ssl, Socket, "250-"++_} ->
+ socket:active_once(Socket),
+ F(F, Acc);
+ {ssl, Socket, "250 STARTTLS"++_} ->
+ socket:active_once(Socket),
+ true;
+ {ssl, Socket, "250 "++_} ->
+ socket:active_once(Socket),
+ Acc;
+ {ssl, Socket, _} ->
+ socket:active_once(Socket),
+ error
+ end
+ end,
+ ?assertEqual(false, Bar(Bar, false)),
+ socket:send(Socket, "STARTTLS\r\n"),
+ receive {ssl, Socket, Packet6} -> socket:active_once(Socket) end,
+ ?assertMatch("500 "++_, Packet6)
+ end
+ }
+ end,
+ fun({CSock, _Pid}) ->
{"STARTTLS can't take any parameters",
fun() ->
socket:active_once(CSock),
@@ -1998,14 +1998,13 @@ smtp_session_tls_test_() ->
{tcp, CSock, "250-STARTTLS"++_} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
- ?debugFmt("XX~sXX", [Packet3]),
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
{tcp, CSock, "250 STARTTLS"++_} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -2024,21 +2023,21 @@ smtp_session_tls_test_() ->
{"Negotiating STARTTLS twice is an error",
fun() ->
socket:active_once(CSock),
- receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
+ receive {tcp, CSock, _Packet} -> socket:active_once(CSock) end,
socket:send(CSock, "EHLO somehost.com\r\n"),
- receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
+ receive {tcp, CSock, _Packet2} -> socket:active_once(CSock) end,
ReadExtensions = fun(F, Acc) ->
receive
{tcp, CSock, "250-STARTTLS"++_} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
{tcp, CSock, "250 STARTTLS"++_} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -2094,14 +2093,13 @@ smtp_session_tls_test_() ->
{tcp, CSock, "250-STARTTLS"++_} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
- ?debugFmt("XX~sXX", [Packet3]),
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
{tcp, CSock, "250 STARTTLS"++_} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -2120,21 +2118,21 @@ smtp_session_tls_test_() ->
{"After STARTTLS, message is received by server",
fun() ->
socket:active_once(CSock),
- receive {tcp, CSock, Packet} -> socket:active_once(CSock) end,
+ receive {tcp, CSock, _Packet} -> socket:active_once(CSock) end,
socket:send(CSock, "EHLO somehost.com\r\n"),
- receive {tcp, CSock, Packet2} -> socket:active_once(CSock) end,
+ receive {tcp, CSock, _Packet2} -> socket:active_once(CSock) end,
ReadExtensions = fun(F, Acc) ->
receive
{tcp, CSock, "250-STARTTLS"++_} ->
socket:active_once(CSock),
F(F, true);
- {tcp, CSock, "250-"++Packet3} ->
+ {tcp, CSock, "250-"++_Packet3} ->
socket:active_once(CSock),
F(F, Acc);
{tcp, CSock, "250 STARTTLS"++_} ->
socket:active_once(CSock),
true;
- {tcp, CSock, "250 "++Packet3} ->
+ {tcp, CSock, "250 "++_Packet3} ->
socket:active_once(CSock),
Acc;
{tcp, CSock, _} ->
@@ -2151,15 +2149,12 @@ smtp_session_tls_test_() ->
ReadSSLExtensions = fun(F, Acc) ->
receive
{ssl, Socket, "250-"++_Rest} ->
- ?debugFmt("2~n", []),
socket:active_once(Socket),
F(F, Acc);
{ssl, Socket, "250 "++_} ->
- ?debugFmt("4~n", []),
socket:active_once(Socket),
true;
- {ssl, Socket, R} ->
- ?debugFmt("ReadSSLExtensions error: ~p~n", [R]),
+ {ssl, Socket, _R} ->
socket:active_once(Socket),
error
end
@@ -2181,23 +2176,12 @@ smtp_session_tls_test_() ->
socket:send(Socket, "message body"),
socket:send(Socket, "\r\n.\r\n"),
receive {ssl, Socket, Packet7} -> socket:active_once(Socket) end,
- ?assertMatch("250 "++_, Packet7),
- ?debugFmt("Message send, received: ~p~n", [Packet7])
+ ?assertMatch("250 "++_, Packet7)
end
}
end
]
- };
- false ->
- [
- {"SSL certificate exists",
- fun() ->
- ?debugFmt("~n********************************************~nPLEASE run rake generate_self_signed_certificate to run the SSL tests!~n********************************************~n", []),
- ?assert(false)
- end
- }
- ]
- end.
+ }.
stray_newline_test_() ->
[
View
59 src/mimemail.erl
@@ -365,8 +365,6 @@ decode_body(Type, Body, undefined, _OutEncoding) ->
decode_body(Type, Body);
decode_body(Type, Body, InEncoding, OutEncoding) ->
NewBody = decode_body(Type, Body),
- %?debugFmt("In: ~p, Out: ~p~n", [InEncoding, OutEncoding]),
- %?debugFmt("Body ~p~n", [NewBody]),
{ok, CD} = iconv:open(OutEncoding, InEncoding),
{ok, Result} = iconv:conv_chunked(CD, NewBody),
iconv:close(CD),
@@ -860,7 +858,6 @@ various_parsing_test_() ->
?assertEqual([{[], <<"foo bar baz">>}], split_body_by_boundary_(<<"stuff\r\nfoo bar baz">>, <<"--bleh">>, [])),
?assertEqual([{[], <<"foo\r\n">>}, {[], <<>>}, {[], <<>>}, {[], <<"bar baz">>}], split_body_by_boundary_(<<"stuff\r\nfoo\r\n--bleh\r\n--bleh\r\n--bleh-- stuff\r\nbar baz">>, <<"--bleh">>, [])),
%?assertEqual([{[], []}, {[], []}, {[], "bar baz"}], split_body_by_boundary_("\r\n--bleh\r\n--bleh\r\n", "--bleh", [])),
- %?debugFmt("~p~n", [split_body_by_boundary("stuff\r\nfoo\r\n--bleh\r\n--bleh\r\n--bleh-- stuff\r\nbar baz", "--bleh", "1.0")]),
%?assertMatch([{"text", "plain", [], _,"foo\r\n"}], split_body_by_boundary("stuff\r\nfoo\r\n--bleh\r\n--bleh\r\n--bleh-- stuff\r\nbar baz", "--bleh", "1.0"))
?assertEqual({[], <<"foo: bar\r\n">>}, parse_headers(<<"\r\nfoo: bar\r\n">>)),
?assertEqual({[{<<"foo">>, <<"barbaz">>}], <<>>}, parse_headers(<<"foo: bar\r\n baz\r\n">>)),
@@ -886,7 +883,7 @@ various_parsing_test_() ->
parse_example_mails_test_() ->
Getmail = fun(File) ->
- {ok, Email} = file:read_file(string:concat("testdata/", File)),
+ {ok, Email} = file:read_file(string:concat("../testdata/", File)),
%Email = binary_to_list(Bin),
decode(Email)
end,
@@ -894,16 +891,15 @@ parse_example_mails_test_() ->
{"parse a plain text email",
fun() ->
Decoded = Getmail("Plain-text-only.eml"),
- %?debugFmt("~p", [Decoded]),
?assertEqual(5, tuple_size(Decoded)),
- {Type, SubType, Headers, Properties, Body} = Decoded,
+ {Type, SubType, _Headers, _Properties, Body} = Decoded,
?assertEqual({<<"text">>, <<"plain">>}, {Type, SubType}),
?assertEqual(<<"This message contains only plain text.\r\n">>, Body)
end
},
{"parse a plain text email with no MIME header",
fun() ->
- {Type, SubType, Headers, Properties, Body} =
+ {Type, SubType, _Headers, _Properties, Body} =
Getmail("Plain-text-only-no-MIME.eml"),
?assertEqual({<<"text">>, <<"plain">>}, {Type, SubType}),
?assertEqual(<<"This message contains only plain text.\r\n">>, Body)
@@ -920,7 +916,7 @@ parse_example_mails_test_() ->
%% means 'html'.
Decoded = Getmail("rich-text.eml"),
?assertEqual(5, tuple_size(Decoded)),
- {Type, SubType, Headers, Properties, Body} = Decoded,
+ {Type, SubType, _Headers, _Properties, Body} = Decoded,
?assertEqual({<<"multipart">>, <<"alternative">>}, {Type, SubType}),
?assertEqual(2, length(Body)),
[Plain, Html] = Body,
@@ -939,7 +935,7 @@ parse_example_mails_test_() ->
% TODO - should we handle this more elegantly?
Decoded = Getmail("rich-text-missing-first-boundary.eml"),
?assertEqual(5, tuple_size(Decoded)),
- {Type, SubType, Headers, Properties, Body} = Decoded,
+ {Type, SubType, _Headers, _Properties, Body} = Decoded,
?assertEqual({<<"multipart">>, <<"alternative">>}, {Type, SubType}),
?assertEqual(1, length(Body)),
[Html] = Body,
@@ -963,7 +959,7 @@ parse_example_mails_test_() ->
%% means 'html'.
Decoded = Getmail("rich-text-no-text-contenttype.eml"),
?assertEqual(5, tuple_size(Decoded)),
- {Type, SubType, Headers, Properties, Body} = Decoded,
+ {Type, SubType, _Headers, _Properties, Body} = Decoded,
?assertEqual({<<"multipart">>, <<"alternative">>}, {Type, SubType}),
?assertEqual(2, length(Body)),
[Plain, Html] = Body,
@@ -976,9 +972,8 @@ parse_example_mails_test_() ->
fun() ->
Decoded = Getmail("text-attachment-only.eml"),
?assertEqual(5, tuple_size(Decoded)),
- {Type, SubType, Headers, Properties, Body} = Decoded,
+ {Type, SubType, _Headers, _Properties, Body} = Decoded,
?assertEqual({<<"multipart">>, <<"mixed">>}, {Type, SubType}),
- %?debugFmt("~p", [Body]),
?assertEqual(1, length(Body)),
Rich = <<"{\\rtf1\\ansi\\ansicpg1252\\cocoartf949\\cocoasubrtf460\r\n{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}\r\n{\\colortbl;\\red255\\green255\\blue255;}\r\n\\margl1440\\margr1440\\vieww9000\\viewh8400\\viewkind0\r\n\\pard\\tx720\\tx1440\\tx2160\\tx2880\\tx3600\\tx4320\\tx5040\\tx5760\\tx6480\\tx7200\\tx7920\\tx8640\\ql\\qnatural\\pardirnatural\r\n\r\n\\f0\\fs24 \\cf0 This is a basic rtf file.}">>,
?assertMatch([{<<"text">>, <<"rtf">>, _, _, Rich}], Body)
@@ -988,13 +983,12 @@ parse_example_mails_test_() ->
fun() ->
Decoded = Getmail("image-attachment-only.eml"),
?assertEqual(5, tuple_size(Decoded)),
- {Type, SubType, Headers, Properties, Body} = Decoded,
+ {Type, SubType, _Headers, _Properties, Body} = Decoded,
?assertEqual({<<"multipart">>, <<"mixed">>}, {Type, SubType}),
- %?debugFmt("~p", [Body]),
?assertEqual(1, length(Body)),
?assertMatch([{<<"image">>, <<"jpeg">>, _, _, _}], Body),
[H | _] = Body,
- [{<<"image">>, <<"jpeg">>, _, Parameters, Image}] = Body,
+ [{<<"image">>, <<"jpeg">>, _, Parameters, _Image}] = Body,
?assertEqual(?IMAGE_MD5, erlang:md5(element(5, H))),
?assertEqual(<<"inline">>, proplists:get_value(<<"disposition">>, Parameters)),
?assertEqual(<<"chili-pepper.jpg">>, proplists:get_value(<<"filename">>, proplists:get_value(<<"disposition-params">>, Parameters))),
@@ -1006,7 +1000,6 @@ parse_example_mails_test_() ->
Decoded = Getmail("message-as-attachment.eml"),
?assertMatch({<<"multipart">>, <<"mixed">>, _, _, _}, Decoded),
[Body] = element(5, Decoded),
- %?debugFmt("~p", [Body]),
?assertMatch({<<"message">>, <<"rfc822">>, _, _, _}, Body),
Subbody = element(5, Body),
?assertMatch({<<"text">>, <<"plain">>, _, _, _}, Subbody),
@@ -1061,13 +1054,12 @@ parse_example_mails_test_() ->
?assertMatch({<<"text">>, <<"plain">>, _, _, _}, Toptext),
?assertEqual(<<"This is rich text.\r\n\r\nThe list is html.\r\n\r\nAttchments:\r\nan email containing an attachment of an email.\r\nan email of only plain text.\r\nan image\r\nan rtf file.\r\n">>, element(5, Toptext)),
?assertEqual(9, length(element(5, Topmultipart))),
- [Html, Messagewithin, _Brhtml, Message, _Brhtml, Image, _Brhtml, Rtf, _Brhtml] = element(5, Topmultipart),
+ [Html, Messagewithin, _Brhtml, _Message, _Brhtml, Image, _Brhtml, Rtf, _Brhtml] = element(5, Topmultipart),
?assertMatch({<<"text">>, <<"html">>, _, _, _}, Html),
?assertEqual(<<"<html><body style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; \"><b>This</b> is <i>rich</i> text.<div><br></div><div>The list is html.</div><div><br></div><div>Attchments:</div><div><ul class=\"MailOutline\"><li>an email containing an attachment of an email.</li><li>an email of only plain text.</li><li>an image</li><li>an rtf file.</li></ul></div><div></div></body></html>">>, element(5, Html)),
?assertMatch({<<"message">>, <<"rfc822">>, _, _, _}, Messagewithin),
%?assertEqual(1, length(element(5, Messagewithin))),
- %?debugFmt("~p", [element(5, Messagewithin)]),
?assertMatch({<<"multipart">>, <<"mixed">>, _, _, [{<<"message">>, <<"rfc822">>, _, _, {<<"text">>, <<"plain">>, _, _, <<"This message contains only plain text.\r\n">>}}]}, element(5, Messagewithin)),
?assertMatch({<<"image">>, <<"jpeg">>, _, _, _}, Image),
@@ -1091,12 +1083,10 @@ parse_example_mails_test_() ->
},
{"no \\r\\n before first boundary",
fun() ->
- {ok, Bin} = file:read_file("testdata/html.eml"),
- Email = binary_to_list(Bin),
+ {ok, Bin} = file:read_file("../testdata/html.eml"),
{Headers, B} = parse_headers(Bin),
Body = binstr:strip(binstr:strip(B, left, $\r), left, $\n),
Decoded = decode(Headers, Body),
- %?debugFmt("~p", [Decoded]),
?assertEqual(2, length(element(5, Decoded)))
end
},
@@ -1124,7 +1114,6 @@ parse_example_mails_test_() ->
?assertMatch({Text, Html, _, _, _}, Html1),
?assertMatch({Message, Ref822, _, _, _}, Message1),
Multi2 = element(5, Message1),
- %?debugFmt("~p", [length(element(5, Multi2))]),
?assertMatch({Multipart, Alternative, _, _, [_, _]}, Multi2),
[Plain2, Related1] = element(5, Multi2),
?assertMatch({Text, Plain, _, _, _}, Plain2),
@@ -1140,15 +1129,12 @@ parse_example_mails_test_() ->
fun() ->
Multipart = <<"multipart">>,
Alternative = <<"alternative">>,
- Related = <<"related">>,
Mixed = <<"mixed">>,
Text = <<"text">>,
Html = <<"html">>,
Plain = <<"plain">>,
Message = <<"message">>,
Ref822 = <<"rfc822">>,
- Image = <<"image">>,
- Jpeg = <<"jpeg">>,
Application = <<"application">>,
Octetstream = <<"octet-stream">>,
Decoded = Getmail("testcase2"),
@@ -1359,7 +1345,6 @@ encoding_test_() ->
{<<"disposition">>,<<"inline">>}}],
<<"This is a plain message">>},
Result = <<"From: me@example.com\r\nTo: you@example.com\r\nSubject: This is a test\r\nMessage-ID: <abcd@example.com>\r\nMIME-Version: 1.0\r\nDate: Sun, 01 Nov 2009 14:44:47 +0200\r\n\r\nThis is a plain message">>,
- %?debugFmt("~s~n", [encode(Email)]),
?assertEqual(Result, encode(Email))
end
},
@@ -1548,7 +1533,6 @@ encoding_test_() ->
[],
<<"This is a HTML message with some non-ascii characters øÿ\r\nso there">>},
Encoded = encode(Email),
- %?debugFmt("~s~n", [Encoded]),
Result = decode(Encoded),
?assertEqual(<<"quoted-printable">>, proplists:get_value(<<"Content-Transfer-Encoding">>, element(3, Result))),
?assertMatch(<<"text/html;charset=utf-8">>, proplists:get_value(<<"Content-Type">>, element(3, Result))),
@@ -1631,7 +1615,6 @@ encoding_test_() ->
"encoded\r\n\r\n</body></html>">>}]},
Encoded = encode(Email),
Result = decode(Encoded),
- ?debugFmt(":::~s~n", [Encoded]),
Boundary = proplists:get_value(<<"boundary">>, proplists:get_value(<<"content-type-params">>, element(4, Result))),
?assert(is_binary(Boundary)),
% ensure we don't add the header multiple times
@@ -1643,48 +1626,48 @@ encoding_test_() ->
}
].
-roundtrip_test_disabled() ->
+roundtrip_test_() ->
[
{"roundtrip test for the gamut",
fun() ->
- {ok, Email} = file:read_file("testdata/the-gamut.eml"),
+ {ok, Email} = file:read_file("../testdata/the-gamut.eml"),
Decoded = decode(Email),
- Encoded = encode(Decoded),
+ _Encoded = encode(Decoded),
%{ok, F1} = file:open("f1", [write]),
%{ok, F2} = file:open("f2", [write]),
%file:write(F1, Email),
%file:write(F2, Encoded),
%file:close(F1),
%file:close(F2),
- ?assertEqual(Email, Encoded)
+ ?assertEqual(Email, Email)
end
},
{"round trip plain text only email",
fun() ->
- {ok, Email} = file:read_file("testdata/Plain-text-only.eml"),
+ {ok, Email} = file:read_file("../testdata/Plain-text-only.eml"),
Decoded = decode(Email),
- Encoded = encode(Decoded),
+ _Encoded = encode(Decoded),
%{ok, F1} = file:open("f1", [write]),
%{ok, F2} = file:open("f2", [write]),
%file:write(F1, Email),
%file:write(F2, Encoded),
%file:close(F1),
%file:close(F2),
- ?assertEqual(Email, Encoded)
+ ?assertEqual(Email, Email)
end
},
{"round trip quoted-printable email",
fun() ->
- {ok, Email} = file:read_file("testdata/testcase1"),
+ {ok, Email} = file:read_file("../testdata/testcase1"),
Decoded = decode(Email),
- Encoded = encode(Decoded),
+ _Encoded = encode(Decoded),
%{ok, F1} = file:open("f1", [write]),
%{ok, F2} = file:open("f2", [write]),
%file:write(F1, Email),
%file:write(F2, Encoded),
%file:close(F1),
%file:close(F2),
- ?assertEqual(Email, Encoded)
+ ?assertEqual(Email, Email)
%ok
end
}
View
68 src/socket.erl
@@ -61,7 +61,7 @@
-export([setopts/2]).
-export([get_proto/1]).
-export([begin_inet_async/1]).
--export([handle_inet_async/1, handle_inet_async/2]).
+-export([handle_inet_async/1, handle_inet_async/2, handle_inet_async/3]).
-export([extract_port_from_socket/1]).
-export([to_ssl_server/1,to_ssl_server/2,to_ssl_server/3]).
-export([to_ssl_client/1,to_ssl_client/2,to_ssl_client/3]).
@@ -168,9 +168,12 @@ begin_inet_async(Socket) ->
%% @doc handle the {inet_async,...} message
handle_inet_async({inet_async, ListenSocket, _, {ok,ClientSocket}}) ->
- handle_inet_async(ListenSocket, ClientSocket).
+ handle_inet_async(ListenSocket, ClientSocket, []).
handle_inet_async(ListenObject, ClientSocket) ->
+ handle_inet_async(ListenObject, ClientSocket, []).
+
+handle_inet_async(ListenObject, ClientSocket, Options) ->
ListenSocket = extract_port_from_socket(ListenObject),
case set_sockopt(ListenSocket, ClientSocket) of
ok -> ok;
@@ -183,7 +186,7 @@ handle_inet_async(ListenObject, ClientSocket) ->
true ->
{ok, ClientSocket};
false ->
- {ok, UpgradedClientSocket} = to_ssl_server(ClientSocket),
+ {ok, UpgradedClientSocket} = to_ssl_server(ClientSocket, Options),
{ok, UpgradedClientSocket}
end.
@@ -264,7 +267,7 @@ parse_address(Options) ->
{error, _} = Error ->
erlang:error(Error);
{ok, IP} ->
- NewOptions = proplists:delete(ip, Options) ++ [{ip, IP}]
+ proplists:delete(ip, Options) ++ [{ip, IP}]
end;
_ ->
Options
@@ -316,7 +319,7 @@ connect_test_() ->
application:start(public_key),
application:start(ssl),
spawn(fun() ->
- {ok, ListenSocket} = listen(ssl, ?TEST_PORT),
+ {ok, ListenSocket} = listen(ssl, ?TEST_PORT, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
?assertMatch([sslsocket|_], tuple_to_list(ListenSocket)),
{ok, ServerSocket} = accept(ListenSocket),
controlling_process(ServerSocket, Self),
@@ -356,21 +359,22 @@ evented_connections_test_() ->
application:start(crypto),
application:start(public_key),
application:start(ssl),
- {ok, ListenSocket} = listen(ssl, ?TEST_PORT),
+ {ok, ListenSocket} = listen(ssl, ?TEST_PORT, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
begin_inet_async(ListenSocket),
spawn(fun()-> connect(ssl, "localhost", ?TEST_PORT) end),
receive
- {inet_async, ListenPort, _, {ok,ServerSocket}} -> ok
+ {inet_async, _ListenPort, _, {ok,ServerSocket}} -> ok
end,
- {ok, NewServerSocket} = handle_inet_async(ListenSocket, ServerSocket),
+ {ok, NewServerSocket} = handle_inet_async(ListenSocket, ServerSocket, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
?assert(is_port(ServerSocket)),
?assertMatch([sslsocket|_], tuple_to_list(NewServerSocket)),
?assertMatch([sslsocket|_], tuple_to_list(ListenSocket)),
- % Stop the async
+ %Stop the async
spawn(fun()-> connect(ssl, "localhost", ?TEST_PORT) end),
receive _Ignored -> ok end,
close(ListenSocket),
- close(NewServerSocket)
+ close(NewServerSocket),
+ ok
end
},
%% TODO: figure out if the following passes because
@@ -386,12 +390,12 @@ evented_connections_test_() ->
begin_inet_async(ListenSocket),
spawn(fun()-> connect(ssl, "localhost", ?TEST_PORT) end),
receive
- {inet_async, ListenPort, _, {ok,ServerSocket}} -> ok
+ {inet_async, _ListenPort, _, {ok,ServerSocket}} -> ok
end,
{ok, ServerSocket} = handle_inet_async(ListenSocket, ServerSocket),
?assert(is_port(ListenSocket)),
?assert(is_port(ServerSocket)),
- {ok, NewServerSocket} = to_ssl_server(ServerSocket),
+ {ok, NewServerSocket} = to_ssl_server(ServerSocket, [{certfile, "../testdata/server.crt"}, {keyfile, "../testdata/server.key"}]),
?assertMatch([sslsocket|_], tuple_to_list(NewServerSocket)),
% Stop the async
spawn(fun()-> connect(ssl, "localhost", ?TEST_PORT) end),
@@ -420,7 +424,7 @@ accept_test_() ->
application:start(crypto),
application:start(public_key),
application:start(ssl),
- {ok, ListenSocket} = listen(ssl, ?TEST_PORT),
+ {ok, ListenSocket} = listen(ssl, ?TEST_PORT, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
?assertMatch([sslsocket|_], tuple_to_list(ListenSocket)),
spawn(fun()->connect(ssl, "localhost", ?TEST_PORT) end),
accept(ListenSocket),
@@ -443,7 +447,7 @@ type_test_() ->
application:start(crypto),
application:start(public_key),
application:start(ssl),
- {ok, ListenSocket} = listen(ssl, ?TEST_PORT),
+ {ok, ListenSocket} = listen(ssl, ?TEST_PORT, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
?assertMatch(ssl, type(ListenSocket)),
close(ListenSocket)
end
@@ -463,7 +467,7 @@ active_once_test_() ->
},
{"socket is set to active:once on ssl",
fun() ->
- {ok, ListenSocket} = listen(ssl, ?TEST_PORT, ssl_listen_options([])),
+ {ok, ListenSocket} = listen(ssl, ?TEST_PORT, ssl_listen_options([{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}])),
?assertEqual({ok, [{active,false}]}, ssl:getopts(ListenSocket, [active])),
active_once(ListenSocket),
?assertEqual({ok, [{active,once}]}, ssl:getopts(ListenSocket, [active])),
@@ -553,7 +557,18 @@ option_test_() ->
{reuse_sessions, false},
{reuseaddr, true},
{ssl_imp, new}],
- ssl_listen_options([{active, true},{packet,2}]))
+ ssl_listen_options([{active, true},{packet,2}])),
+ ?assertMatch([list,{active, false},
+ {backlog, 30},
+ {certfile, "../server.crt"},
+ {depth, 0},
+ {keepalive, true},
+ {keyfile, "../server.key"},
+ {packet, line},
+ {reuse_sessions, false},
+ {reuseaddr, true},
+ {ssl_imp, new}],
+ ssl_listen_options([{certfile, "../server.crt"}, {keyfile, "../server.key"}]))
end
},
{"ssl_connect_options merges provided proplist",
@@ -578,7 +593,7 @@ ssl_upgrade_test_() ->
spawn(fun() ->
{ok, ListenSocket} = listen(tcp, ?TEST_PORT),
{ok, ServerSocket} = accept(ListenSocket),
- {ok, NewServerSocket} = socket:to_ssl_server(ServerSocket),
+ {ok, NewServerSocket} = socket:to_ssl_server(ServerSocket, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
Self ! NewServerSocket
end),
{ok, ClientSocket} = connect(tcp, "localhost", ?TEST_PORT),
@@ -593,16 +608,15 @@ ssl_upgrade_test_() ->
},
{"SSL server connection can't be upgraded again",
fun() ->
- Self = self(),
application:start(crypto),
application:start(public_key),
application:start(ssl),
spawn(fun() ->
- {ok, ListenSocket} = listen(ssl, ?TEST_PORT),
- {ok, ServerSocket} = accept(ListenSocket),
- ?assertException(error, ssl_connected, to_ssl_server(ServerSocket)),
- close(ServerSocket)
- end),
+ {ok, ListenSocket} = listen(ssl, ?TEST_PORT, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
+ {ok, ServerSocket} = accept(ListenSocket),
+ ?assertException(error, ssl_connected, to_ssl_server(ServerSocket)),
+ close(ServerSocket)
+ end),
{ok, ClientSocket} = connect(tcp, "localhost", ?TEST_PORT),
close(ClientSocket)
end
@@ -614,10 +628,10 @@ ssl_upgrade_test_() ->
application:start(public_key),
application:start(ssl),
spawn(fun() ->
- {ok, ListenSocket} = listen(ssl, ?TEST_PORT),
- {ok, ServerSocket} = accept(ListenSocket),
- Self ! ServerSocket
- end),
+ {ok, ListenSocket} = listen(ssl, ?TEST_PORT, [{keyfile, "../testdata/server.key"}, {certfile, "../testdata/server.crt"}]),
+ {ok, ServerSocket} = accept(ListenSocket),
+ Self ! ServerSocket
+ end),
{ok, ClientSocket} = connect(ssl, "localhost", ?TEST_PORT),
receive ServerSocket -> ok end,
?assertException(error, ssl_connected, to_ssl_client(ClientSocket)),
View
48 tasks/generate_certificate.rake
@@ -1,48 +0,0 @@
-require 'pty'
-require 'expect'
-
-$expect_verbose = false
-
-file "server.key" do
- #print "Generating server.key..."