MozPersona/Controller.pm

filter: Statementstmt 37.7% 20 / 53 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 29.2% 29 / 99 CC 14 SCAR 40.5
CC
14
Cov
25%
js
110.0
signin
30.0
signout
2.0
CRAP 57.2
« MozPersona.pm ↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Mojolicious::Plugin::MozPersona::Controller;
5 1 $Mojolicious::Plugin::MozPersona::Controller::VERSION = '0.05';
6 # ABSTRACT: Default implementation for server side functions for "Persona" authentication.
7  
8 1 ▶use Mojo::Base 'Mojolicious::Controller';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Mojo::JSON qw(decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Mozilla::CA qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 0 ▶sub signin {
Subroutine signin: not called CC=5 SCAR=34.0
Pod documented
17 0 my $self = shift;
18  
19 0 $ENV{'MOJO_CA_FILE'} = Mozilla::CA::SSL_ca_file();
20  
21 0 my $persona_response = '';
22 0 my $result = '';
23  
24 0 eval {
25 0 $persona_response = $self->ua->post(
26 $self->stash('_persona_service')
27 => form => {
28 assertion => $self->param('assertion'),
29 audience => $self->stash('_persona_audience'),
30 }
31 )->res;
32  
33 0 $result = decode_json $persona_response->body;
34 };
35  
36 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not $result->{'status'} eq 'okay' || $result->{'status'} eq 'failure') { } 0 0 0
37 0 $self->app->log->error("Error verifying assertion with IdP: $@");
38 0 $self->render( json => { signin => Mojo::JSON->false } );
39 }
40 ▶ elsif ( ! ( $result->{'status'} eq "okay" or $result->{'status'} eq "failure" ) ) {
Condition0%0/3
$result->{'status'} eq 'okay' || $result->{'status'} eq 'failure'
l!l&&r!l&&!r
000
MC/DC0%0/2
$result->{'status'} eq 'okay' || $result->{'status'} eq 'failure'
$result->{'status'} eq 'okay' $result->{'status'} eq 'failure'
Truth table0%0/3
A || B
A= $result->{'status'} eq 'okay'B= $result->{'status'} eq 'failure'
ABresult
1X1
011
000
41 0 require Data::Dumper;
42 0 $self->app->log->error("Invalid response from IdP: " . Data::Dumper::Dumper($result));
43 }
44 else {
45 0 ▶ if ( $self->app->log->is_debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->app->log->is_debug) 0 0 0
46 0 require Data::Dumper;
47 0 $self->app->log->debug("Successfully verified user assertion with IdP: " . Data::Dumper::Dumper($result));
48 }
49 0 $self->session->{_persona} = $result;
50 0 $self->render( json => { signin => Mojo::JSON->true, result => $result } );
51 }
52 }
53  
54  
55 0 ▶sub signout {
Subroutine signout: not called CC=1 SCAR=6.9
Pod documented
56 0 my $self = shift;
57 0 delete $self->session->{_persona};
58 0 $self->render( json => { signout => Mojo::JSON->true } );
59 }
60  
61  
62 0 ▶sub js {
Subroutine js: not called CC=10 SCAR=47.0
Pod documented
63 0 my $self = shift;
64 0 my %c = %{ $self->stash('_persona_conf') };
65  
66 0 foreach my $k ( keys %c ) {
67 0 $self->stash( $k => $c{$k} );
68 }
69  
70 # set empty value for optional config
71 0 foreach my $w ( qw( siteLogo privacyPolicy termsOfService returnTo oncancel ) ) {
72 0 ▶ $self->stash( $w => '' ) unless $c{$w};
Branch: 1 branch
BranchTrueFalseTotal
unless $c{$w} 0 0 0
73 }
74  
75 0 $self->res->headers->content_type('text/javascript');
76  
77 0 my ( $tName, $tFormat, $tHandler ) = split( /\./, $c{'localJsTpl'} );
78 0 ▶ $tName = 'persona_local_js' unless defined($tName) and $tName;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tName and $tName 0 0 0
Condition0%0/3
defined $tName and $tName
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tName and $tName
defined $tName $tName
Truth table0%0/3
A and B
A= defined $tNameB= $tName
ABresult
0X0
100
111
79 0 ▶ $tFormat = 'txt' unless defined($tFormat) and $tFormat;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tFormat and $tFormat 0 0 0
Condition0%0/3
defined $tFormat and $tFormat
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tFormat and $tFormat
defined $tFormat $tFormat
Truth table0%0/3
A and B
A= defined $tFormatB= $tFormat
ABresult
0X0
100
111
80 0 ▶ $tHandler = 'ep' unless defined($tHandler) and $tHandler;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tHandler and $tHandler 0 0 0
Condition0%0/3
defined $tHandler and $tHandler
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tHandler and $tHandler
defined $tHandler $tHandler
Truth table0%0/3
A and B
A= defined $tHandlerB= $tHandler
ABresult
0X0
100
111
81  
82 0 $self->render( $tName, format => $tFormat, handler => $tHandler );
83 }
84  
85  
86 1 1;
87  
88 __END__
« MozPersona.pm ↑ Summary