Add an email reporting test, which runs tripwire --test mode & verifies the required mail header fields look right. This test only uses the sendmail (pipe) mailmethod, since I'm not sure how to automate SMTP testing in our Perl framework.
This commit is contained in:
parent
cdfb2096c5
commit
b1f0ed4b71
|
@ -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;
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue