blib/lib/Catalyst/Authentication/Credential/Upstream/Headers.pm

filter: Statementstmt 100% 26 / 26 Branchbran 83.3% 5 / 6 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 3 / 3 Podpod 50.0% 1 / 2 totaltotal 86.6% 39 / 45 CC 6 SCAR 15.7
CC
6
Cov
92%
authenticate
6.1
BEGIN
1.0
BUILDARGS
1.0
CRAP 4.8
↑ Summary
1 package Catalyst::Authentication::Credential::Upstream::Headers;
2 {
3 2 $Catalyst::Authentication::Credential::Upstream::Headers::VERSION = '0.02';
4 }
5  
6 # ABSTRACT: Catalyst authentication credentials from HTTP headers
7  
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 has user_header =>
11 isa => 'Str',
12 is => 'ro',
13 default => 'X-Catalyst-Credential-Upstream-User';
14  
15 2 has role_header =>
16 isa => 'Str',
17 is => 'ro',
18 default => 'X-Catalyst-Credential-Upstream-Roles';
19  
20 2 has role_delimiter =>
21 isa => 'Str',
22 is => 'ro',
23 default => '|';
24  
25 2 has use_x500_cn =>
26 isa => 'Bool',
27 is => 'ro',
28 default => 1;
29  
30 2 has realm =>
31 isa => 'Catalyst::Authentication::Realm',
32 is => 'ro',
33 required => 1;
34  
35 sub BUILDARGS
36 1 ▶{
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod documented
37 1 my $class = shift;
38 1 my $config = shift;
39 1 my $app = shift;
40 1 my $realm = shift;
41  
42 1 return { %$config, realm => $realm };
43 }
44  
45 sub authenticate
46 9 ▶{
Subroutine authenticate: called CC=6 SCAR=18.1
Pod undocumented
47 9 my $self = shift;
48 9 my $c = shift;
49  
50 # This method is a no-op for the most part. The work that is done
51 # here is mostly marshalling the request headers into user objects
52 # that fit the authentication plugin's interface.
53  
54 9 my $user = undef;
55 9 my $delimiter = $self->role_delimiter;
56  
57 9 ▶ if (my $username = $c->req->headers->header($self->user_header)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $username = $c->req->headers->header($self->user_header)) 4 5 9
58 4 ▶ my @roles = split /\Q$delimiter\E */, $c->req->headers->header($self->role_header) || '';
Condition100%2/2
$c->req->headers->header($self->role_header) || ''
l!l
31
MC/DC100%1/1
$c->req->headers->header($self->role_header) || ''
$c->req->headers->header($self->role_header)
Truth table100%2/2
A
A= $c->req->headers->header($self->role_header)
Aresult
11
00
59  
60 # attempt to extract the cn (common name) component of anything
61 # that looks like it might be an X.501 distinguished name
62  
63 4 ▶ @roles = map { { split /[;,= ]+/ }->{cn} || $_ } @roles
Branch: 1 branch
BranchTrueFalseTotal
if $self->use_x500_cn 4 0 4
Condition33%1/3
{split(/[;,= ]+/, $_, 0)}->{'cn'} || $_
l!l&&r!l&&!r
060
MC/DC0%0/2
{split(/[;,= ]+/, $_, 0)}->{'cn'} || $_
{split(/[;,= ]+/, $_, 0)}->{'cn'} $_
Truth table33%1/3
A || B
A= {split(/[;,= ]+/, $_, 0)}->{'cn'}B= $_
ABresult
1X1
011
000
64 if $self->use_x500_cn;
65  
66 4 $user = { id => $username, roles => \@roles };
67 }
68  
69 9 ▶ return $user ? $self->realm->find_user($user) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$user ? : 4 5 9
70 }
71  
72 2 1;
73  
74 __END__
↑ Summary