| 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
| |||||||||||||||||||||||||||||
| 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'
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'
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $tName and $tName
MC/DC0%0/2
defined $tName and $tName
defined $tName
$tName
Truth table0%0/3
A and B
A= defined $tNameB= $tName
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $tFormat = 'txt' unless defined($tFormat) and $tFormat; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tFormat and $tFormat
MC/DC0%0/2
defined $tFormat and $tFormat
defined $tFormat
$tFormat
Truth table0%0/3
A and B
A= defined $tFormatB= $tFormat
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $tHandler = 'ep' unless defined($tHandler) and $tHandler; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tHandler and $tHandler
MC/DC0%0/2
defined $tHandler and $tHandler
defined $tHandler
$tHandler
Truth table0%0/3
A and B
A= defined $tHandlerB= $tHandler
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | $self->render( $tName, format => $tFormat, handler => $tHandler ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||