Index: t/root_spamd_tell_x.t =================================================================== --- t/root_spamd_tell_x.t (revision 0) +++ t/root_spamd_tell_x.t (revision 0) @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +use SATest; sa_t_init("root_spamd_tell_x"); +use Test; + +use constant TEST_ENABLED => conf_bool('run_root_tests'); +use constant IS_ROOT => eval { ($> == 0); }; +use constant RUN_TEST => (TEST_ENABLED && IS_ROOT); + +BEGIN { plan tests => (RUN_TESTS ? 6 : 0) }; +exit unless RUN_TESTS; + +# --------------------------------------------------------------------------- + +%patterns = ( +q{ Message successfully } => 'learned', +); + +# run spamc as unpriv uid +$spamc = "sudo -u nobody $spamc"; + +# remove these first +unlink('log/user_state/bayes_seen'); +unlink('log/user_state/bayes_toks'); + +# ensure it is writable by all +use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state"; + +ok(start_spamd("-L --allow-tell --create-prefs -x")); + +ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb)); +ok_all_patterns(); + +ok(stop_spamd()); + +# ensure these are not owned by root +ok check_owner('log/user_state/bayes_seen'); +ok check_owner('log/user_state/bayes_toks'); + +sub check_owner { + my $f = shift; + my @stat = stat $f; + + print "stat($f) = ".join(', ', @stat)."\n"; + + if (!defined $stat[1]) { + warn "no stat for $f"; + return 0; + } + elsif ($stat[4] == 0) { + warn "stat for $f: owner is root"; + return 0; + } + else { + return 1; + } +} Property changes on: t/root_spamd_tell_x.t ___________________________________________________________________ Name: svn:executable + * Index: t/root_spamd_tell_paranoid.t =================================================================== --- t/root_spamd_tell_paranoid.t (revision 0) +++ t/root_spamd_tell_paranoid.t (revision 0) @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +use SATest; sa_t_init("root_spamd_tell_paranoid"); +use Test; + +use constant TEST_ENABLED => conf_bool('run_root_tests'); +use constant IS_ROOT => eval { ($> == 0); }; +use constant RUN_TEST => (TEST_ENABLED && IS_ROOT); + +BEGIN { plan tests => (RUN_TESTS ? 6 : 0) }; +exit unless RUN_TESTS; + +# --------------------------------------------------------------------------- + +%patterns = ( +q{ Message successfully } => 'learned', +); + +# run spamc as unpriv uid +$spamc = "sudo -u nobody $spamc"; + +# remove these first +unlink('log/user_state/bayes_seen'); +unlink('log/user_state/bayes_toks'); + +# ensure it is writable by all +use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state"; + +ok(start_spamd("-L --allow-tell --paranoid")); + +ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb)); +ok_all_patterns(); + +ok(stop_spamd()); + +# ensure these are not owned by root +ok check_owner('log/user_state/bayes_seen'); +ok check_owner('log/user_state/bayes_toks'); + +sub check_owner { + my $f = shift; + my @stat = stat $f; + + print "stat($f) = ".join(', ', @stat)."\n"; + + if (!defined $stat[1]) { + warn "no stat for $f"; + return 0; + } + elsif ($stat[4] == 0) { + warn "stat for $f: owner is root"; + return 0; + } + else { + return 1; + } +} Property changes on: t/root_spamd_tell_paranoid.t ___________________________________________________________________ Name: svn:executable + * Index: t/root_spamd_x.t =================================================================== --- t/root_spamd_x.t (revision 0) +++ t/root_spamd_x.t (revision 0) @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +use SATest; sa_t_init("root_spamd_x"); +use Test; + +use constant TEST_ENABLED => conf_bool('run_root_tests'); +use constant IS_ROOT => eval { ($> == 0); }; +use constant RUN_TEST => (TEST_ENABLED && IS_ROOT); + +BEGIN { plan tests => (RUN_TESTS ? 14 : 0) }; +exit unless RUN_TESTS; + +# --------------------------------------------------------------------------- + +%patterns = ( + +q{ Return-Path: sb55sb55@yahoo.com}, 'firstline', +q{ Subject: There yours for FREE!}, 'subj', +q{ X-Spam-Status: Yes, score=}, 'status', +q{ X-Spam-Flag: YES}, 'flag', +q{ X-Spam-Level: **********}, 'stars', +q{ TEST_ENDSNUMS}, 'endsinnums', +q{ TEST_NOREALNAME}, 'noreal', +q{ This must be the very last line}, 'lastline', + +); + +# run spamc as unpriv uid +$spamc = "sudo -u nobody $spamc"; + +ok(start_spamd("-L --create-prefs -x")); + +ok(spamcrun("< data/spam/001", \&patterns_run_cb)); +ok_all_patterns(); + +%patterns = ( +q{ X-Spam-Status: Yes, score=}, 'status', +q{ X-Spam-Flag: YES}, 'flag', + ); + + +ok (spamcrun("< data/spam/018", \&patterns_run_cb)); +ok_all_patterns(); + +ok(stop_spamd()); Property changes on: t/root_spamd_x.t ___________________________________________________________________ Name: svn:executable + * Index: t/root_spamd_tell_x_paranoid.t =================================================================== --- t/root_spamd_tell_x_paranoid.t (revision 0) +++ t/root_spamd_tell_x_paranoid.t (revision 0) @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +use SATest; sa_t_init("root_spamd_tell_x_paranoid"); +use Test; + +use constant TEST_ENABLED => conf_bool('run_root_tests'); +use constant IS_ROOT => eval { ($> == 0); }; +use constant RUN_TEST => (TEST_ENABLED && IS_ROOT); + +BEGIN { plan tests => (RUN_TESTS ? 6 : 0) }; +exit unless RUN_TESTS; + +# --------------------------------------------------------------------------- + +%patterns = ( +q{ Message successfully } => 'learned', +); + +# run spamc as unpriv uid +$spamc = "sudo -u nobody $spamc"; + +# remove these first +unlink('log/user_state/bayes_seen'); +unlink('log/user_state/bayes_toks'); + +# ensure it is writable by all +use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state"; + +ok(start_spamd("-L --allow-tell --create-prefs -x --paranoid")); + +ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb)); +ok_all_patterns(); + +ok(stop_spamd()); + +# ensure these are not owned by root +ok check_owner('log/user_state/bayes_seen'); +ok check_owner('log/user_state/bayes_toks'); + +sub check_owner { + my $f = shift; + my @stat = stat $f; + + print "stat($f) = ".join(', ', @stat)."\n"; + + if (!defined $stat[1]) { + warn "no stat for $f"; + return 0; + } + elsif ($stat[4] == 0) { + warn "stat for $f: owner is root"; + return 0; + } + else { + return 1; + } +} Property changes on: t/root_spamd_tell_x_paranoid.t ___________________________________________________________________ Name: svn:executable + * Index: t/config.dist =================================================================== --- t/config.dist (revision 543469) +++ t/config.dist (working copy) @@ -57,3 +57,9 @@ # depending on changes in the third-party modules we import. run_saw_ampersand_test=n +# --------------------------------------------------------------------------- + +# The "root_*.t" tests require root privileges, and may create files in +# the filesystem as part of the test. Disabled by default. +run_root_tests=n + Index: t/root_spamd_tell.t =================================================================== --- t/root_spamd_tell.t (revision 0) +++ t/root_spamd_tell.t (revision 0) @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +use SATest; sa_t_init("root_spamd_tell"); +use Test; + +use constant TEST_ENABLED => conf_bool('run_root_tests'); +use constant IS_ROOT => eval { ($> == 0); }; +use constant RUN_TEST => (TEST_ENABLED && IS_ROOT); + +BEGIN { plan tests => (RUN_TESTS ? 6 : 0) }; +exit unless RUN_TESTS; + +# --------------------------------------------------------------------------- + +%patterns = ( +q{ Message successfully } => 'learned', +); + +# run spamc as unpriv uid +$spamc = "sudo -u nobody $spamc"; + +# remove these first +unlink('log/user_state/bayes_seen'); +unlink('log/user_state/bayes_toks'); + +# ensure it is writable by all +use File::Path; mkpath("log/user_state"); chmod 01777, "log/user_state"; + +ok(start_spamd("-L --allow-tell")); + +ok(spamcrun("-lx -L ham < data/spam/001", \&patterns_run_cb)); +ok_all_patterns(); + +ok(stop_spamd()); + +# ensure these are not owned by root +ok check_owner('log/user_state/bayes_seen'); +ok check_owner('log/user_state/bayes_toks'); + +sub check_owner { + my $f = shift; + my @stat = stat $f; + + print "stat($f) = ".join(', ', @stat)."\n"; + + if (!defined $stat[1]) { + warn "no stat for $f"; + return 0; + } + elsif ($stat[4] == 0) { + warn "stat for $f: owner is root"; + return 0; + } + else { + return 1; + } +} Property changes on: t/root_spamd_tell.t ___________________________________________________________________ Name: svn:executable + * Index: t/root_spamd_x_paranoid.t =================================================================== --- t/root_spamd_x_paranoid.t (revision 0) +++ t/root_spamd_x_paranoid.t (revision 0) @@ -0,0 +1,46 @@ +#!/usr/bin/perl + +use lib '.'; use lib 't'; +use SATest; sa_t_init("root_spamd_x_paranoid"); +use Test; + +use constant TEST_ENABLED => conf_bool('run_root_tests'); +use constant IS_ROOT => eval { ($> == 0); }; +use constant RUN_TEST => (TEST_ENABLED && IS_ROOT); + +BEGIN { plan tests => (RUN_TESTS ? 14 : 0) }; +exit unless RUN_TESTS; + +# --------------------------------------------------------------------------- + +%patterns = ( + +q{ Return-Path: sb55sb55@yahoo.com}, 'firstline', +q{ Subject: There yours for FREE!}, 'subj', +q{ X-Spam-Status: Yes, score=}, 'status', +q{ X-Spam-Flag: YES}, 'flag', +q{ X-Spam-Level: **********}, 'stars', +q{ TEST_ENDSNUMS}, 'endsinnums', +q{ TEST_NOREALNAME}, 'noreal', +q{ This must be the very last line}, 'lastline', + +); + +# run spamc as unpriv uid +$spamc = "sudo -u nobody $spamc"; + +ok(start_spamd("-L --create-prefs -x --paranoid")); + +ok(spamcrun("< data/spam/001", \&patterns_run_cb)); +ok_all_patterns(); + +%patterns = ( +q{ X-Spam-Status: Yes, score=}, 'status', +q{ X-Spam-Flag: YES}, 'flag', + ); + + +ok (spamcrun("< data/spam/018", \&patterns_run_cb)); +ok_all_patterns(); + +ok(stop_spamd()); Property changes on: t/root_spamd_x_paranoid.t ___________________________________________________________________ Name: svn:executable + * Index: t/root_spamd.t =================================================================== --- t/root_spamd.t (revision 0) +++ t/root_spamd.t (revision 0) @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# run with: sudo prove -v t/root_spamd* + +use lib '.'; use lib 't'; +use SATest; sa_t_init("root_spamd"); +use Test; + +use constant TEST_ENABLED => conf_bool('run_root_tests'); +use constant IS_ROOT => eval { ($> == 0); }; +use constant RUN_TEST => (TEST_ENABLED && IS_ROOT); + +BEGIN { plan tests => (RUN_TESTS ? 14 : 0) }; +exit unless RUN_TESTS; + +# --------------------------------------------------------------------------- + +%patterns = ( + +q{ Return-Path: sb55sb55@yahoo.com}, 'firstline', +q{ Subject: There yours for FREE!}, 'subj', +q{ X-Spam-Status: Yes, score=}, 'status', +q{ X-Spam-Flag: YES}, 'flag', +q{ X-Spam-Level: **********}, 'stars', +q{ TEST_ENDSNUMS}, 'endsinnums', +q{ TEST_NOREALNAME}, 'noreal', +q{ This must be the very last line}, 'lastline', + +); + +# run spamc as unpriv uid +$spamc = "sudo -u nobody $spamc"; + +ok(start_spamd("-L")); + +ok(spamcrun("< data/spam/001", \&patterns_run_cb)); +ok_all_patterns(); + +%patterns = ( +q{ X-Spam-Status: Yes, score=}, 'status', +q{ X-Spam-Flag: YES}, 'flag', + ); + + +ok (spamcrun("< data/spam/018", \&patterns_run_cb)); +ok_all_patterns(); + +ok(stop_spamd()); Property changes on: t/root_spamd.t ___________________________________________________________________ Name: svn:executable + *