diff --git a/src/test-harness/tests/crypto.pm b/src/test-harness/tests/crypto.pm new file mode 100644 index 0000000..795f078 --- /dev/null +++ b/src/test-harness/tests/crypto.pm @@ -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 < +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; diff --git a/src/test-harness/tests/dbupdate.pm b/src/test-harness/tests/dbupdate.pm index 51746d6..22efe5c 100644 --- a/src/test-harness/tests/dbupdate.pm +++ b/src/test-harness/tests/dbupdate.pm @@ -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; diff --git a/src/test-harness/tests/polupdate.pm b/src/test-harness/tests/polupdate.pm index 1b95b4c..4f701a1 100644 --- a/src/test-harness/tests/polupdate.pm +++ b/src/test-harness/tests/polupdate.pm @@ -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(); diff --git a/src/test-harness/twtools.pm b/src/test-harness/twtools.pm index 2c50a3a..0959290 100644 --- a/src/test-harness/twtools.pm +++ b/src/test-harness/twtools.pm @@ -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); }