Update of /cvsroot/fink/fink/t/Services
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27474/t/Services
Modified Files:
Tag: shlibs
ChangeLog execute_nonroot_okay.t
Log Message:
Only PkgVersion.pm left and then to start testing and fixing. YAY
Index: execute_nonroot_okay.t
===================================================================
RCS file: /cvsroot/fink/fink/t/Services/execute_nonroot_okay.t,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -u -d -r1.6.2.1 -r1.6.2.2
--- execute_nonroot_okay.t 27 Dec 2004 19:01:30 -0000 1.6.2.1
+++ execute_nonroot_okay.t 1 Feb 2005 03:19:59 -0000 1.6.2.2
@@ -1,61 +1,127 @@
#!/usr/bin/perl -w
use strict;
-use Test::More 'no_plan';
+use Test::More tests=>12;
-require_ok('Fink::Services');
+require_ok('Fink::Services'); # 1
# exported functions
-use_ok('Fink::Services','execute');
+use_ok('Fink::Services','execute'); # 2
# needed for passing 'fink --build-as-nobody' flag to execute()
# (don't really care how it's implemented, but these tests are currently
# written for it being implemented with Fink::Config options)
-require_ok('Fink::Config');
-can_ok('Fink::Config','get_option');
-can_ok('Fink::Config','set_options');
+require_ok('Fink::Config'); # 3
+can_ok('Fink::Config','get_option'); # 4
+can_ok('Fink::Config','set_options'); # 5
-# anyone can write to /tmp (local dir could be chmod 700 to a user)
-use_ok('File::Temp', 'tempdir');
-my $tmpdir = tempdir( 'execute_nonroot_okay.t_XXXXX', DIR => '/tmp', CLEANUP
=> 1);
-$tmpdir or die "Bailing--cannot create scratchdir\n";
-chmod 0755, $tmpdir; # only root can write to this dir
-chdir "/tmp"; # "nobody" must start shells here in order to test
+# need a a safe place to create files
-my $result;
+# OS X 10.2 comes with perl 5.6.0, but File::Temp isn't in core until 5.6.1
+#use File::Temp (qw/ tempdir /);
+#my $tmpdir = tempdir( 'execute_nonroot_okay.t_XXXXX',
+# DIR => '/tmp', # dir itself be accessible to *all* users
+## CLEANUP => 1 # CLEANUP is unsafe (see 'rmtree' below)
+# );
+
+# OS X 10.2 mktemp does not have the -p flag implemented
+my $tmpdir = `/usr/bin/mktemp -d /tmp/execute_nonroot_okay.t_XXXXX`;
+chomp $tmpdir;
+
+if (!defined $tmpdir or !length $tmpdir or !-d $tmpdir) {
+ print "Bail out! Cannot create scratchdir\n";
+ die "\n";
+}
+chmod 0755, $tmpdir; # must have only root be able to write to dir but all
read
+# Need a world-readable Fink/Services.pm but don't want to go changing
+# perms on the whole hierarchy leading to whereever user is running test,
+# so make a copy in a known place with known perms.
+if (system qq{ mkdir "$tmpdir/Fink" && cp ../perlmod/Fink/Services.pm
"$tmpdir/Fink" }) {
+ diag "Could not create temp Services.pm; using local copy
instead.\nDepending on permissions and the presence of an existing Fink,
this\nsituation may result in an apparently-missing Services.pm.\n";
+} else {
+ chmod 0755, "$tmpdir/Fink";
+ chmod 0644, "$tmpdir/Fink/Services.pm";
+ $ENV{'PERL5LIB'} = defined $ENV{'PERL5LIB'} # so subprocesses see it
+ ? "$tmpdir:$ENV{'PERL5LIB'}"
+ : $tmpdir;
+}
+
+chdir "/tmp"; # set local dir to where user="nobody" can start shells
+
+# 6
Fink::Config::set_options( {'build_as_nobody' => 0} );
-eval { $result = &execute("touch $tmpdir/f1 >/dev/null 2>&1", nonroot_okay=>1)
};
-like("$result: $@", qr/^0: /, 'disabling build_as_nobody causes normal
execution');
+cmp_ok( &execute("touch $tmpdir/f1", nonroot_okay=>1),
+ '==', 0,
+ 'disabling build_as_nobody causes normal execution'
+ );
+# 7
Fink::Config::set_options( {'build_as_nobody' => 1} );
-eval { $result = &execute("touch $tmpdir/f2 >/dev/null 2>&1") };
-like("$result: $@", '/^0: /', 'omitting nonroot_okay option causes normal
execution');
+cmp_ok( &execute("touch $tmpdir/f2"),
+ '==', 0,
+ 'omitting nonroot_okay option causes normal execution'
+ );
+# 8
Fink::Config::set_options( {'build_as_nobody' => 1} );
-eval { $result = &execute("touch $tmpdir/f3 >/dev/null 2>&1", nonroot_okay=>0)
};
-like("$result: $@", '/^0: /', 'false nonroot_okay option causes normal
execution');
+cmp_ok( &execute("touch $tmpdir/f3", nonroot_okay=>0),
+ '==', 0,
+ 'false nonroot_okay option causes normal execution'
+ );
-Fink::Config::set_options( {'build_as_nobody' => 1} );
-eval { $result = &execute("touch $tmpdir/f4 >/dev/null 2>&1", nonroot_okay=>1)
};
+# 9
SKIP: {
+ Fink::Config::set_options( {'build_as_nobody' => 1} );
skip "You must be non-root for this test", 1 if $> == 0;
- like("$result: $@", '/^\d+: .*EUID/', 'try to set EUID when not root');
+ # this touch should fail noisily, so redirect
+ cmp_ok( &execute("touch $tmpdir/f4 > /dev/null 2>&1", nonroot_okay=>1),
+ '!=', 0,
+ 'try to switch users when not root'
+ );
}
+
+# 10
SKIP: {
+ Fink::Config::set_options( {'build_as_nobody' => 1} );
skip "You must be root for this test", 1 if $> != 0;
- unlike("$result: $@", '/^0: /', 'requires normal user but build_as_nobody
enabled');
+ # this touch should fail noisily, so redirect
+ cmp_ok( &execute("touch $tmpdir/f5 > /dev/null 2>&1", nonroot_okay=>1,
delete_tempfile=>1),
+ '!=', 0,
+ 'requires normal user but build_as_nobody enabled'
+ );
+ }
+
+# 11
+ SKIP: {
+ Fink::Config::set_options( {'build_as_nobody' => 1} );
+ skip "You must be root for this test", 1 if $> != 0;
+ my $file = "$tmpdir/f6";
+ open FOO, ">$file";
+ close FOO;
+ chmod 0666, $file; # create a file that all users can touch
+ cmp_ok( &execute("touch $file", nonroot_okay=>1),
+ '==', 0,
+ 'user "nobody" can do this and build_as_nobody enabled'
+ );
}
+# 12
SKIP: {
skip "You must be root for this test", 1 if $> != 0;
- TODO: {
- local $TODO = "cannot fully drop root yet";
# this test should use the exact same perl binary as is running
# this test (which is the same as the one to be used to run fink)
Fink::Config::set_options( {'build_as_nobody' => 1} );
- eval { $result = &execute('/usr/bin/perl -e \'print "hello\n"\' >
/dev/null', nonroot_okay=>1) };
- like("$result: $@", '/^0: /', 'command is not run under setuid');
- }
-}
+ cmp_ok( &execute('/usr/bin/perl -e "1;"', nonroot_okay=>1),
+ '==', 0,
+ 'command is not run under setuid'
+ );
+ }
+
+# We cannot use tempdir(CLEANUP=>1) because that works by installing
+# an END block to do the cleanup, which breaks us because &execute may
+# be implemented with forks: the END block runs when each child ends
+# not just at the end of the parent (== this test script). Damn it.
+use File::Path (qw/ rmtree /);
+rmtree($tmpdir, 0, 1);
Index: ChangeLog
===================================================================
RCS file: /cvsroot/fink/fink/t/Services/ChangeLog,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -d -r1.7.2.1 -r1.7.2.2
--- ChangeLog 27 Dec 2004 19:01:30 -0000 1.7.2.1
+++ ChangeLog 1 Feb 2005 03:19:59 -0000 1.7.2.2
@@ -1,3 +1,39 @@
+2005-1-11 Daniel Macks <[EMAIL PROTECTED]>
+
+ * execute_nonroot_okay.t: execute() may fork a process that needs
+ to find Services.pm, so make a copy of that file that is
+ guaranteed to be readable by "nobody".
+
+2005-1-5 Daniel Macks <[EMAIL PROTECTED]>
+
+ * execute_nonroot_okay.t: delete expected tempfile.
+
+2004-12-30 Daniel Macks <[EMAIL PROTECTED]>
+
+ * execute_nonroot_okay.t: rework a test to avoid using "touch" on
+ a dir.
+
+2004-12-30 Daniel Macks <[EMAIL PROTECTED]>
+
+ * execute_nonroot_okay.t: OS X 10.2 (perl 5.6.0) portability fix:
+ use /usr/bin/mktemp instead of File::Temp.
+
+2004-12-30 Daniel Macks <[EMAIL PROTECTED]>
+
+ * execute_nonroot_okay.t: Don't use Test tests for test-suite
+ prereqs. Fix tempdir sanity-check bail-out. More output-hiding
+ adjustments.
+
+2004-12-28 Daniel Macks <[EMAIL PROTECTED]>
+
+ * execute_nonroot_okay.t: Specify /usr/bin/touch since binutils'
+ can't touch directories. Don't hide output of tests that should be
+ silent.
+
+2004-12-28 Daniel Macks <[EMAIL PROTECTED]>
+
+ * execute_nonroot_okay.t: Majorly reworked for new execute().
+
2004-12-22 Daniel Macks <[EMAIL PROTECTED]>
* execute_nonroot_okay.t: Explicitly use correct perl interp
-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Fink-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fink-commits