HTTPServer/BasicAuthenHandler.pm

filter: Statementstmt 100% 36 / 36 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 50.0% 1 / 2 totaltotal 92.7% 51 / 55 CC 4 SCAR 7.4
CC
4
Cov
95%
handle
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« HTTPServer/ParameterParseHandler.pm ↑ Summary HTTPServer/NotFoundHandler.pm »
1 package POE::Component::Server::HTTPServer::BasicAuthenHandler;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use MIME::Base64 qw( decode_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use POE::Component::Server::HTTPServer::Handler qw( H_CONT H_FINAL );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'POE::Component::Server::HTTPServer::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
9 1 my $self = shift;
10 1 my $realm = shift;
11 1 $self->{realm} = $realm;
12 }
13  
14 2 ▶sub handle {
Subroutine handle: called CC=4 SCAR=13.9
Pod documented
15 2 my $self = shift;
16 2 my $context = shift;
17 2 my $cred = $context->{request}->header('Authorization');
18 2 ▶ if ( defined($cred) && $cred =~ /^Basic\s+(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cred and $cred =~ /^Basic\s+(.*)$/) 1 1 2
Condition66%2/3
defined $cred and $cred =~ /^Basic\s+(.*)$/
!ll&&!rl&&r
101
MC/DC50%1/2
defined $cred and $cred =~ /^Basic\s+(.*)$/
defined $cred $cred =~ /^Basic\s+(.*)$/
Truth table66%2/3
A and B
A= defined $credB= $cred =~ /^Basic\s+(.*)$/
ABresult
0X0
100
111
19 1 my $unscrambled = decode_base64($1);
20 1 ▶ if ( my($username,$password) = ( $unscrambled=~/^(.*?):(.*)/ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $unscrambled =~ /^(.*?):(.*)/) 1 0 1
21 1 $context->{basic_username} = $username;
22 1 $context->{basic_password} = $password;
23 1 return H_CONT;
24 }
25 }
26 # respond with basic auth challenge
27 1 return $self->authen_challenge($context);
28 }
29  
30 1 ▶sub authen_challenge {
Subroutine authen_challenge: called CC=1 SCAR=0.0
Pod undocumented
31 1 my $self = shift;
32 1 my $context = shift;
33 1 my $realm = $self->{realm};
34 1 $context->{response}->header('WWW-Authenticate',
35 qq{Basic realm="$realm"});
36 1 $context->{response}->code( RC_UNAUTHORIZED );
37 1 $context->{response}->content( "<HTML><BODY>Unauthorized</BODY></HTML>\n" );
38 1 return H_FINAL;
39 }
40  
41 1 1;
42 __END__
« HTTPServer/ParameterParseHandler.pm ↑ Summary HTTPServer/NotFoundHandler.pm »