Allow to check last logins with stayConnected plugin & improve unit test (#2365)
This commit is contained in:
parent
a1ec4c2114
commit
7ac2a0da80
|
@ -110,6 +110,7 @@ sub display {
|
||||||
CHECK_LOGINS => $self->conf->{portalCheckLogins}
|
CHECK_LOGINS => $self->conf->{portalCheckLogins}
|
||||||
&& $req->data->{login},
|
&& $req->data->{login},
|
||||||
ASK_LOGINS => $req->param('checkLogins') || 0,
|
ASK_LOGINS => $req->param('checkLogins') || 0,
|
||||||
|
ASK_STAYCONNECTED => $req->param('stayconnected') || 0,
|
||||||
CONFIRMKEY => $self->stamp(),
|
CONFIRMKEY => $self->stamp(),
|
||||||
(
|
(
|
||||||
$req->data->{customScript}
|
$req->data->{customScript}
|
||||||
|
@ -138,6 +139,7 @@ sub display {
|
||||||
CHECK_LOGINS => $self->conf->{portalCheckLogins}
|
CHECK_LOGINS => $self->conf->{portalCheckLogins}
|
||||||
&& $req->data->{login},
|
&& $req->data->{login},
|
||||||
ASK_LOGINS => $req->param('checkLogins') || 0,
|
ASK_LOGINS => $req->param('checkLogins') || 0,
|
||||||
|
ASK_STAYCONNECTED => $req->param('stayconnected') || 0,
|
||||||
CONFIRMKEY => $self->stamp(),
|
CONFIRMKEY => $self->stamp(),
|
||||||
LIST => $req->data->{list} || [],
|
LIST => $req->data->{list} || [],
|
||||||
(
|
(
|
||||||
|
@ -377,6 +379,7 @@ sub display {
|
||||||
DONT_STORE_PASSWORD => $self->conf->{browsersDontStorePassword},
|
DONT_STORE_PASSWORD => $self->conf->{browsersDontStorePassword},
|
||||||
CHECK_LOGINS => $self->conf->{portalCheckLogins},
|
CHECK_LOGINS => $self->conf->{portalCheckLogins},
|
||||||
ASK_LOGINS => $req->param('checkLogins') || 0,
|
ASK_LOGINS => $req->param('checkLogins') || 0,
|
||||||
|
ASK_STAYCONNECTED => $req->param('stayconnected') || 0,
|
||||||
DISPLAY_RESETPASSWORD => $self->conf->{portalDisplayResetPassword},
|
DISPLAY_RESETPASSWORD => $self->conf->{portalDisplayResetPassword},
|
||||||
DISPLAY_REGISTER => $self->conf->{portalDisplayRegister},
|
DISPLAY_REGISTER => $self->conf->{portalDisplayRegister},
|
||||||
DISPLAY_UPDATECERTIF =>
|
DISPLAY_UPDATECERTIF =>
|
||||||
|
|
|
@ -19,8 +19,8 @@ our @pList = (
|
||||||
portalStatus => '::Plugins::Status',
|
portalStatus => '::Plugins::Status',
|
||||||
cda => '::Plugins::CDA',
|
cda => '::Plugins::CDA',
|
||||||
notification => '::Plugins::Notifications',
|
notification => '::Plugins::Notifications',
|
||||||
portalCheckLogins => '::Plugins::History',
|
|
||||||
stayConnected => '::Plugins::StayConnected',
|
stayConnected => '::Plugins::StayConnected',
|
||||||
|
portalCheckLogins => '::Plugins::History',
|
||||||
bruteForceProtection => '::Plugins::BruteForceProtection',
|
bruteForceProtection => '::Plugins::BruteForceProtection',
|
||||||
grantSessionRules => '::Plugins::GrantSession',
|
grantSessionRules => '::Plugins::GrantSession',
|
||||||
upgradeSession => '::Plugins::Upgrade',
|
upgradeSession => '::Plugins::Upgrade',
|
||||||
|
|
|
@ -56,9 +56,17 @@ sub init {
|
||||||
sub newDevice {
|
sub newDevice {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
|
|
||||||
|
my $checkLogins = $req->param('checkLogins');
|
||||||
|
$self->logger->debug("StayConnected: checkLogins set") if $checkLogins;
|
||||||
|
|
||||||
if ( $req->param('stayconnected') ) {
|
if ( $req->param('stayconnected') ) {
|
||||||
my $token = $self->ott->createToken( {
|
my $token = $self->ott->createToken( {
|
||||||
name => $req->sessionInfo->{ $self->conf->{whatToTrace} }
|
name => $req->sessionInfo->{ $self->conf->{whatToTrace} },
|
||||||
|
(
|
||||||
|
$checkLogins
|
||||||
|
? ( history => $req->sessionInfo->{_loginHistory} )
|
||||||
|
: ()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$req->response(
|
$req->response(
|
||||||
|
@ -69,6 +77,7 @@ sub newDevice {
|
||||||
URL => $req->urldc,
|
URL => $req->urldc,
|
||||||
TOKEN => $token,
|
TOKEN => $token,
|
||||||
ACTION => '/registerbrowser',
|
ACTION => '/registerbrowser',
|
||||||
|
CHECKLOGINS => $checkLogins
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -109,6 +118,7 @@ sub storeBrowser {
|
||||||
max_age => 2592000,
|
max_age => 2592000,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$req->sessionInfo->{_loginHistory} = $tmp->{history} if exists $tmp->{history};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$self->logger->warn("Browser hasn't return fingerprint");
|
$self->logger->warn("Browser hasn't return fingerprint");
|
||||||
|
@ -128,8 +138,8 @@ sub storeBrowser {
|
||||||
$self->userLogger->error('StayConnected called without token');
|
$self->userLogger->error('StayConnected called without token');
|
||||||
}
|
}
|
||||||
|
|
||||||
# Deliver cookie llngbrowser
|
# Return cookie llngconnexion
|
||||||
return $self->p->do( $req, [ sub { PE_OK } ] );
|
return $self->p->do( $req, [ @{ $self->p->endAuth }, sub { PE_OK } ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for:
|
# Check for:
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<input type="checkbox" id="stayconnected" name="stayconnected" aria-describedby="stayConnectedLabel" />
|
<input type="checkbox" id="stayconnected" name="stayconnected" aria-describedby="stayConnectedLabel" <TMPL_IF NAME="ASK_STAYCONNECTED">checked</TMPL_IF> />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="form-control">
|
<p class="form-control">
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<p>Please wait...</p>
|
<p>Please wait...</p>
|
||||||
<form id="form" action="<TMPL_VAR NAME="ACTION">" method="post">
|
<form id="form" action="<TMPL_VAR NAME="ACTION">" method="post">
|
||||||
<input type="hidden" name="token" value="<TMPL_VAR NAME="TOKEN">" />
|
<input type="hidden" name="token" value="<TMPL_VAR NAME="TOKEN">" />
|
||||||
|
<input type="hidden" id="checkLogins" name="checkLogins" value="<TMPL_VAR NAME="CHECKLOGINS">">
|
||||||
<input type="hidden" name="url" value="<TMPL_VAR NAME="URL">" />
|
<input type="hidden" name="url" value="<TMPL_VAR NAME="URL">" />
|
||||||
<input type="hidden" name="fg" id="fg" value="" />
|
<input type="hidden" name="fg" id="fg" value="" />
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -40,7 +40,7 @@ ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
|
||||||
or print STDERR Dumper( $res->[2]->[0] );
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
count(1);
|
count(1);
|
||||||
ok( $res->[2]->[0] =~ /trspan="lastLogins"/, 'History found' )
|
ok( $res->[2]->[0] =~ /trspan="lastLogins"/, 'History found' )
|
||||||
or explain( $res->[2]->[0], 'trspan="noHistory"' );
|
or explain( $res->[2]->[0], 'trspan="lastLogins"' );
|
||||||
my @c = ( $res->[2]->[0] =~ /<td>127.0.0.1/gs );
|
my @c = ( $res->[2]->[0] =~ /<td>127.0.0.1/gs );
|
||||||
|
|
||||||
# History with 1 successLogin
|
# History with 1 successLogin
|
||||||
|
|
|
@ -11,6 +11,8 @@ my $client = LLNG::Manager::Test->new( {
|
||||||
logLevel => 'error',
|
logLevel => 'error',
|
||||||
useSafeJail => 1,
|
useSafeJail => 1,
|
||||||
stayConnected => 1,
|
stayConnected => 1,
|
||||||
|
loginHistoryEnabled => 1,
|
||||||
|
portalMainLogo => 'common/logos/logo_llng_old.png',
|
||||||
accept => 'text/html',
|
accept => 'text/html',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,11 +107,57 @@ ok(
|
||||||
),
|
),
|
||||||
'Post bad fingerprint'
|
'Post bad fingerprint'
|
||||||
);
|
);
|
||||||
count(1);
|
|
||||||
( $host, $url, $query ) = expectForm($res);
|
( $host, $url, $query ) = expectForm($res);
|
||||||
ok( $query =~ /user/, ' Get login form' );
|
ok( $query =~ /user/, ' Get login form' );
|
||||||
count(1);
|
count(2);
|
||||||
|
|
||||||
|
# Try to authenticate with history
|
||||||
|
# --------------------------------
|
||||||
|
ok(
|
||||||
|
$res = $client->_post(
|
||||||
|
'/',
|
||||||
|
IO::String->new(
|
||||||
|
'user=dwho&password=dwho&stayconnected=1&checkLogins=1'),
|
||||||
|
length => 53
|
||||||
|
),
|
||||||
|
'Auth query'
|
||||||
|
);
|
||||||
|
count(1);
|
||||||
|
$id = expectCookie($res);
|
||||||
|
( $host, $url, $query ) =
|
||||||
|
expectForm( $res, undef, '/registerbrowser', 'fg', 'token' );
|
||||||
|
|
||||||
|
# Push fingerprint
|
||||||
|
$query =~ s/fg=/fg=aaa/;
|
||||||
|
ok(
|
||||||
|
$res = $client->_post(
|
||||||
|
'/registerbrowser',
|
||||||
|
IO::String->new($query),
|
||||||
|
length => length($query),
|
||||||
|
cookie => "lemonldap=$id",
|
||||||
|
accept => 'text/html',
|
||||||
|
),
|
||||||
|
'Post fingerprint'
|
||||||
|
);
|
||||||
|
count(1);
|
||||||
|
$cid = expectCookie( $res, 'llngconnexion' );
|
||||||
|
|
||||||
|
ok( $res->[2]->[0] =~ qr%<img src="/static/common/logos/logo_llng_old.png"%,
|
||||||
|
'Found custom Main Logo' )
|
||||||
|
or print STDERR Dumper( $res->[2]->[0] );
|
||||||
|
ok( $res->[2]->[0] =~ /trspan="lastLogins"/, 'History found' )
|
||||||
|
or explain( $res->[2]->[0], 'trspan="lastLogins"' );
|
||||||
|
my @c = ( $res->[2]->[0] =~ /<td>127.0.0.1/gs );
|
||||||
|
|
||||||
|
# History with 2 successLogins
|
||||||
|
ok( @c == 2, " -> Two entries found" )
|
||||||
|
or explain( $res->[2]->[0], 'Two entries found' );
|
||||||
|
ok( $res = $client->_get( '/', cookie => "lemonldap=$cid" ),
|
||||||
|
'Verify connection' );
|
||||||
|
count(4);
|
||||||
|
expectOK($res);
|
||||||
|
|
||||||
|
$client->logout($cid);
|
||||||
clean_sessions();
|
clean_sessions();
|
||||||
|
|
||||||
done_testing( count() );
|
done_testing( count() );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user