blib/lib/Lemonldap/NG/Portal/Plugins/StayConnected.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 62 CC 5 SCAR 22.3
CC
5
Cov
0%
check
20.0
init
6.0
skipAuthentication
2.0
CRAP 9.3
1 # Plugin to enable "stay connected on this device" feature
2  
3 package Lemonldap::NG::Portal::Plugins::StayConnected;
4  
5 use strict;
6 use Mouse;
7 use Lemonldap::NG::Portal::Main::Constants qw(
8 PE_OK
9 );
10  
11 our $VERSION = '2.23.0';
12  
13 extends qw(
14 Lemonldap::NG::Portal::Main::Plugin
15 );
16  
17 # INTERFACE
18  
19 use constant beforeAuth => 'check';
20 has rule => ( is => 'rw', default => sub { 0 } );
21  
22 # INITIALIZATION
23 sub init {
24 my ($self) = @_;
25  
26 # Parse activation rule
27 $self->rule(
28 $self->p->buildRule( $self->conf->{stayConnected}, 'stayConnected' ) );
29 return 0 unless $self->rule;
30  
31 return 1;
32 }
33  
34 # Check for:
35 sub check {
36 my ( $self, $req ) = @_;
37  
38 if ( !$self->rule->( $req, $req->sessionInfo ) ) {
39 $self->logger->debug("Stay Connected not allowed");
40 }
41  
42 my $trustedBrowser = $self->p->getService('trustedBrowser');
43  
44 # Run TrustedBrowser challenge
45 if ( $trustedBrowser->mustChallenge($req) ) {
46 return $trustedBrowser->challenge( $req, '#' );
47 }
48 elsif ( my $state = $trustedBrowser->getKnownBrowserState($req) ) {
49 return $self->skipAuthentication( $req, $state );
50 }
51 return PE_OK;
52 }
53  
54 # Remove authentication steps from the login flow
55 sub skipAuthentication {
56 my ( $self, $req, $state ) = @_;
57 my $uid = $state->{_trustedUser};
58 $req->user($uid);
59 $req->sessionInfo->{_stayConnectedSession} =
60 $state->{_stayConnectedSession};
61 $req->sessionInfo->{_trustedBrowser} = 1;
62 my @steps =
63 grep { ref $_ or $_ !~ /^(?:extractFormInfo|authenticate)$/ }
64 @{ $req->steps };
65 $req->steps( \@steps );
66 $self->userLogger->notice("$uid connected by StayConnected cookie");
67 return PE_OK;
68 }
69  
70 1;