Auth.pm

filter: Statementstmt 29.7% 11 / 37 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 37.5% 3 / 8 Podpod 100% 1 / 1 totaltotal 20.2% 15 / 74 CC 11 SCAR 34.2
CC
11
Cov
19%
register
56.0
__ANON__
30.0
__ANON__
2.0
CRAP 30.6
« Auth/OAuth2.pm ↑ Summary Auth/OAuth.pm »
1 package Mojolicious::Plugin::Web::Auth;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.17';
7  
8 1 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub register {
Subroutine register: not called CC=7 SCAR=40.3
Pod documented
11 0 my ( $self, $app, $args ) = @_;
12 0 ▶ my $module = delete $args->{module} or die "Missing mandatory parameter: module";
Branch: 1 branch
BranchTrueFalseTotal
my $module = delete $args->{"module"} or die "Missing mandatory parameter: module" 0 0 0
13 0 my $klass = join '::', __PACKAGE__, 'Site', $module;
14 0 ▶ if ($Mojolicious::VERSION >= 5.81) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Mojolicious::VERSION >= 5.81) { } 0 0 0
15 0 Mojo::Loader::load_class($klass);
16 } else {
17 0 Mojo::Loader->load($klass);
18 }
19  
20 0 my $moniker = $klass->moniker();
21 0 ▶ my $authenticate_path = delete $args->{authenticate_path} || "/auth/${moniker}/authenticate";
Condition0%0/2
delete $args->{'authenticate_path'} || "/auth/$moniker/authenticate"
l!l
00
MC/DC0%0/1
delete $args->{'authenticate_path'} || "/auth/$moniker/authenticate"
delete $args->{'authenticate_path'}
Truth table0%0/2
A
A= delete $args->{'authenticate_path'}
Aresult
11
00
22 0 ▶ my $callback_path = delete $args->{callback_path} || "/auth/${moniker}/callback";
Condition0%0/2
delete $args->{'callback_path'} || "/auth/$moniker/callback"
l!l
00
MC/DC0%0/1
delete $args->{'callback_path'} || "/auth/$moniker/callback"
delete $args->{'callback_path'}
Truth table0%0/2
A
A= delete $args->{'callback_path'}
Aresult
11
00
23  
24 # handlers
25 0 ▶ my $on_finished = delete $args->{on_finished} or die "Missing mandatory parameter: on_finished";
Branch: 1 branch
BranchTrueFalseTotal
my $on_finished = delete $args->{"on_finished"} or die "Missing mandatory parameter: on_finished" 0 0 0
26 0 ▶ my $on_error = delete $args->{on_error} || sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 my ( $c, $err ) = @_;
28 0 die "Authentication error in $module: $err";
29 0 ▶ };
Condition0%0/3
delete $args->{'on_error'} || sub { my($c, $err) = @_; die "Authentication error in ${module}: $err"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args->{'on_error'} || sub { my($c, $err) = @_; die "Authentication error in ${module}: $err"; }
delete $args->{'on_error'} sub { my($c, $err) = @_; die "Authentication error in ${module}: $err"; }
Truth table0%0/3
A || B
A= delete $args->{'on_error'}B= sub { my($c, $err) = @_; die "Authentication error in ${module}: $err"; }
ABresult
1X1
011
000
30  
31 # auth object
32 0 my $auth = $klass->new(%$args);
33  
34 0 ▶ $app->hook( before_dispatch => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
35 0 my $c = shift;
36 0 my $path = $c->req->url->path;
37 0 ▶ if ( $path->contains($authenticate_path) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($path->contains($authenticate_path)) { } 0 0 0
elsif ($path->contains($callback_path)) { } 0 0 0
38 0 my $forwarded_proto = $c->req->headers->header('x-forwarded-proto');
39 0 ▶ $c->req->url->base->scheme('https') if (defined $forwarded_proto && $forwarded_proto eq 'https');
Branch: 1 branch
BranchTrueFalseTotal
if defined $forwarded_proto and $forwarded_proto eq "https" 0 0 0
Condition0%0/3
defined $forwarded_proto and $forwarded_proto eq "https"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $forwarded_proto and $forwarded_proto eq "https"
defined $forwarded_proto $forwarded_proto eq "https"
Truth table0%0/3
A and B
A= defined $forwarded_protoB= $forwarded_proto eq "https"
ABresult
0X0
100
111
40 0 my $callback = $c->req->url->path($callback_path)->to_abs;
41 0 return $c->redirect_to( $auth->auth_uri( $c, $callback ) );
42 }
43 elsif ( $path->contains($callback_path) ) {
44 return $auth->callback( $c, +{
45 0 ▶ on_finished => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 $on_finished->($c, @_);
47 },
48 0 ▶ on_error => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 $on_error->($c, @_);
50 },
51 0 } );
52 }
53 0 } );
54  
55 0 return $self;
56 }
57  
58 1 1;
59  
60 __END__
« Auth/OAuth2.pm ↑ Summary Auth/OAuth.pm »