Make -Dusemorebits find long doubles in Solaris.
[p5sagit/p5-mst-13.2.git] / t / lib / ftmp-security.t
CommitLineData
e2cf2bdb 1#!/usr/bin/perl -w
262eb13a 2# Test for File::Temp - Security levels
3
4# Some of the security checking will not work on all platforms
5# Test a simple open in the cwd and tmpdir foreach of the
6# security levels
7
e2cf2bdb 8BEGIN {
9 chdir 't' if -d 't';
20822f61 10 @INC = '../lib';
e2cf2bdb 11 require Test; import Test;
2898e2cc 12 plan(tests => 13);
e2cf2bdb 13}
262eb13a 14
e2cf2bdb 15use strict;
262eb13a 16use File::Spec;
1c19c868 17
18# Set up END block - this needs to happen before we load
19# File::Temp since this END block must be evaluated after the
20# END block configured by File::Temp
21my @files; # list of files to remove
22END { foreach (@files) { ok( !(-e $_) )} }
23
262eb13a 24use File::Temp qw/ tempfile unlink0 /;
25ok(1);
26
781948c1 27# The high security tests must currently be skipped on some platforms
28my $skipplat = ( (
29 # No sticky bits.
30 $^O eq 'MSWin32' || $^O eq 'os2' || $^O eq 'dos'
31 ) ? 1 : 0 );
262eb13a 32
33# Can not run high security tests in perls before 5.6.0
34my $skipperl = ($] < 5.006 ? 1 : 0 );
35
36# Determine whether we need to skip things and why
37my $skip = 0;
38if ($skipplat) {
39 $skip = "Skip Not supported on this platform";
40} elsif ($skipperl) {
41 $skip = "Skip Perl version must be v5.6.0 for these tests";
42
43}
44
45print "# We will be skipping some tests : $skip\n" if $skip;
46
47# start off with basic checking
48
49File::Temp->safe_level( File::Temp::STANDARD );
50
51print "# Testing with STANDARD security...\n";
52
53&test_security(0);
54
55# Try medium
56
57File::Temp->safe_level( File::Temp::MEDIUM )
58 unless $skip;
59
60print "# Testing with MEDIUM security...\n";
61
62# Now we need to start skipping tests
63&test_security($skip);
64
65# Try HIGH
66
67File::Temp->safe_level( File::Temp::HIGH )
68 unless $skip;
69
70print "# Testing with HIGH security...\n";
71
72&test_security($skip);
73
74exit;
75
76# Subroutine to open two temporary files.
77# one is opened in the current dir and the other in the temp dir
78
79sub test_security {
80
81 # Read in the skip flag
82 my $skip = shift;
83
84 # If we are skipping we need to simply fake the correct number
85 # of tests -- we dont use skip since the tempfile() commands will
86 # fail with MEDIUM/HIGH security before the skip() command would be run
87 if ($skip) {
669b450a 88
262eb13a 89 skip($skip,1);
90 skip($skip,1);
669b450a 91
262eb13a 92 # plus we need an end block so the tests come out in the right order
93 eval q{ END { skip($skip,1); skip($skip,1) } 1; } || die;
669b450a 94
262eb13a 95 return;
96 }
97
1c19c868 98 # Create the tempfile
781948c1 99 my $template = "tmpXXXXX";
262eb13a 100 my ($fh1, $fname1) = tempfile ( $template,
da7cc32f 101 DIR => File::Spec->tmpdir,
262eb13a 102 UNLINK => 1,
103 );
781948c1 104 if (defined $fname1) {
105 print "# fname1 = $fname1\n";
106 ok( (-e $fname1) );
107 } elsif (File::Temp->safe_level() != File::Temp::STANDARD) {
108 skip("system possibly insecure, see INSTALL, section 'make test'", 1);
109 } else {
110 ok(0);
111 }
262eb13a 112
113 # Explicitly
781948c1 114 my ($fh2, $fname2) = tempfile ($template, UNLINK => 1 );
115 if (defined $fname2) {
116 print "# fname2 = $fname2\n";
117 ok( (-e $fname2) );
118 close($fh2);
119 } elsif (File::Temp->safe_level() != File::Temp::STANDARD) {
120 skip("system possibly insecure, see INSTALL, section 'make test'", 1);
121 } else {
122 ok(0);
123 }
262eb13a 124
125 # Store filenames for the end block
126 push(@files, $fname1, $fname2);
262eb13a 127}