X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2Fftmp-security.t;h=96b2c4283c30829afd1dce5536a1d7cac01bcfde;hb=22d4bb9ccb8701e68f9243547d7e3a3c55f70908;hp=5f30f9651fa735c26015bd09bd3aa09f25d9badd;hpb=4b19af017623bfa3bb72bb164598a517f586e0d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/lib/ftmp-security.t b/t/lib/ftmp-security.t index 5f30f96..96b2c42 100755 --- a/t/lib/ftmp-security.t +++ b/t/lib/ftmp-security.t @@ -7,7 +7,7 @@ BEGIN { chdir 't' if -d 't'; - unshift @INC, '../lib'; + @INC = '../lib'; require Test; import Test; plan(tests => 13); } @@ -24,8 +24,11 @@ END { foreach (@files) { ok( !(-e $_) )} } use File::Temp qw/ tempfile unlink0 /; ok(1); -# The high security tests must currently be skipped on Windows -my $skipplat = ( ($^O eq 'MSWin32' || $^O eq 'os2') ? 1 : 0 ); +# The high security tests must currently be skipped on some platforms +my $skipplat = ( ( + # No sticky bits. + $^O eq 'MSWin32' || $^O eq 'os2' || $^O eq 'dos' + ) ? 1 : 0 ); # Can not run high security tests in perls before 5.6.0 my $skipperl = ($] < 5.006 ? 1 : 0 ); @@ -93,22 +96,45 @@ sub test_security { } # Create the tempfile - my $template = "temptestXXXXXXXX"; - my ($fh1, $fname1) = tempfile ( $template, - DIR => File::Spec->curdir, + my $template = "tmpXXXXX"; + my ($fh1, $fname1) = eval { tempfile ( $template, + DIR => File::Spec->tmpdir, UNLINK => 1, ); - print "# Fname1 = $fname1\n"; - ok( ( -e $fname1) ); + }; + + if (defined $fname1) { + print "# fname1 = $fname1\n"; + ok( (-e $fname1) ); + push(@files, $fname1); # store for end block + } elsif (File::Temp->safe_level() != File::Temp::STANDARD) { + my $skip2 = "Skip system possibly insecure, see INSTALL, section 'make test'"; + skip($skip2, 1); + # plus we need an end block so the tests come out in the right order + eval q{ END { skip($skip2,1); } 1; } || die; + } else { + ok(0); + } # Explicitly - my ($fh2, $fname2) = tempfile ($template, UNLINK => 1 ); - ok( (-e $fname2) ); - close($fh2); - - # Store filenames for the end block - push(@files, $fname1, $fname2); - - + if ( $< < File::Temp->top_system_uid() ){ + skip("Skip Test inappropriate for root", 1); + eval q{ END { skip($skip,1); } 1; } || die; + return; + } + my ($fh2, $fname2) = eval { tempfile ($template, UNLINK => 1 ); }; + if (defined $fname2) { + print "# fname2 = $fname2\n"; + ok( (-e $fname2) ); + push(@files, $fname2); # store for end block + close($fh2); + } elsif (File::Temp->safe_level() != File::Temp::STANDARD) { + my $skip2 = "Skip system possibly insecure, see INSTALL, section 'make test'"; + skip($skip2, 1); + # plus we need an end block so the tests come out in the right order + eval q{ END { skip($skip2,1); } 1; } || die; + } else { + ok(0); + } }