Proxy.pm

filter: Statementstmt 95.6% 44 / 46 Branchbran 81.2% 13 / 16 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 93.3% 70 / 75 CC 10 SCAR 14.5
CC
10
Cov
92%
authenticate_basic
7.2
init
4.0
BEGIN
1.0
CRAP 4.3
↑ Summary Proxy/User.pm »
1 package Catalyst::Authentication::Credential::HTTP::Proxy;
2 2 ▶use base qw/Catalyst::Authentication::Credential::HTTP/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use String::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Catalyst::Authentication::Credential::HTTP::Proxy::User;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = "0.06";
12  
13 2 __PACKAGE__->mk_accessors(qw/
14 url
15 /);
16  
17 4 ▶sub init {
Subroutine init: called CC=4 SCAR=13.9
Pod documented
18 4 my ($self) = @_;
19
20 4 ▶ my $type = $self->type || 'basic';
Condition100%2/2
$self->type || 'basic'
l!l
22
MC/DC100%1/1
$self->type || 'basic'
$self->type
Truth table100%2/2
A
A= $self->type
Aresult
11
00
21
22 4 ▶ if (!$self->_config->{url}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_config->{"url"}) 1 3 4
23 1 Catalyst::Exception->throw(__PACKAGE__ . " configuration does not include a 'url' key, cannot proceed");
24 }
25
26 3 ▶ if (!grep /^$type$/, ('basic')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$type$/, "basic") 1 2 3
27 1 Catalyst::Exception->throw(__PACKAGE__ . " used with unsupported authentication type: " . $type);
28 }
29 2 $self->type($type);
30 }
31  
32 8 ▶sub authenticate_basic {
Subroutine authenticate_basic: called CC=7 SCAR=19.8
Pod documented
33 8 my ( $self, $c, $realm, $auth_info ) = @_;
34  
35 8 ▶ $c->log->debug('Checking http basic authentication.') if $c->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 8 8
36  
37 8 my $headers = $c->req->headers;
38  
39 8 ▶ if ( my ( $user, $password ) = $headers->authorization_basic ) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = $headers->authorization_basic) { } 6 2 8
elsif ($c->debug) { } 0 2 2
40 6 my $ua = Catalyst::Authentication::Credential::HTTP::Proxy::User->new;
41 6 $ua->credentials($user, $password);
42 6 my $resp = $ua->get($self->url);
43 6 ▶ if ( $resp->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->is_success) { } 4 2 6
44 # Config username_field TODO
45 4 my $user_obj = $realm->find_user( { username => $user }, $c);
46 4 ▶ unless ($user_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user_obj) 2 2 4
47 2 ▶ $c->log->debug("User '$user' doesn't exist in the default store")
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 2 2
48 if $c->debug;
49 2 return;
50 }
51 2 $c->set_authenticated($user_obj);
52 2 return 1;
53 }
54 else {
55 2 $c->log->info('Remote authentication failed:'.$resp->message);
56 2 return 0;
57 }
58 }
59 elsif ( $c->debug ) {
60 0 $c->log->info('No credentials provided for basic auth');
61 0 return 0;
62 }
63 }
64  
65 2 1;
66  
67 __END__
↑ Summary Proxy/User.pm »