Add more bad policy test cases; split good & bad policies into separate tests
This commit is contained in:
parent
b4e530b40f
commit
dc943880de
|
@ -0,0 +1 @@
|
|||
->
|
|
@ -0,0 +1,4 @@
|
|||
(asdf=fjfj)
|
||||
{
|
||||
/foo -> $(IgnoreNone);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
@@
|
|
@ -0,0 +1 @@
|
|||
@@unknown fjfjfj
|
|
@ -0,0 +1 @@
|
|||
@@ifhost
|
|
@ -0,0 +1 @@
|
|||
@@error This should fail
|
|
@ -0,0 +1,2 @@
|
|||
@@section GLOBAL
|
||||
/foo -> $(IgnoreNone);
|
|
@ -0,0 +1 @@
|
|||
/foo -> $(IgnoreSome);
|
|
@ -0,0 +1 @@
|
|||
/foo
|
|
@ -0,0 +1 @@
|
|||
/foo ->
|
|
@ -0,0 +1 @@
|
|||
/foo -> $(IgnoreNone)
|
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
/foo -> $(IgnoreNone);
|
|
@ -0,0 +1,2 @@
|
|||
/foo -> $(IgnoreNone);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
(emailto="foo@bar
|
||||
{
|
||||
/foo -> $(IgnoreNone);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
(emailto="foo@bar"
|
||||
{
|
||||
/foo -> $(IgnoreNone);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
foo -> $(IgnoreNone);
|
|
@ -0,0 +1,3 @@
|
|||
/foo -> +S;
|
||||
/bar -> $(IgnoreNone);
|
||||
!/baz;
|
|
@ -0,0 +1,6 @@
|
|||
@@ifhost localhost
|
||||
@@print Hello World
|
||||
/foo -> $(IgnoreNone);
|
||||
@@else
|
||||
@@error Failed
|
||||
@@endif
|
|
@ -0,0 +1,7 @@
|
|||
@@section GLOBAL
|
||||
FOO =/foo ;
|
||||
BAR = +pinug ;
|
||||
|
||||
@@section FS
|
||||
$(FOO) -> $(BAR);
|
||||
|
|
@ -12,53 +12,17 @@ BEGIN
|
|||
$description = "policy creation test";
|
||||
$testpolicydir = "$twtools::twrootdir/../../parser/testfiles";
|
||||
$badpolicydir = "$twtools::twrootdir/../../parser/testfiles.bad";
|
||||
$twpassed = 1;
|
||||
}
|
||||
|
||||
|
||||
######################################################################
|
||||
# various policies
|
||||
# Try all policy files in specified directory, & verify each returns expected value
|
||||
#
|
||||
sub basic_policy
|
||||
{
|
||||
return <<POLICY_END;
|
||||
|
||||
/foo -> +S;
|
||||
/bar -> \$(IgnoreNone);
|
||||
!/baz;
|
||||
|
||||
POLICY_END
|
||||
}
|
||||
|
||||
sub variable_policy
|
||||
{
|
||||
return <<POLICY_END;
|
||||
\@\@section GLOBAL
|
||||
FOO = /foo ;
|
||||
BAR = +pinug ;
|
||||
|
||||
\@\@section FS
|
||||
\$(FOO) -> \$(BAR);
|
||||
|
||||
POLICY_END
|
||||
}
|
||||
|
||||
sub host_conditional_policy
|
||||
{
|
||||
return <<POLICY_END;
|
||||
\@\@ifhost localhost
|
||||
\@\@print Hello World
|
||||
/foo -> \$(IgnoreNone);
|
||||
\@\@else
|
||||
\@\@error failed
|
||||
\@\@endif
|
||||
|
||||
POLICY_END
|
||||
}
|
||||
|
||||
|
||||
sub test_policy_dir
|
||||
{
|
||||
my ($policydir, $expected) = @_;
|
||||
my $twpassed = 1;
|
||||
# my $twpassed = 1;
|
||||
|
||||
opendir my $dir, $policydir or return 0;
|
||||
my @files = readdir $dir;
|
||||
|
@ -74,69 +38,63 @@ sub test_policy_dir
|
|||
|
||||
twtools::CreatePolicy({policy-text => "$policydir/$current_file"});
|
||||
if ( $? != $expected ) {
|
||||
twtools::logStatus ("create-polfile with $policydir/$current_file failed, error = $?\n");
|
||||
twtools::logStatus ("*** create-polfile with $policydir/$current_file failed, error = $?\n");
|
||||
$twpassed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
twtools::logStatus("Done with policy dir $policydir, result = $twpassed\n");
|
||||
return $twpassed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
######################################################################
|
||||
#
|
||||
# Run the test.
|
||||
#
|
||||
sub run
|
||||
{
|
||||
my $twpassed = 1;
|
||||
my $out = 1;
|
||||
|
||||
|
||||
# First try a bunch of policies that are supposed to succeed
|
||||
#
|
||||
twtools::logStatus("*** Beginning policy creation test\n");
|
||||
printf("%-30s", "-- $description");
|
||||
|
||||
twtools::GeneratePolicyFile( basic_policy() );
|
||||
if ( $? != 0 ) {
|
||||
twtools::logStatus("basic create-polfile failed, error = $?\n");
|
||||
$twpassed = 0;
|
||||
}
|
||||
|
||||
twtools::GeneratePolicyFile( variable_policy() );
|
||||
if ( $? != 0 ) {
|
||||
twtools::logStatus("create-polfile with variables failed, error = $?\n");
|
||||
$twpassed = 0;
|
||||
}
|
||||
|
||||
twtools::GeneratePolicyFile( host_conditional_policy() );
|
||||
if ( $? != 0 ) {
|
||||
twtools::logStatus("create-polfile with ifhost conditional failed, error = $?\n");
|
||||
$twpassed = 0;
|
||||
}
|
||||
printf("%-30s", "-- policy creation test");
|
||||
|
||||
test_policy_dir( "$testpolicydir", 0 );
|
||||
if ( $? != 0 ) {
|
||||
$twpassed = 0;
|
||||
}
|
||||
|
||||
test_policy_dir( "$badpolicydir", 1 );
|
||||
if ( $? != 0 ) {
|
||||
$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;
|
||||
$out = 0;
|
||||
}
|
||||
|
||||
|
||||
# Now try some bad policies
|
||||
#
|
||||
twtools::logStatus("*** Beginning bad policy rejection test\n");
|
||||
printf("%-30s", "-- bad policy rejection test");
|
||||
|
||||
$twpassed = 1;
|
||||
++$twtools::twtotaltests;
|
||||
|
||||
test_policy_dir( "$badpolicydir", 256 );
|
||||
if ($twpassed) {
|
||||
++$twtools::twpassedtests;
|
||||
print "PASSED\n";
|
||||
}
|
||||
else {
|
||||
++$twtools::twfailedtests;
|
||||
print "*FAILED*\n";
|
||||
$out = 0;
|
||||
}
|
||||
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ sub PrepareForTest
|
|||
#
|
||||
sub RunBasicTest
|
||||
{
|
||||
twtools::logStatus("*** Beginning dbupdate.basic test\n");
|
||||
twtools::logStatus("*** Beginning dbupdate.basic test\n");
|
||||
printf("%-30s", "-- dbupdate.basic test");
|
||||
|
||||
PrepareForTest();
|
||||
|
|
|
@ -273,7 +273,7 @@ sub GeneratePolicyFile {
|
|||
|
||||
print "generating policy file...\n" if $verbose;
|
||||
|
||||
logStatus(`$twrootdir/bin/twadmin -m P -c $twrootdir/$twcfgloc -Q $twsitepass -p $twrootdir/$twpolfileloc $twrootdir/$twpolicyloc`);
|
||||
logStatus(`$twrootdir/bin/twadmin -m P -c $twrootdir/$twcfgloc -Q $twsitepass -p $twrootdir/$twpolfileloc $twrootdir/$twpolicyloc 2>&1`);
|
||||
|
||||
return ($? == 0);
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ sub CreatePolicy {
|
|||
|
||||
print "generating policy file...\n" if $verbose;
|
||||
|
||||
logStatus(`$twrootdir/bin/twadmin -m P -c $twrootdir/$twcfgloc -Q $twsitepass -p $twrootdir/$twpolfileloc $params{policy-text}`);
|
||||
logStatus(`$twrootdir/bin/twadmin -m P -c $twrootdir/$twcfgloc -Q $twsitepass -p $twrootdir/$twpolfileloc $params{policy-text} 2>&1`);
|
||||
|
||||
return ($? == 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue