diff --git a/src/parser/testfiles.bad/arrow.txt b/src/parser/testfiles.bad/arrow.txt new file mode 100644 index 0000000..e4400a5 --- /dev/null +++ b/src/parser/testfiles.bad/arrow.txt @@ -0,0 +1 @@ +-> diff --git a/src/parser/testfiles.bad/asdf.txt b/src/parser/testfiles.bad/asdf.txt new file mode 100644 index 0000000..e08928b --- /dev/null +++ b/src/parser/testfiles.bad/asdf.txt @@ -0,0 +1,4 @@ +(asdf=fjfj) +{ +/foo -> $(IgnoreNone); +} diff --git a/src/parser/testfiles.bad/atat.txt b/src/parser/testfiles.bad/atat.txt new file mode 100644 index 0000000..0282815 --- /dev/null +++ b/src/parser/testfiles.bad/atat.txt @@ -0,0 +1 @@ +@@ diff --git a/src/parser/testfiles.bad/bad-directive.txt b/src/parser/testfiles.bad/bad-directive.txt new file mode 100644 index 0000000..87e2747 --- /dev/null +++ b/src/parser/testfiles.bad/bad-directive.txt @@ -0,0 +1 @@ +@@unknown fjfjfj diff --git a/src/parser/testfiles.bad/bad-ifhost.txt b/src/parser/testfiles.bad/bad-ifhost.txt new file mode 100644 index 0000000..6672764 --- /dev/null +++ b/src/parser/testfiles.bad/bad-ifhost.txt @@ -0,0 +1 @@ +@@ifhost diff --git a/src/parser/testfiles.bad/error.txt b/src/parser/testfiles.bad/error.txt new file mode 100644 index 0000000..179b4a5 --- /dev/null +++ b/src/parser/testfiles.bad/error.txt @@ -0,0 +1 @@ +@@error This should fail diff --git a/src/parser/testfiles.bad/global-foo.txt b/src/parser/testfiles.bad/global-foo.txt new file mode 100644 index 0000000..81cfcd6 --- /dev/null +++ b/src/parser/testfiles.bad/global-foo.txt @@ -0,0 +1,2 @@ +@@section GLOBAL +/foo -> $(IgnoreNone); diff --git a/src/parser/testfiles.bad/ignore-some.txt b/src/parser/testfiles.bad/ignore-some.txt new file mode 100644 index 0000000..70f3d29 --- /dev/null +++ b/src/parser/testfiles.bad/ignore-some.txt @@ -0,0 +1 @@ +/foo -> $(IgnoreSome); diff --git a/src/parser/testfiles.bad/incomplete-1.txt b/src/parser/testfiles.bad/incomplete-1.txt new file mode 100644 index 0000000..0661686 --- /dev/null +++ b/src/parser/testfiles.bad/incomplete-1.txt @@ -0,0 +1 @@ +/foo diff --git a/src/parser/testfiles.bad/incomplete-2.txt b/src/parser/testfiles.bad/incomplete-2.txt new file mode 100644 index 0000000..cdceccf --- /dev/null +++ b/src/parser/testfiles.bad/incomplete-2.txt @@ -0,0 +1 @@ +/foo -> diff --git a/src/parser/testfiles.bad/incomplete-3.txt b/src/parser/testfiles.bad/incomplete-3.txt new file mode 100644 index 0000000..5b7d008 --- /dev/null +++ b/src/parser/testfiles.bad/incomplete-3.txt @@ -0,0 +1 @@ +/foo -> $(IgnoreNone) diff --git a/src/parser/testfiles.bad/incomplete-4.txt b/src/parser/testfiles.bad/incomplete-4.txt new file mode 100644 index 0000000..7073e76 --- /dev/null +++ b/src/parser/testfiles.bad/incomplete-4.txt @@ -0,0 +1,2 @@ +{ +/foo -> $(IgnoreNone); diff --git a/src/parser/testfiles.bad/incomplete-5.txt b/src/parser/testfiles.bad/incomplete-5.txt new file mode 100644 index 0000000..533ee7f --- /dev/null +++ b/src/parser/testfiles.bad/incomplete-5.txt @@ -0,0 +1,2 @@ +/foo -> $(IgnoreNone); +} diff --git a/src/parser/testfiles.bad/incomplete-6.txt b/src/parser/testfiles.bad/incomplete-6.txt new file mode 100644 index 0000000..ff668ee --- /dev/null +++ b/src/parser/testfiles.bad/incomplete-6.txt @@ -0,0 +1,4 @@ +(emailto="foo@bar +{ +/foo -> $(IgnoreNone); +} diff --git a/src/parser/testfiles.bad/incomplete-7.txt b/src/parser/testfiles.bad/incomplete-7.txt new file mode 100644 index 0000000..82df1f7 --- /dev/null +++ b/src/parser/testfiles.bad/incomplete-7.txt @@ -0,0 +1,4 @@ +(emailto="foo@bar" +{ +/foo -> $(IgnoreNone); +} diff --git a/src/parser/testfiles.bad/relpath.txt b/src/parser/testfiles.bad/relpath.txt new file mode 100644 index 0000000..ac86154 --- /dev/null +++ b/src/parser/testfiles.bad/relpath.txt @@ -0,0 +1 @@ +foo -> $(IgnoreNone); diff --git a/src/parser/testfiles/basic.txt b/src/parser/testfiles/basic.txt new file mode 100644 index 0000000..86c70fe --- /dev/null +++ b/src/parser/testfiles/basic.txt @@ -0,0 +1,3 @@ +/foo -> +S; +/bar -> $(IgnoreNone); +!/baz; diff --git a/src/parser/testfiles.bad/empty.txt b/src/parser/testfiles/empty.txt similarity index 100% rename from src/parser/testfiles.bad/empty.txt rename to src/parser/testfiles/empty.txt diff --git a/src/parser/testfiles/ifhost.txt b/src/parser/testfiles/ifhost.txt new file mode 100644 index 0000000..4117d1c --- /dev/null +++ b/src/parser/testfiles/ifhost.txt @@ -0,0 +1,6 @@ +@@ifhost localhost + @@print Hello World + /foo -> $(IgnoreNone); +@@else + @@error Failed +@@endif diff --git a/src/parser/testfiles/variable.txt b/src/parser/testfiles/variable.txt new file mode 100644 index 0000000..f651b03 --- /dev/null +++ b/src/parser/testfiles/variable.txt @@ -0,0 +1,7 @@ +@@section GLOBAL +FOO =/foo ; +BAR = +pinug ; + +@@section FS +$(FOO) -> $(BAR); + diff --git a/src/test-harness/tests/createpolicy.pm b/src/test-harness/tests/createpolicy.pm index a67632d..ecf63d5 100644 --- a/src/test-harness/tests/createpolicy.pm +++ b/src/test-harness/tests/createpolicy.pm @@ -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 < +S; -/bar -> \$(IgnoreNone); -!/baz; - -POLICY_END -} - -sub variable_policy -{ - return < \$(BAR); - -POLICY_END -} - -sub host_conditional_policy -{ - return < \$(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; } diff --git a/src/test-harness/tests/dbupdate.pm b/src/test-harness/tests/dbupdate.pm index 22efe5c..e536b4a 100644 --- a/src/test-harness/tests/dbupdate.pm +++ b/src/test-harness/tests/dbupdate.pm @@ -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(); diff --git a/src/test-harness/twtools.pm b/src/test-harness/twtools.pm index b04c633..8950e06 100644 --- a/src/test-harness/twtools.pm +++ b/src/test-harness/twtools.pm @@ -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); }