You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by si...@apache.org on 2007/07/23 11:40:36 UTC

svn commit: r558675 - in /spamassassin/branches/3.1/t: SATest.pm spamd_allow_user_rules.t spamd_plugin.t

Author: sidney
Date: Mon Jul 23 02:40:35 2007
New Revision: 558675

URL: http://svn.apache.org/viewvc?view=rev&rev=558675
Log:
bug 5510: fix test suite to support running as root, now that spamd will automatically fall back to 'nobody' privs

Modified:
    spamassassin/branches/3.1/t/SATest.pm
    spamassassin/branches/3.1/t/spamd_allow_user_rules.t
    spamassassin/branches/3.1/t/spamd_plugin.t

Modified: spamassassin/branches/3.1/t/SATest.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/t/SATest.pm?view=diff&rev=558675&r1=558674&r2=558675
==============================================================================
--- spamassassin/branches/3.1/t/SATest.pm (original)
+++ spamassassin/branches/3.1/t/SATest.pm Mon Jul 23 02:40:35 2007
@@ -82,6 +82,13 @@
 
   read_config();
 
+  # if running as root, ensure "nobody" can write to it too
+  if ($> == 0) {
+    $tmp_dir_mode = 0777;
+  } else {
+    $tmp_dir_mode = 0755;
+  }
+
   $NO_SPAMC_EXE = ($RUNNING_ON_WINDOWS &&
                    !$ENV{'SPAMC_SCRIPT'} &&
                    !(-e "../spamc/spamc.exe"));
@@ -130,7 +137,8 @@
   # create an empty .prefs file
   open (PREFS, ">>log/test_default.cf"); close PREFS;
 
-  mkdir("log/user_state",0755);
+  mkdir("log/user_state",$tmp_dir_mode);
+  chmod ($tmp_dir_mode, "log/user_state");  # unaffected by umask
 
   $home = $ENV{'HOME'};
   $home ||= $ENV{'WINDIR'} if (defined $ENV{'WINDIR'});
@@ -139,7 +147,10 @@
   $ENV{'TEST_DIR'} = $cwd;
   $testname = $tname;
 
-  $current_user = (getpwuid($>))[0];
+  $spamd_run_as_user = (getpwuid($>))[0];
+  if ($> == 0) {
+    $spamd_run_as_user = "nobody";
+  }
 }
 
 # a port number between 32768 and 65535; used to allow multiple test
@@ -231,9 +242,7 @@
   my $post_redir = '';
   $args =~ s/ 2\>\&1$// and $post_redir = ' 2>&1';
 
-  rmtree ("log/outputdir.tmp"); # some tests use this
-  mkdir ("log/outputdir.tmp", 0755);
-
+  recreate_outputdir_tmp();
   %found = ();
   %found_anti = ();
 
@@ -265,8 +274,7 @@
   my $args = shift;
   my $read_sub = shift;
 
-  rmtree ("log/outputdir.tmp"); # some tests use this
-  mkdir ("log/outputdir.tmp", 0755);
+  recreate_outputdir_tmp();
 
   %found = ();
   %found_anti = ();
@@ -372,6 +380,12 @@
   1;
 }
 
+sub recreate_outputdir_tmp {
+  rmtree ("log/outputdir.tmp"); # some tests use this
+  mkdir ("log/outputdir.tmp", $tmp_dir_mode);
+  chmod ($tmp_dir_mode, "log/outputdir.tmp");  # unaffected by umask
+}
+
 sub start_spamd {
 
   return if $SKIP_SPAMD_TESTS;
@@ -380,8 +394,7 @@
 
   return if (defined($spamd_pid) && $spamd_pid > 0);
 
-  rmtree ("log/outputdir.tmp"); # some tests use this
-  mkdir ("log/outputdir.tmp", 0755);
+  recreate_outputdir_tmp();
 
   if (defined $ENV{'SD_ARGS'}) {
     $spamd_extra_args = $ENV{'SD_ARGS'} . " ". $spamd_extra_args;

Modified: spamassassin/branches/3.1/t/spamd_allow_user_rules.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/t/spamd_allow_user_rules.t?view=diff&rev=558675&r1=558674&r2=558675
==============================================================================
--- spamassassin/branches/3.1/t/spamd_allow_user_rules.t (original)
+++ spamassassin/branches/3.1/t/spamd_allow_user_rules.t Mon Jul 23 02:40:35 2007
@@ -36,7 +36,7 @@
 ";
 close OUT;
 
-ok (start_spamd ("--virtual-config-dir=log/virtualconfig/%u -L -u $current_user"));
+ok (start_spamd ("--virtual-config-dir=log/virtualconfig/%u -L -u $spamd_run_as_user"));
 ok (spamcrun ("-u testuser < data/spam/009", \&patterns_run_cb));
 ok (stop_spamd ());
 

Modified: spamassassin/branches/3.1/t/spamd_plugin.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/t/spamd_plugin.t?view=diff&rev=558675&r1=558674&r2=558675
==============================================================================
--- spamassassin/branches/3.1/t/spamd_plugin.t (original)
+++ spamassassin/branches/3.1/t/spamd_plugin.t Mon Jul 23 02:40:35 2007
@@ -22,6 +22,7 @@
 open(COUNTER,">log/spamd_plugin.tmp");
 print COUNTER "0";
 close COUNTER;
+chmod (0666, "log/spamd_plugin.tmp");
 
 my $sockpath = mk_safe_tmpdir()."/spamd.sock";
 start_spamd("-D -L --socketpath=$sockpath");