Testsuite: find a group name if 'mail' is not available.
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Wed, 2 Nov 2016 21:28:18 +0000 (22:28 +0100)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Wed, 2 Nov 2016 21:30:32 +0000 (22:30 +0100)
If the group 'mail' does not exist (as on some *BSD systems),
test 0001 fails. We now use a randomly choosen group, if necessary.

The group name isn't used for anything else than testing the config
file parser.

test/confs/0001
test/lib/Exim/Runtest.pm [new file with mode: 0644]
test/runtest

index 8d55b29..1eb0e88 100644 (file)
@@ -198,7 +198,7 @@ no_syslog_timestamp
 system_filter = /home/exim/test/filter
 system_filter_directory_transport =
 system_filter_file_transport =
 system_filter = /home/exim/test/filter
 system_filter_directory_transport =
 system_filter_file_transport =
-system_filter_group = mail
+system_filter_group = MAILGROUP
 system_filter_pipe_transport =
 system_filter_reply_transport =
 system_filter_user = 99
 system_filter_pipe_transport =
 system_filter_reply_transport =
 system_filter_user = 99
@@ -236,7 +236,7 @@ manualroute:
   no_fail_verify_recipient
   no_fail_verify_sender
   fallback_hosts = localhost
   no_fail_verify_recipient
   no_fail_verify_sender
   fallback_hosts = localhost
-  group = mail
+  group = MAILGROUP
   headers_add =
   headers_remove =
   host_find_failed = freeze
   headers_add =
   headers_remove =
   host_find_failed = freeze
@@ -370,7 +370,7 @@ forward:
   forbid_filter_run
   no_forbid_include
   no_forbid_pipe
   forbid_filter_run
   no_forbid_include
   no_forbid_pipe
-  group = mail
+  group = MAILGROUP
   headers_add =
   headers_remove =
   hide_child_in_errmsg
   headers_add =
   headers_remove =
   hide_child_in_errmsg
@@ -386,7 +386,7 @@ forward:
   more
   no_one_time
   owners = root
   more
   no_one_time
   owners = root
-  owngroups = mail
+  owngroups = MAILGROUP
   pipe_transport = dummy
   no_qualify_preserve_domain
   redirect_router = aliasfile2
   pipe_transport = dummy
   no_qualify_preserve_domain
   redirect_router = aliasfile2
@@ -420,7 +420,7 @@ localuser:
   no_fail_verify_recipient
   no_fail_verify_sender
   fallback_hosts =
   no_fail_verify_recipient
   no_fail_verify_sender
   fallback_hosts =
-  group = mail
+  group = MAILGROUP
   headers_add = X-added: by localuser
   headers_remove =
   no_initgroups
   headers_add = X-added: by localuser
   headers_remove =
   no_initgroups
@@ -460,7 +460,7 @@ smartuser:
   file_transport = dummy
   forbid_file
   forbid_pipe
   file_transport = dummy
   forbid_file
   forbid_pipe
-  group = mail
+  group = MAILGROUP
   headers_add =
   headers_remove =
   hide_child_in_errmsg
   headers_add =
   headers_remove =
   hide_child_in_errmsg
@@ -519,7 +519,7 @@ appendfile:
   file = /home/$local_part/inbox
   file_format = "From : appendfile"
   no_file_must_exist
   file = /home/$local_part/inbox
   file_format = "From : appendfile"
   no_file_must_exist
-  group = mail
+  group = MAILGROUP
   headers_add = X-original-domain: $original_domain\nX-original-localp: $original_local_part
   headers_remove =
   headers_rewrite = a@b c@d
   headers_add = X-original-domain: $original_domain\nX-original-localp: $original_local_part
   headers_remove =
   headers_rewrite = a@b c@d
diff --git a/test/lib/Exim/Runtest.pm b/test/lib/Exim/Runtest.pm
new file mode 100644 (file)
index 0000000..2ac9a61
--- /dev/null
@@ -0,0 +1,28 @@
+package Exim::Runtest;
+use strict;
+use warnings;
+use Carp;
+
+use List::Util qw'shuffle';
+
+
+# find a group name, preferrable 'mail', but
+# use some other random name if 'mail' isn't a valid group
+# name
+sub mailgroup {
+    my $group = shift;
+
+    croak "Need a group *name*, not a numeric group id."
+        if $group =~ /^\d+$/;
+
+    return $group if getgrnam $group;
+
+    my @groups;
+    setgrent or die "setgrent: $!\n";
+    push @groups, $_ while defined($_ = getgrent);
+    endgrent;
+    return (shuffle @groups)[0];
+};
+
+
+1;
index e8fbe48..78cd051 100755 (executable)
@@ -26,6 +26,11 @@ use Socket;
 use Time::Local;
 use Cwd;
 use File::Basename;
 use Time::Local;
 use Cwd;
 use File::Basename;
+use FindBin qw'$Bin';
+
+use lib "$Bin/lib";
+use Exim::Runtest;
+
 use if $ENV{DEBUG} && $ENV{DEBUG} =~ /\bruntest\b/ => ('Smart::Comments' => '####');
 
 
 use if $ENV{DEBUG} && $ENV{DEBUG} =~ /\bruntest\b/ => ('Smart::Comments' => '####');
 
 
@@ -88,6 +93,10 @@ $parm_port_d3 = 1227;        # Additional for daemon
 $parm_port_d4 = 1228;        # Additional for daemon
 my $dynamic_socket;          # allocated later for PORT_DYNAMIC
 
 $parm_port_d4 = 1228;        # Additional for daemon
 my $dynamic_socket;          # allocated later for PORT_DYNAMIC
 
+# Find a suiteable group name for test (currently only 0001
+# uses a group name. A numeric group id would do
+my $parm_mailgroup = Exim::Runtest::mailgroup('mail');
+
 # Manually set locale
 $ENV{LC_ALL} = 'C';
 
 # Manually set locale
 $ENV{LC_ALL} = 'C';
 
@@ -149,6 +158,7 @@ s?\bTESTNUM\b?$_[0]?g;
 s?(\b|_)V4NET([\._])?$1$parm_ipv4_test_net$2?g;
 s?\bV6NET:?$parm_ipv6_test_net:?g;
 s?\bPORT_DYNAMIC\b?$dynamic_socket->sockport()?eg;
 s?(\b|_)V4NET([\._])?$1$parm_ipv4_test_net$2?g;
 s?\bV6NET:?$parm_ipv6_test_net:?g;
 s?\bPORT_DYNAMIC\b?$dynamic_socket->sockport()?eg;
+s?\bMAILGROUP\b?$parm_mailgroup?g;
 }
 
 
 }