Add a test-harness that does a happy path thru the twadmin file crypto modes.

This commit is contained in:
Brian Cox 2017-06-25 14:48:56 -07:00
parent 60b24b0201
commit 73a8f0e59b
4 changed files with 155 additions and 2 deletions

View File

@ -0,0 +1,108 @@
use twtools;
package crypto;
######################################################################
# One time module initialization goes in here...
#
BEGIN {
$description = "file crypto test";
}
######################################################################
# PolicyFileString -- return the policy text as a string
#
sub PolicyFileString
{
return <<POLICY_END;
# Policy file generated by file crypto test
/etc -> +M; #read only plus MD5
POLICY_END
}
######################################################################
#
# Initialize, get ready to run this test...
#
sub initialize() {
my $twstr = PolicyFileString();
twtools::GeneratePolicyFile($twstr);
}
######################################################################
#
# Run the test.
#
sub run() {
my $twpassed = 1;
my $testpath = "$twtools::twrootdir/$twtools::twpolfileloc";
twtools::logStatus("*** Beginning $description\n");
printf("%-30s", "-- $description");
if ( ! twtools::ExamineEncryption("$testpath"))
{
twtools::logStatus("first examine encryption failed\n");
$twpassed = 0;
}
twtools::logStatus("testing file crypto removal...\n");
if ( !twtools::RemoveEncryption("$testpath"))
{
twtools::logStatus("remove encryption failed\n");
$twpassed = 0;
}
if ( ! twtools::ExamineEncryption("$testpath"))
{
twtools::logStatus("second examine encryption failed\n");
$twpassed = 0;
}
twtools::logStatus("testing file crypto...\n");
if ( ! twtools::AddEncryption("$testpath"))
{
twtools::logStatus("add encryption failed\n");
$twpassed = 0;
}
if ( ! twtools::ExamineEncryption("$testpath"))
{
twtools::logStatus("third examine encryption failed\n");
$twpassed = 0;
}
#########################################################
#
# See if the tests all succeeded...
#
if ($twpassed) {
++$twtools::twpassedtests;
print "PASSED\n";
return 1;
}
else {
++$twtools::twfailedtests;
print "*FAILED*\n";
return 0;
}
}
######################################################################
# One time module cleanup goes in here...
#
END {
}
1;

View File

@ -142,6 +142,7 @@ sub PrepareForTest
#
sub RunBasicTest
{
twtools::logStatus("*** Beginning dbupdate.basic test\n");
printf("%-30s", "-- dbupdate.basic test");
PrepareForTest();
@ -191,6 +192,7 @@ sub RunBasicTest
#
sub RunSecureModeTest
{
twtools::logStatus("*** Beginning dbupdate.secure-mode test\n");
printf("%-30s", "-- dbupdate.secure-mode test");
++$twtools::twskippedtests;

View File

@ -165,6 +165,7 @@ sub PrepareForTest
#
sub RunBasicTest
{
twtools::logStatus("*** Beginning polupdate.basic test\n");
printf("%-30s", "-- polupdate.basic test");
PrepareForTest();
@ -198,6 +199,7 @@ sub RunBasicTest
#
sub RunSecureModeTest
{
twtools::logStatus("*** Beginning polupdate.secure-mode test\n");
printf("%-30s", "-- polupdate.secure-mode test");
PrepareForTest();

View File

@ -169,6 +169,47 @@ sub SignConfigFile {
}
######################################################################
# Examine encryption
#
sub ExamineEncryption {
my ($filename) = @_;
logStatus(`$twrootdir/bin/twadmin -m e -c $twrootdir/$twcfgloc $filename`);
return ($? == 0);
}
######################################################################
# Add encryption
#
sub AddEncryption {
my ($filename) = @_;
logStatus "addding crypt to file...\n";
logStatus(`$twrootdir/bin/twadmin -m E -c $twrootdir/$twcfgloc -P $twlocalpass -Q $twsitepass $filename`);
return ($? == 0);
}
######################################################################
# Remove encryption
#
sub RemoveEncryption {
my ($filename) = @_;
logStatus "removing crypto from file...\n";
logStatus(`$twrootdir/bin/twadmin -m R -c $twrootdir/$twcfgloc -P $twlocalpass -Q $twsitepass $filename`);
return ($? == 0);
}
######################################################################
# Write policy text to disk... Note the contents
# of the policy file are passed in as '$twstr'.
@ -197,7 +238,7 @@ sub GeneratePolicyFile {
logStatus(`$twrootdir/bin/twadmin -m P -c $twrootdir/$twcfgloc -Q $twsitepass -p $twrootdir/$twpolfileloc $twrootdir/$twpolicyloc`);
return ($? == 0);
return ($? == 0);
}
@ -211,7 +252,7 @@ sub InitializeDatabase {
print "initializing database for '$twmsg' test...\n" if $verbose;
logStatus(`$twrootdir/bin/tripwire -m i -P $twsitepass -p $twrootdir/$twpolfileloc -c $twrootdir/$twcfgloc 2>&1`);
return ($? == 0);
return ($? == 0);
}