Debian Codegraph @

t2/tmp_perms.t

raw
1 use Test2::V0;
2 use File::Spec;
3 use Test2::Harness::Util qw/clean_path/;
4 use Fcntl ':mode';
5
6 sub check_perms {
7 my $file = shift;
8 my $mode = (stat($file))[2];
9
10 my @bad;
11 $mode & S_ISVTX or push @bad => "$file does not have sticky-bit";
12 $mode & S_IRWXU or push @bad => "$file is not user RWX";
13 $mode & S_IRWXG or push @bad => "$file is not group RWX";
14 $mode & S_IRWXO or push @bad => "$file is not other RWX";
15
16 return \@bad;
17 }
18
19 my $system_tmp = clean_path($ENV{SYSTEM_TMPDIR});
20
21 my $problems = check_perms($system_tmp);
22 skip_all join ", " => @$problems if @$problems;
23
24 my $path = $ENV{TMPDIR};
25 is(check_perms($path), [], "tempdir has correct permissions");
26
27 my $last = $path;
28 my $cnt = 0;
29 while ($system_tmp) {
30 my $next = clean_path(File::Spec->catdir($last, File::Spec->updir()));
31 last if $next eq $system_tmp; # We hit system temp, we can stop
32 last if $next eq $last; # We probably hit root
33 last if $cnt++ > 10; # Something went wrong, no need to loop forever
34 $last = $next;
35
36 is(check_perms($next), [], "$next has correct permissions");
37 }
38
39 done_testing;