--------------------- SMTP Client Test Plan --------------------- -Ian! D. Allen - idallen@idallen.ca I recommend using a shell script test_plan.sh to create an automated test plan; so, you don't have to redo all the tests manually every time you change something in your client. To test SMTP responses, you can "fake" a whole set of responses from an SMTP server by putting the lines you want the fake server to send in a text file and using "nc" as the server: $ nc -v -l localhost 55555 $message Subject: This is a test message Body Line 1. .Line starting with a period. Body Line 3. . Body Line 5. EOF # This is how we actually run a test. # - connect to and flush any existing left-over server (make it exit) # - start a fake server in background, reading from the SMTP response file # - number the output of the server to make it easy to see # - run the client against the server # - possibly pause and ask to run the next test # - kill the server in case it didn't exit # DoTest () { echo " " echo "==============================================================" echo "Test $testno: $*" echo "==============================================================" # Connect to and flush any existing left-over server (make it exit). # nc -w 1 -v localhost $PORT /dev/null 2>&1 # Start our fake SMTP server in the background: # - use cat to make unprintable chars visible and number the output # Make sure the server started (kill -0). # $RUNSERVER <$smtp | cat -v -n & if ! kill -0 $! ; then echo 1>&2 "$0: Unable to start $RUNSERVER" exit 1 fi echo " " # Run our client, with message, against the server. # $RUNTEST <$message echo "*** Client exit status is $?" echo " " # If stdin is a terminal, prompt to continue next test. # (To run tests without prompting, redirect stdin from /dev/null ) # if [ -t 0 ] ; then let next=testno+1 echo 1>&2 "$0: Press RETURN to go to next test (#$next)..." read junk else # Sleep a bit to give the fake server time to exit on its own. sleep 1 fi kill $! 2>/dev/null # kill any left-over background nc server } ########################################################################## # This test is for a plain SMTP session with a few continuation lines. # let testno=testno+1 cat <$smtp 220 test$testno greeting 250-test$testno response to EHLO 250-test$testno option1 250-test$testno option2 250-test$testno option3 250 test$testno optionlast 250 test$testno response to MAIL FROM 250 test$testno response to RCPT TO 354 test$testno response to DATA 250 test$testno response to end of DATA 221 test$testno response to QUIT (closing) EOF DoTest "A few continuation lines" ########################################################################## # This tests a small message length. # let testno=testno+1 cat <$smtp 220 test$testno greeting 250-test$testno response to EHLO 250 SIZE 50 250 test$testno response to MAIL FROM 250 test$testno response to RCPT TO 354 test$testno response to DATA 250 test$testno response to end of DATA 221 test$testno response to QUIT (closing) EOF DoTest "A fixed small message length" ########################################################################## # This tests a refused greeting. # let testno=testno+1 cat <$smtp 554 test$testno refused greeting EOF DoTest "A refused greeting" ########################################################################## # This tests an error refused EHLO. # let testno=testno+1 cat <$smtp 220 test$testno greeting 504 test$testno error refused EHLO EOF DoTest "An error refused EHLO - exit status EX_UNAVAILABLE (69)" ########################################################################## # This tests a temporary refused EHLO. # let testno=testno+1 cat <$smtp 220 test$testno greeting 421 test$testno temporary refused EHLO EOF DoTest "A temporary refused EHLO - exit status EX_TEMPFAIL (75)" ########################################################################## # This tests a line too short. # let testno=testno+1 cat <$smtp xx EOF DoTest "A line too short." ########################################################################## # This tests a time-out. (Make sure the client has small time-outs!) # let testno=testno+1 cat <$smtp 220 test$testno greeting EOF DoTest "A time-out" ########################################################################## # more tests here ...