diff --git a/src/test-harness/tests/email.pm b/src/test-harness/tests/email.pm new file mode 100644 index 0000000..f03eb09 --- /dev/null +++ b/src/test-harness/tests/email.pm @@ -0,0 +1,85 @@ + +use twtools; + +package email; + +###################################################################### +# One time module initialization goes in here... +# +BEGIN { + $description = "email test"; +} + + +###################################################################### +# +# Initialize, get ready to run this test... +# +sub initialize() { +} + + +###################################################################### +# +# Run the test. +# +sub run() { + + my $twpassed = 1; + + twtools::logStatus("*** Beginning $description\n"); + printf("%-30s", "-- $description"); + + my($sending, undef, undef, $mailfrom, $mailto, $subject, undef, undef, undef, $body) = twtools::RunEmailTest(); + + # Verify that various lines in the test email output look right, + # including the RFC 2822-required CRLFs that should be in everything + # except $sending, which isn't part of the actual email. + # + if ( !($sending =~ "Sending a test message to: elvis\@mars")) { + twtools::logStatus("Unexpected sending line: $sending\n"); + $twpassed = 0; + } + + if ( !($mailfrom =~ "taz\@cat")) { + twtools::logStatus("Unexpected From: field: $mailfrom\n"); + $twpassed = 0; + } + + if ( !($mailto =~ "To: elvis\@mars\r")) { + twtools::logStatus("Unexpected To: field: $mailto\n"); + $twpassed = 0; + } + + if ( !($subject =~ "Subject: Test email message from Tripwire\r")) { + twtools::logStatus("Unexpected Subject field: $subject\n"); + $twpassed = 0; + } + + if ( !($body =~ "If you receive this message, email notification from tripwire is working correctly.\r")) { + twtools::logStatus("Unexpected message body: $body\n"); + $twpassed = 0; + } + + ######################################################### + # + # See if the tests all succeeded... + # + if ($twpassed) { + print "PASSED\n"; + ++$twtools::twpassedtests; + } + else { + ++$twtools::twfailedtests; + print "*FAILED*\n"; + } +} + + +###################################################################### +# One time module cleanup goes in here... +# +END { +} + +1; diff --git a/src/test-harness/twtools.pm b/src/test-harness/twtools.pm index 1209d39..8a904df 100644 --- a/src/test-harness/twtools.pm +++ b/src/test-harness/twtools.pm @@ -53,8 +53,8 @@ BEGIN { REPORTLEVEL => '3', MAILMETHOD => 'SENDMAIL', SYSLOGREPORTING => 'false', - MAILPROGRAM => '/usr/lib/sendmail -oi -t' - + MAILPROGRAM => 'cat', + MAILFROMADDRESS => 'taz@cat' ); } @@ -235,6 +235,19 @@ sub RunReport(%) { } +###################################################################### +# Run an email test (configured with mailmethod=sendmail) & capture output +# +sub RunEmailTest { + + my (@out) = `$twrootdir/bin/tripwire --test -c $twrootdir/tw.cfg --email elvis\@mars`; + + logStatus(@out); + + return @out; +} + + ###################################################################### # Run tripwire to do an integrity check on # the test data