DJabberd/Authen/AllowedUsers.pm

filter: Statementstmt 45.2% 24 / 53 Branchbran 11.1% 2 / 18 Conditioncond 20.0% 2 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 34.6% 35 / 101 CC 16 SCAR 41.3
CC
16
Cov
35%
check_cleartext
132.0
set_config_deniedusers
6.0
finalize
3.1
CRAP 61.9
« DJabberd/Connection.pm ↑ Summary DJabberd/RosterItem.pm »
1 package DJabberd::Authen::AllowedUsers;
2 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 20 ▶use base 'DJabberd::Authen';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 20 ▶use DJabberd::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 20 our $logger = DJabberd::Log->get_logger;
9  
10 82 ▶sub set_config_policy {
Subroutine set_config_policy: called CC=2 SCAR=7.0
Pod undocumented
11 82 my ($self, $policy) = @_;
12 82 $policy = lc $policy;
13 82 ▶ croak("Policy must be 'deny' or 'accept'") unless $policy =~ /^deny|accept$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $policy =~ /^deny|accept$/ 0 82 82
14 82 $self->{policy} = $policy;
15 }
16  
17 41 ▶sub set_config_allowedusers {
Subroutine set_config_allowedusers: called CC=2 SCAR=7.2
Pod undocumented
18 41 my ($self, $val) = @_;
19 41 ▶ $self->{allowed} = ref $val ? $val : [ split(/\s+/, $val) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $val ? : 41 0 41
20 }
21  
22 0 ▶sub set_config_deniedusers {
Subroutine set_config_deniedusers: not called CC=2 SCAR=17.9
Pod undocumented
23 0 my ($self, $val) = @_;
24 0 ▶ $self->{denied} = ref $val ? $val : [ split(/\s+/, $val) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $val ? : 0 0 0
25 }
26  
27 41 ▶sub finalize {
Subroutine finalize: called CC=3 SCAR=11.4
Pod undocumented
28 41 my $self = shift;
29 # just for error checking:
30 41 $self->set_config_policy($self->{policy});
31 41 ▶ $self->{allowed} ||= [];
Condition50%1/2
$self->{"allowed"} ||= []
l!l
410
MC/DC0%0/1
$self->{"allowed"} ||= []
$self->{"allowed"}
Truth table50%1/2
A
A= $self->{"allowed"}
Aresult
11
00
32 41 ▶ $self->{denied} ||= [];
Condition50%1/2
$self->{"denied"} ||= []
l!l
041
MC/DC0%0/1
$self->{"denied"} ||= []
$self->{"denied"}
Truth table50%1/2
A
A= $self->{"denied"}
Aresult
11
00
33 }
34  
35 0 ▶sub check_cleartext {
Subroutine check_cleartext: not called CC=11 SCAR=48.8
Pod undocumented
36 0 my ($self, $cb, %args) = @_;
37 0 my $user = $args{'username'};
38  
39 0 ▶ if ($self->{'policy'} eq "deny") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"policy"} eq "deny") 0 0 0
40 0 $logger->debug("$self --- user=$user, denying, unless allowed: @{$self->{allowed}}");
41 0 foreach my $allowed (@{$self->{allowed}}) {
42 0 ▶ if (ref $allowed eq "Regexp" && $user =~ /$allowed/) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $allowed eq 'Regexp' and $user =~ /$allowed/) { } 0 0 0
elsif ($user eq $allowed) { } 0 0 0
Condition0%0/3
ref $allowed eq "Regexp" and $user =~ /$allowed/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $allowed eq "Regexp" and $user =~ /$allowed/
ref $allowed eq "Regexp" $user =~ /$allowed/
Truth table0%0/3
A and B
A= ref $allowed eq "Regexp"B= $user =~ /$allowed/
ABresult
0X0
100
111
43 0 $cb->decline; # okay username, may continue in auth phase
44 0 return;
45 } elsif ($user eq $allowed) {
46 0 $cb->decline; # okay username, may continue in auth phase
47 0 return;
48 }
49 }
50 0 $cb->reject;
51 0 return;
52 }
53  
54 0 ▶ if ($self->{'policy'} eq "accept") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"policy"} eq "accept") 0 0 0
55 0 $logger->debug("$self --- user=$user, accepting, unless denied: @{$self->{denied}}");
56 0 foreach my $allowed (@{$self->{denied}}) {
57 0 ▶ if (ref $allowed eq "Regexp" && $user =~ /$allowed/) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $allowed eq 'Regexp' and $user =~ /$allowed/) { } 0 0 0
elsif ($user eq $allowed) { } 0 0 0
Condition0%0/3
ref $allowed eq "Regexp" and $user =~ /$allowed/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $allowed eq "Regexp" and $user =~ /$allowed/
ref $allowed eq "Regexp" $user =~ /$allowed/
Truth table0%0/3
A and B
A= ref $allowed eq "Regexp"B= $user =~ /$allowed/
ABresult
0X0
100
111
58 0 $cb->reject; # okay username, may continue in auth phase
59 0 return;
60 } elsif ($user eq $allowed) {
61 0 $cb->reject; # okay username, may continue in auth phase
62 0 return;
63 }
64 }
65 0 $cb->decline;
66 0 return;
67 }
68  
69 0 $cb->reject;
70 }
71  
72 20 1;
« DJabberd/Connection.pm ↑ Summary DJabberd/RosterItem.pm »