line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::PAUSE::Permissions; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1372971
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
774
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
409
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
47
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
1104
|
use PAUSE::Permissions; |
|
1
|
|
|
|
|
166892
|
|
|
1
|
|
|
|
|
27
|
|
8
|
1
|
|
|
1
|
|
244672
|
use Parse::LocalDistribution; |
|
1
|
|
|
|
|
114466
|
|
|
1
|
|
|
|
|
827
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = (@Test::More::EXPORT, qw/all_permissions_ok/); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub all_permissions_ok { |
15
|
0
|
|
|
0
|
1
|
|
my $author = shift; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
plan skip_all => 'Set RELEASE_TESTING environmental variable to test this.' unless $ENV{RELEASE_TESTING}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Get your id from .pause |
20
|
0
|
|
0
|
|
|
|
$author ||= _get_pause_user(); |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
plan skip_all => "Can't determine who is going to release." unless $author; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Get authority from META |
25
|
0
|
|
0
|
|
|
|
my $meta_authority ||= _get_authority_in_meta(); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Prepare 06perms for testing |
28
|
0
|
|
|
|
|
|
my $perms = PAUSE::Permissions->new; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Get packages (respecting no_index) |
31
|
0
|
|
|
|
|
|
my $provides = Parse::LocalDistribution->new->parse(); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Iterate |
34
|
|
|
|
|
|
|
SKIP: |
35
|
0
|
|
|
|
|
|
for my $package (keys %$provides) { |
36
|
0
|
|
0
|
|
|
|
my $authority = uc($meta_authority || $author || ''); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $mp = $perms->module_permissions($package); |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if (!$mp) { |
41
|
0
|
|
|
|
|
|
pass "$package: no one has permissions ($authority should have the first come)"; |
42
|
0
|
|
|
|
|
|
next; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
my @maintainers = $mp->all_maintainers; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Author should have permissions, regardless of the authority |
47
|
0
|
0
|
|
|
|
|
if (grep { uc $_ eq uc $author } @maintainers) { |
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
pass "$package: $author has a permission"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
0
|
|
|
|
|
|
fail "$package: maintained by ".join ', ', @maintainers; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# $AUTHORITY has no effect in PAUSE. |
55
|
|
|
|
|
|
|
# just see if $AUTHORITY matches x_authority for information |
56
|
0
|
0
|
|
|
|
|
if ($meta_authority) { |
57
|
0
|
|
|
|
|
|
my $file_authority = _get_authority_in_file($package, $provides->{$package}); |
58
|
0
|
0
|
0
|
|
|
|
if ($file_authority && $file_authority ne $meta_authority) { |
59
|
|
|
|
|
|
|
# XXX: should fail? |
60
|
0
|
|
|
|
|
|
diag "$package: \$AUTHORITY ($file_authority) doesn't match x_authority ($meta_authority)"; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
done_testing; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _get_pause_user { |
69
|
|
|
|
|
|
|
# Get authority from ~/.pause |
70
|
0
|
|
|
0
|
|
|
require Config::Identity::PAUSE; |
71
|
0
|
|
|
|
|
|
my %config = Config::Identity::PAUSE->load; |
72
|
0
|
|
|
|
|
|
return $config{user}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _get_authority_in_meta { |
76
|
|
|
|
|
|
|
# Get authority from META |
77
|
0
|
|
|
0
|
|
|
my $meta = _parse_meta(); |
78
|
0
|
0
|
0
|
|
|
|
if ($meta && $meta->{x_authority}) { |
79
|
0
|
|
|
|
|
|
my $authority = $meta->{x_authority}; |
80
|
0
|
|
|
|
|
|
$authority =~ s/^cpan://i; |
81
|
0
|
|
|
|
|
|
return $authority; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _parse_meta { |
86
|
0
|
|
|
0
|
|
|
for my $file (qw/META.json META.yml/) { |
87
|
0
|
0
|
0
|
|
|
|
next unless -f $file && -r _; |
88
|
0
|
|
|
|
|
|
my $meta = Parse::CPAN::Meta->load_file($file); |
89
|
0
|
0
|
0
|
|
|
|
return $meta if $meta && ref $meta eq ref {}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _get_authority_in_file { |
94
|
0
|
|
|
0
|
|
|
my ($package, $package_info) = @_; |
95
|
0
|
|
|
|
|
|
my $file = $package_info->{infile}; |
96
|
0
|
0
|
0
|
|
|
|
return unless $file && -f $file && -r _; |
|
|
|
0
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
open my $fh, '<', $file or return; |
99
|
0
|
|
|
|
|
|
my $in_pod = 0; |
100
|
0
|
|
|
|
|
|
while(<$fh>) { |
101
|
0
|
0
|
|
|
|
|
last if /__(DATA|END)__/; |
102
|
0
|
0
|
|
|
|
|
$in_pod = /^=(?!cut?)/ ? 1 : /^=cut/ ? 0 : $in_pod; |
|
|
0
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
next if $in_pod; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if (/\$(?:${package}::)?AUTHORITY\s*=.+?(?i:cpan):([A-Za-z0-9]+)/) { |
106
|
0
|
|
|
|
|
|
return $1; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |