Authentication/Credential/Remote.pm

filter: Statementstmt 83.0% 49 / 59 Branchbran 55.2% 21 / 38 Conditioncond 53.5% 15 / 28 MC/DCmcdc 33.3% 6 / 18 Subroutinesub 72.7% 8 / 11 Podpod 100% 2 / 2 totaltotal 64.7% 101 / 156 CC 30 SCAR 33.6
CC
30
Cov
68%
authenticate
47.2
new
11.6
__ANON__
2.0
CRAP 28.9
« Authentication/Credential/Password.pm ↑ Summary Plugin/Authentication.pm »
1 package Catalyst::Authentication::Credential::Remote;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 with 'MooseX::Emulate::Class::Accessor::Fast';
6  
7 2 ▶use Try::Tiny qw/ try catch /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 __PACKAGE__->mk_accessors(
10 qw/allow_re deny_re cutname_re source realm username_field/);
11  
12 2 ▶sub new {
Subroutine new: called CC=9 SCAR=24.5
Pod documented
13 2 my ( $class, $config, $app, $realm ) = @_;
14  
15 2 my $self = { };
16 2 bless $self, $class;
17  
18 # we are gonna compile regular expresions defined in config parameters
19 # and explicitly throw an exception saying what parameter was invalid
20 2 ▶ if (defined($config->{allow_regexp}) && ($config->{allow_regexp} ne "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"allow_regexp"} and $config->{"allow_regexp"} ne "") 2 0 2
Condition33%1/3
defined $config->{"allow_regexp"} and $config->{"allow_regexp"} ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $config->{"allow_regexp"} and $config->{"allow_regexp"} ne ""
defined $config->{"allow_regexp"} $config->{"allow_regexp"} ne ""
Truth table33%1/3
A and B
A= defined $config->{"allow_regexp"}B= $config->{"allow_regexp"} ne ""
ABresult
0X0
100
111
21 2 ▶ try { $self->allow_re( qr/$config->{allow_regexp}/ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
22 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 Catalyst::Exception->throw( "Invalid regular expression in ".
24 "'allow_regexp' configuration parameter");
25 2 };
26 }
27 2 ▶ if (defined($config->{deny_regexp}) && ($config->{deny_regexp} ne "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"deny_regexp"} and $config->{"deny_regexp"} ne "") 2 0 2
Condition33%1/3
defined $config->{"deny_regexp"} and $config->{"deny_regexp"} ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $config->{"deny_regexp"} and $config->{"deny_regexp"} ne ""
defined $config->{"deny_regexp"} $config->{"deny_regexp"} ne ""
Truth table33%1/3
A and B
A= defined $config->{"deny_regexp"}B= $config->{"deny_regexp"} ne ""
ABresult
0X0
100
111
28 2 ▶ try { $self->deny_re( qr/$config->{deny_regexp}/ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
29 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 Catalyst::Exception->throw( "Invalid regular expression in ".
31 "'deny_regexp' configuration parameter");
32 2 };
33 }
34 2 ▶ if (defined($config->{cutname_regexp}) && ($config->{cutname_regexp} ne "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"cutname_regexp"} and $config->{"cutname_regexp"} ne "") 2 0 2
Condition33%1/3
defined $config->{"cutname_regexp"} and $config->{"cutname_regexp"} ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $config->{"cutname_regexp"} and $config->{"cutname_regexp"} ne ""
defined $config->{"cutname_regexp"} $config->{"cutname_regexp"} ne ""
Truth table33%1/3
A and B
A= defined $config->{"cutname_regexp"}B= $config->{"cutname_regexp"} ne ""
ABresult
0X0
100
111
35 2 ▶ try { $self->cutname_re( qr/$config->{cutname_regexp}/ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
36 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 Catalyst::Exception->throw( "Invalid regular expression in ".
38 "'cutname_regexp' configuration parameter");
39 2 };
40 }
41 2 ▶ $self->source($config->{source} || 'REMOTE_USER');
Condition100%2/2
$config->{'source'} || 'REMOTE_USER'
l!l
11
MC/DC100%1/1
$config->{'source'} || 'REMOTE_USER'
$config->{'source'}
Truth table100%2/2
A
A= $config->{'source'}
Aresult
11
00
42 2 $self->realm($realm);
43 2 ▶ $self->username_field($config->{username_field} || 'username');
Condition100%2/2
$config->{'username_field'} || 'username'
l!l
11
MC/DC100%1/1
$config->{'username_field'} || 'username'
$config->{'username_field'}
Truth table100%2/2
A
A= $config->{'username_field'}
Aresult
11
00
44 2 return $self;
45 }
46  
47 11 ▶sub authenticate {
Subroutine authenticate: called CC=22 SCAR=38.5
Pod documented
48 11 my ( $self, $c, $realm, $authinfo ) = @_;
49  
50 11 my $remuser;
51 11 ▶ if ($self->source eq "REMOTE_USER") {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->source eq 'REMOTE_USER') { } 8 3 11
elsif ($self->source =~ /^(SSL_CLIENT_.*|CERT_.*|AUTH_USER)$/) { } 3 0 3
52 8 ▶ if ($c->req->can('remote_user')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c->req->can('remote_user')) { } 8 0 8
elsif ($c->engine->can('env') and defined $c->engine->env) { } 0 0 0
elsif ($c->req->can('user')) { } 0 0 0
53 # $c->req->remote_user was introduced in 5.80005; if not evailable we are
54 # gonna use $c->req->user that is deprecated but more or less works as well
55 8 $remuser = $c->req->remote_user;
56 }
57 # compatibility hack:
58 ▶ elsif ($c->engine->can('env') && defined($c->engine->env)) {
Condition0%0/3
$c->engine->can("env") and defined $c->engine->env
!ll&&!rl&&r
000
MC/DC0%0/2
$c->engine->can("env") and defined $c->engine->env
$c->engine->can("env") defined $c->engine->env
Truth table0%0/3
A and B
A= $c->engine->can("env")B= defined $c->engine->env
ABresult
0X0
100
111
59 # BEWARE: $c->engine->env was broken prior 5.80005
60 0 $remuser = $c->engine->env->{REMOTE_USER};
61 }
62 elsif ($c->req->can('user')) {
63 # maybe show warning that we are gonna use DEPRECATED $req->user
64 0 ▶ if (ref($c->req->user)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c->req->user) { } 0 0 0
65 # I do not know exactly when this happens but it happens
66 0 Catalyst::Exception->throw( "Cannot get remote user from ".
67 "\$c->req->user as it seems to be a reference not a string" );
68 }
69 else {
70 0 $remuser = $c->req->user;
71 }
72 }
73 }
74 elsif ($self->source =~ /^(SSL_CLIENT_.*|CERT_.*|AUTH_USER)$/) {
75 # if you are using 'exotic' webserver or if the user is
76 # authenticated e.g via SSL certificate his name could be avaliable
77 # in different variables
78 # BEWARE: $c->engine->env was broken prior 5.80005
79 3 my $nam=$self->source;
80 3 ▶ if ($c->request->can('env')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c->request->can('env')) { } 3 0 3
elsif ($c->engine->can('env')) { } 0 0 0
81 3 $remuser = $c->request->env->{$nam};
82 }
83 elsif ($c->engine->can('env')) {
84 0 $remuser = $c->engine->env->{$nam};
85 }
86 else {
87 # this happens on Catalyst 5.80004 and before (when using FastCGI)
88 0 Catalyst::Exception->throw( "Cannot handle parameter 'source=$nam'".
89 " as running Catalyst engine has broken \$c->engine->env" );
90 }
91 }
92 else {
93 0 Catalyst::Exception->throw( "Invalid value of 'source' parameter");
94 }
95 11 ▶ return unless defined($remuser);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $remuser 1 10 11
96 10 ▶ return if ($remuser eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $remuser eq "" 1 9 10
97  
98 # $authinfo hash can contain item username (it is optional) - if it is so
99 # this username has to be equal to remote_user
100 9 my $authuser = $authinfo->{username};
101 9 ▶ return if (defined($authuser) && ($authuser ne $remuser));
Branch: 1 branch
BranchTrueFalseTotal
if defined $authuser and $authuser ne $remuser 0 9 9
Condition33%1/3
defined $authuser and $authuser ne $remuser
!ll&&!rl&&r
900
MC/DC0%0/2
defined $authuser and $authuser ne $remuser
defined $authuser $authuser ne $remuser
Truth table33%1/3
A and B
A= defined $authuserB= $authuser ne $remuser
ABresult
0X0
100
111
102  
103 # handle deny / allow checks
104 9 ▶ return if (defined($self->deny_re) && ($remuser =~ $self->deny_re));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->deny_re and $remuser =~ $self->deny_re 1 8 9
Condition66%2/3
defined $self->deny_re and $remuser =~ $self->deny_re
!ll&&!rl&&r
081
MC/DC50%1/2
defined $self->deny_re and $remuser =~ $self->deny_re
defined $self->deny_re $remuser =~ $self->deny_re
Truth table66%2/3
A and B
A= defined $self->deny_reB= $remuser =~ $self->deny_re
ABresult
0X0
100
111
105 8 ▶ return if (defined($self->allow_re) && ($remuser !~ $self->allow_re));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->allow_re and not $remuser =~ $self->allow_re 1 7 8
Condition66%2/3
defined $self->allow_re and not $remuser =~ $self->allow_re
!ll&&!rl&&r
071
MC/DC50%1/2
defined $self->allow_re and not $remuser =~ $self->allow_re
defined $self->allow_re not $remuser =~ $self->allow_re
Truth table66%2/3
A and not(B)
A= defined $self->allow_reB= not $remuser =~ $self->allow_re
ABresult
0X0
100
111
106  
107 # if param cutname_regexp is specified we try to cut the final usename as a
108 # substring from remote_user
109 7 my $usr = $remuser;
110 7 ▶ if (defined($self->cutname_re)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->cutname_re) 7 0 7
111 7 ▶ if (($remuser =~ $self->cutname_re) && ($1 ne "")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remuser =~ $self->cutname_re and $1 ne "") 5 2 7
Condition100%3/3
$remuser =~ $self->cutname_re and $1 ne ""
!ll&&!rl&&r
115
MC/DC100%2/2
$remuser =~ $self->cutname_re and $1 ne ""
$remuser =~ $self->cutname_re $1 ne ""
Truth table100%3/3
A and B
A= $remuser =~ $self->cutname_reB= $1 ne ""
ABresult
0X0
100
111
112 5 $usr = $1;
113 }
114 }
115  
116 7 $authinfo->{ $self->username_field } = $usr;
117 7 my $user_obj = $realm->find_user( $authinfo, $c );
118 7 ▶ return ref($user_obj) ? $user_obj : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $user_obj ? : 7 0 7
119 }
120  
121 2 1;
122  
123 __END__
« Authentication/Credential/Password.pm ↑ Summary Plugin/Authentication.pm »