| 1 | package PlugAuth::Plugin::FlatAuthz; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Authorization using flat files for PlugAuth | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | our $VERSION = '0.39'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Log::Log4perl qw( :easy ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Text::Glob qw( match_glob ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Clone qw( clone ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Role::Tiny::With; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use File::Touch; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use List::Util qw( uniq ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | with 'PlugAuth::Role::Plugin'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | with 'PlugAuth::Role::Authz'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | with 'PlugAuth::Role::Refresh'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | with 'PlugAuth::Role::Flat'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | our %all_users; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | our %groupUser; # $groupUser{$group}{$user} is true iff $user is in $group | |||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | our %userGroups; # $userGroups{$user}{$group} is true iff $user is in $group | |||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | our %resourceActionGroup; # $resourceActionGroup{$resource}{$action}{$group} is true iff $group can do $action on $resource | |||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | our %actions; # All defined actions $actions{$action} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | our %hostTag; # $hostTag{$host}{$tag} is true iff $user has tag $tag | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | sub refresh | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $config = $class->global_config; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( has_changed( $config->group_file ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | %all_users = map { $_ => 1 } __PACKAGE__->app->auth->all_users; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | %groupUser = (); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my %data = __PACKAGE__->read_file( $config->group_file, nest => 1, lc_values => 1, lc_keys => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | for my $k (keys %data) | |||||||||||||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my %users; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | for my $v (keys %{ $data{$k} }) | |||||||||||||||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my @matches = match_glob( $v, keys %all_users); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | next unless @matches; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | @users{ @matches } = (1) x @matches; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $groupUser{$k} = \%users; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | %userGroups = __PACKAGE__->_reverse_nest(%groupUser); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( has_changed( $config->resource_file ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | %all_users = map { $_ => 1 } __PACKAGE__->app->auth->all_users; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | %resourceActionGroup = __PACKAGE__->read_file( $config->resource_file, nest => 2, lc_values => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | foreach my $resource (keys %resourceActionGroup) | |||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # TODO: maybe #g for group | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if($resource =~ /#u/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $value = delete $resourceActionGroup{$resource}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | foreach my $user (keys %all_users) | |||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $new_resource = $resource; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $new_value = clone $value; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $new_resource =~ s/#u/$user/g; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | foreach my $users (values %$new_value) | |||||||||||||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if(defined $users->{'#u'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | delete $users->{'#u'}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $users->{$user} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $resourceActionGroup{$new_resource} = $new_value; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | %actions = map { map { $_ => 1} keys %$_ } values %resourceActionGroup; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $h = $config->host_file(default => ''); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( ( $h ) && has_changed( $h ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$h and has_changed($h)
MC/DC0%0/2
$h and has_changed($h)
$h
has_changed($h)
Truth table0%0/3
A and B
A= $hB= has_changed($h)
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | %hostTag = __PACKAGE__->read_file( $h, nest => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | # When the user list has changed, the group files need to be reloaded, because | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # each user has his/her own group, so we touch the group file | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->flat_init; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $touch = File::Touch->new( | |||||||||||||||||||||||||||||||||||||||||
| 104 | mtime_only => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 105 | no_create => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my @list = ($self->app->config->group_file(default => [])); | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $self->app->on(user_list_changed => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $touch->touch(@list); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | sub can_user_action_resource | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_user_action_resource: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($class, $user,$action,$resource) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $user = lc $user; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $found; | |||||||||||||||||||||||||||||||||||||||||
| 120 | GROUP: | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | for my $group ( $user, keys %{ $userGroups{$user} } ) | |||||||||||||||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # check exact match on the resource so / will match | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if($resourceActionGroup{$resource} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action}{$group}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action}
MC/DC0%0/3
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action}{$group}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action}{$group}
Truth table0%0/4
A and B and C
A= $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}B= $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action}C= $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$resource}{$action}{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | && $resourceActionGroup{$resource}{$action} | ||||||||||||||||||||||||||||||||||||||||||
| 126 | && $resourceActionGroup{$resource}{$action}{$group}) | ||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $found = "group: $group resource: $resource"; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | last GROUP; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | for my $subresource (__PACKAGE__->_prefixes($resource)) | |||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | next unless $resourceActionGroup{$subresource} | ||||||||||||||||||||||||||||||||||||||||||
| 134 | && $resourceActionGroup{$subresource}{$action} | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | && $resourceActionGroup{$subresource}{$action}{$group}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action}{$group}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action}
MC/DC0%0/3
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action} and $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action}{$group}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action}
$PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action}{$group}
Truth table0%0/4
A and B and C
A= $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}B= $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action}C= $PlugAuth::Plugin::FlatAuthz::resourceActionGroup{$subresource}{$action}{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $found = "group: $group resource: $subresource"; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | last GROUP; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return $found; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub match_resources { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_resources: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my($class, $resourceregex) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | return (grep /$resourceregex/, keys %resourceActionGroup); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub _reverse_nest { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reverse_nest: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 151 | # Given a nested hash ( a => b => c), return one with (b => a => c); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my %h = @_; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my %new; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | while (my ($a,$bc) = each %h) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | while (my ($b,$c) = each %$bc) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $new{$b}{$a} = $c; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return %new; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub _prefixes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prefixes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 166 | # Given a string "/a/b/c/d" return an array of prefixes : | ||||||||||||||||||||||||||||||||||||||||||
| 167 | # "/", "/a", "/a/b", /a/b/c", "/a/b/c/d" | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my @p = split /\//, $str; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my @prefixes = ( map { '/'. join '/', @p[1..$_] } 0..$#p ); | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return @prefixes; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | sub host_has_tag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
host_has_tag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my ($class, $host, $tag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return exists($hostTag{$host}{$tag}); | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
actions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | return sort keys %actions; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub groups_for_user { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
groups_for_user: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $user = shift or return (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $user = lc $user; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return unless $all_users{$user}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | return [ sort $user, keys %{ $userGroups{ $user } || {} } ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$PlugAuth::Plugin::FlatAuthz::userGroups{$user} || {}
MC/DC0%0/1
$PlugAuth::Plugin::FlatAuthz::userGroups{$user} || {}
$PlugAuth::Plugin::FlatAuthz::userGroups{$user}
Truth table0%0/2
A
A= $PlugAuth::Plugin::FlatAuthz::userGroups{$user}
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub all_groups { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_groups: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return sort keys %groupUser; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub users_in_group { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
users_in_group: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my($class, $group) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | return unless defined $group; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $group = lc $group; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | return unless defined $groupUser{$group}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | return [keys %{ $groupUser{$group} }]; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | sub create_group | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_group: not called CC=5 SCAR=31.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my($self, $group, $users) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | unless(defined $group) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | WARN "Group not provided"; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if(defined $groupUser{$group}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | WARN "Group $group already exists"; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | $users = '' unless defined $users; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $filename = $self->global_config->group_file; | |||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | my $ok = $self->lock_and_update_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.4
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $buffer .= "$group : $users\n"; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return 0 unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | INFO "created group $group with members $users"; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | sub delete_group | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_group: not called CC=4 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my($self, $group) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $group = lc $group; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | unless($group && defined $groupUser{$group}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
MC/DC0%0/2
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
$group
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
Truth table0%0/3
A and B
A= $groupB= defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | WARN "Group $group does not exist"; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $filename = $self->global_config->group_file; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my $ok = $self->lock_and_update_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=26.1
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my($thisgroup, $password) = split /\s*:/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | next if defined $thisgroup && lc $thisgroup eq $group; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $thisgroup and lc $thisgroup eq $group
MC/DC0%0/2
defined $thisgroup and lc $thisgroup eq $group
defined $thisgroup
lc $thisgroup eq $group
Truth table0%0/3
A and B
A= defined $thisgroupB= lc $thisgroup eq $group
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | return 0 unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | INFO "deleted group $group"; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | sub update_group | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_group: not called CC=5 SCAR=32.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my($self, $group, $users) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $group = lc $group; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | unless($group && defined $groupUser{$group}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
MC/DC0%0/2
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
$group
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
Truth table0%0/3
A and B
A= $groupB= defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | WARN "Group $group does not exist"; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | return 1 unless defined $users; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $filename = $self->global_config->group_file; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | my $ok = $self->lock_and_update_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=26.1
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my($thisgroup) = split /\s*:/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | $line =~ s{:.*$}{: $users} if defined $thisgroup && lc($thisgroup) eq $group; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $thisgroup and lc $thisgroup eq $group
MC/DC0%0/2
defined $thisgroup and lc $thisgroup eq $group
defined $thisgroup
lc $thisgroup eq $group
Truth table0%0/3
A and B
A= defined $thisgroupB= lc $thisgroup eq $group
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | return 0 unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | INFO "update group $group set members to $users"; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | sub add_user_to_group | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_user_to_group: not called CC=4 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my($self, $group, $user) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $group = lc $group; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $user = lc $user; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | unless($group && defined $groupUser{$group}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
MC/DC0%0/2
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
$group
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
Truth table0%0/3
A and B
A= $groupB= defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | WARN "Group $group does not exist"; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $new_user_list; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $filename = $self->global_config->group_file; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | my $ok = $self->lock_and_update_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | my($thisgroup, $users) = split /\s*:\s*/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if(defined $thisgroup && lc($thisgroup) eq $group) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $thisgroup and lc $thisgroup eq $group
MC/DC0%0/2
defined $thisgroup and lc $thisgroup eq $group
defined $thisgroup
lc $thisgroup eq $group
Truth table0%0/3
A and B
A= defined $thisgroupB= lc $thisgroup eq $group
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $users = join ',', uniq (split(/\s*,\s*/, $users), $user); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $buffer .= "$thisgroup: $users\n"; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $new_user_list = $users; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | else | ||||||||||||||||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | return unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | INFO "update group $group set members to $new_user_list"; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | return $new_user_list; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | sub remove_user_from_group | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_user_from_group: not called CC=4 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my($self, $group, $user) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $group = lc $group; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $user = lc $user; | |||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | unless($group && defined $groupUser{$group}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
MC/DC0%0/2
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
$group
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
Truth table0%0/3
A and B
A= $groupB= defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | { | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | WARN "Group $group does not exist"; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $new_user_list; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $filename = $self->global_config->group_file; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | my $ok = $self->lock_and_update_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=26.9
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my ($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my($thisgroup, $users) = split /\s*:\s*/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if(defined $thisgroup && lc($thisgroup) eq $group) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $thisgroup and lc $thisgroup eq $group
MC/DC0%0/2
defined $thisgroup and lc $thisgroup eq $group
defined $thisgroup
lc $thisgroup eq $group
Truth table0%0/3
A and B
A= defined $thisgroupB= lc $thisgroup eq $group
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $users = join ',', grep { lc($_) ne $user } uniq @{ $self->users_in_group($group) }; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $buffer .= "$thisgroup: $users\n"; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $new_user_list = $users; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | else | ||||||||||||||||||||||||||||||||||||||||||
| 405 | { | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | return unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | INFO "update group $group set members to $new_user_list"; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return $new_user_list; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | sub grant | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grant: not called CC=6 SCAR=35.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my($self, $group, $action, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | $group = lc $group; | |||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | unless($group && (defined $groupUser{$group} || defined $all_users{$group})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group} || defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group} or defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
MC/DC0%0/3
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group} || defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
$group
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
Truth table0%0/4
A and B or C
A= $groupB= defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}C= defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | WARN "Group (or user) $group does not exist"; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $resource =~ s{^/?}{/}; | |||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | if($resourceActionGroup{$resource}->{$action}->{$group}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | { | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | WARN "grant already added $group $action $resource"; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $filename = $self->global_config->resource_file; | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | my $ok = $self->lock_and_update_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.4
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $buffer .= "$resource ($action) : $group\n"; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | return 0 unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | INFO "grant $group $action $resource"; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | sub revoke | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
revoke: not called CC=7 SCAR=38.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my($self, $group, $action, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $group = lc $group; | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | unless($group && (defined $groupUser{$group} || defined $all_users{$group})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group} || defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group} or defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
MC/DC0%0/3
$group and defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group} || defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
$group
defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}
defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
Truth table0%0/4
A and B or C
A= $groupB= defined $PlugAuth::Plugin::FlatAuthz::groupUser{$group}C= defined $PlugAuth::Plugin::FlatAuthz::all_users{$group}
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | { | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | WARN "Group (or user) $group does not exist"; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | $resource = '/' . $resource unless $resource =~ /\//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | unless($resourceActionGroup{$resource}->{$action}->{$group}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 478 | { | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | WARN "Group (or user) $group not authorized to $action on $resource"; | |||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my $filename = $self->global_config->resource_file; | |||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | my $ok = $self->lock_and_update_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=37.5
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | { | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | if($line =~ /^#/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | ▶ | elsif($line =~ m{^\s*(.*?)\s*\((.*?)\)\s*:\s*(.*?)\s*$} && $1 eq $resource && $2 eq $action) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$line =~ /^\s*(.*?)\s*\((.*?)\)\s*:\s*(.*?)\s*$/ and $1 eq $resource and $2 eq $action
$line =~ /^\s*(.*?)\s*\((.*?)\)\s*:\s*(.*?)\s*$/ and $1 eq $resource
MC/DC0%0/3
$line =~ /^\s*(.*?)\s*\((.*?)\)\s*:\s*(.*?)\s*$/ and $1 eq $resource and $2 eq $action
$line =~ /^\s*(.*?)\s*\((.*?)\)\s*:\s*(.*?)\s*$/
$1 eq $resource
$2 eq $action
Truth table0%0/4
A and B and C
A= $line =~ /^\s*(.*?)\s*\((.*?)\)\s*:\s*(.*?)\s*$/B= $1 eq $resourceC= $2 eq $action
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | { | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my(@groups) = grep { $_ ne $group } split /,/, $3; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | $buffer .= "$resource ($action) : " . join(',', @groups) . "\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | if @groups > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | else | ||||||||||||||||||||||||||||||||||||||||||
| 505 | { | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | $buffer .= "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | return 0 unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | INFO "revoke $group $action $resource"; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | sub granted | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
granted: not called CC=1 SCAR=4.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my $filename = $self->global_config->resource_file; | |||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my @granted_list; | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | my $ok = $self->lock_and_read_file($filename, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=24.6
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 5 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my($fh) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | while(! eof $fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | { | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | next if $line =~ /^#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | push @granted_list, "$1 ($2): $3" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | if $line =~ m{^\s*(.*?)\s*\((.*?)\)\s*:\s*(.*?)\s*$}; | ||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | return \@granted_list; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | __END__ | ||||||||||||||||||||||||||||||||||||||||||