Commit 159eb4a6 authored by Yadd's avatar Yadd
Browse files

Enable logout (#LEMONDAP-595)

parent 258fcd7f
......@@ -547,8 +547,8 @@ sub abort {
## @rmethod protected void localUnlog()
# Delete current user from local cache entry.
sub localUnlog {
my $class = shift;
if ( my $id = $class->fetchId ) {
my ( $class, $id ) = @_;
if ( $id //= $class->fetchId ) {
# Delete thread datas
if ( $id eq $class->datas->{_session_id} ) {
......
......@@ -6,7 +6,7 @@ package Lemonldap::NG::Portal::Auth::AD;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants
qw(PE_OK PE_PP_PASSWORD_EXPIRED PE_PP_CHANGE_AFTER_RESET);
qw(PE_OK PE_PP_PASSWORD_EXPIRED PE_PP_CHANGE_AFTER_RESET PM_PP_EXP_WARNING);
our $VERSION = '2.0.0';
......
......@@ -6,7 +6,7 @@ use strict;
use Net::LDAP; #inherits
use Net::LDAP::Util qw(escape_filter_value);
use base qw(Net::LDAP);
use Lemonldap::NG::Portal::Main::Constants;
use Lemonldap::NG::Portal::Main::Constants ':all';
use Encode;
use Unicode::String qw(utf8);
use Scalar::Util 'weaken';
......
......@@ -47,6 +47,7 @@ sub restoreArgs {
sub importHandlerDatas {
my ( $self, $req ) = @_;
$req->{sessionInfo} = HANDLER->datas;
$req->id( $req->sessionInfo->{_session_id} );
PE_OK;
}
......@@ -72,8 +73,11 @@ sub controlUrl {
}
# For logout request, test if Referer comes from an authorizated site
my $tmp =
( $req->param('logout') ? $ENV{HTTP_REFERER} : $req->datas->{urldc} );
my $tmp = (
$req->param('logout')
? $ENV{HTTP_REFERER}
: $req->datas->{urldc}
);
# XSS attack
if (
......@@ -127,6 +131,7 @@ sub deleteSession {
return PE_ERROR;
}
else {
HANDLER->localUnlog( $req->id );
$self->lmLog( "Session $req->{id} deleted from global storage",
'debug' );
}
......
......@@ -225,8 +225,6 @@ sub getApacheSession {
}
unless ($noInfo) {
$self->setApacheUser( $as->data->{ $self->{whatToTrace} } )
if ($id);
$self->{id} = $as->id;
}
return $as;
......
......@@ -79,6 +79,9 @@ ok( $hdrs{'Content-Type'} eq 'text/html', 'Reponse is HTML' )
or explain( \%hdrs, 'Content-Type => "text/html"' );
count(4);
# Test logout
logout($id);
#print STDERR Dumper($res);
clean_sessions();
......
......@@ -43,6 +43,7 @@ SKIP: {
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
clean_sessions();
}
......
......@@ -43,6 +43,7 @@ SKIP: {
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
clean_sessions();
}
......
......@@ -42,8 +42,7 @@ SKIP: {
$res = &client->_post(
'/', '',
IO::String->new('user=dwho&password=dwho'),
'application/x-www-form-urlencoded',
23
'application/x-www-form-urlencoded', 23
),
'Auth query'
);
......@@ -53,6 +52,7 @@ SKIP: {
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
logout($id);
clean_sessions();
}
count(3);
......
......@@ -17,7 +17,8 @@ init(
ok( $res = &client->_get('/'), 'Auth query' );
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
ok( $cookies->{lemonldap}, 'Get cookie' )
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
clean_sessions();
......
......@@ -17,7 +17,8 @@ init(
ok( $res = &client->_get( '/', remote_user => 'dwho' ), 'Auth query' );
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
my $cookies = getCookies($res);
ok( $cookies->{lemonldap}, 'Get cookie' )
my $id;
ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
clean_sessions();
......
......@@ -44,11 +44,35 @@ sub explain {
print STDERR "Expect $ref, get $get\n";
}
sub logout {
my ($id) = @_;
my $res;
ok(
$res = &client->_get(
'/',
query => 'logout',
cookie => "lemonldap=$id",
accept => 'text/html'
),
'Logout'
);
ok( $res->[0] == 200, 'Response is 200' ) or explain( $res->[0], 200 );
ok( $res = &client->_get( '/', cookie => "lemonldap=$id" ),
'Disconnect request' );
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
count(4);
}
sub clean_sessions {
opendir D, 't/sessions' or die $!;
foreach ( grep { /^[^\.]/ } readdir(D) ) {
unlink "t/sessions/$_", "t/sessions/lock/Apache-Session-$_.lock";
}
opendir D, 't/sessions/lock' or die $!;
foreach ( grep { /^[^\.]/ } readdir(D) ) {
unlink "t/sessions/lock/$_";
}
}
sub getCookies {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment