Merge remote-tracking branch 'maxbes/issue1764-langsession' into v2.0

This commit is contained in:
Xavier Guimard 2019-06-13 09:59:33 +02:00
commit 288fe5159c
5 changed files with 113 additions and 50 deletions

View File

@ -356,6 +356,9 @@ sub setSessionInfo {
if $self->conf->{timeoutActivity};
}
# Currently selected language
$req->{sessionInfo}->{_language} = $req->cookies->{llnglanguage} || 'en';
# Store URL origin in session
$req->{sessionInfo}->{_url} = $req->{urldc};

View File

@ -0,0 +1,70 @@
use Test::More;
use strict;
use IO::String;
BEGIN {
require 't/test-lib.pm';
}
my ( $client, $res, $id );
$client = LLNG::Manager::Test->new(
{ ini => { logLevel => 'error', restSessionServer => 1, useSafeJail => 1 }, } );
# Try to authenticate
# -------------------
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
length => 23
),
'Auth query without language cookie'
);
count(1);
expectOK($res);
$id = expectCookie($res);
ok( $res = $client->_get("/sessions/global/$id"), 'Get session' );
count(1);
expectOK($res);
ok( $res = eval { JSON::from_json( $res->[2]->[0] ) }, ' GET JSON' )
or print STDERR $@;
count(1);
ok( $res->{_language} eq 'en', 'Default value for _language' );
count(1);
# Test logout
$client->logout($id);
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=dwho'),
cookie => "llnglanguage=fr",
length => 23
),
'Auth query with language cookie'
);
count(1);
expectOK($res);
$id = expectCookie($res);
ok( $res = $client->_get("/sessions/global/$id"), 'Get session' );
count(1);
expectOK($res);
ok( $res = eval { JSON::from_json( $res->[2]->[0] ) }, ' GET JSON' )
or print STDERR $@;
count(1);
ok( $res->{_language} eq 'fr', 'Correct value for _language' );
count(1);
# Test logout
$client->logout($id);
#print STDERR Dumper($res);
clean_sessions();
done_testing( count() );

View File

@ -114,14 +114,12 @@ ok(
),
'POST checkuser'
);
my @attributes = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( scalar @attributes == 30, 'Found 30 attributes' )
or print STDERR "Missing attributes -> " . scalar @attributes;
ok( $attributes[12] eq '_updateTime', '_updateTime' )
or print STDERR Dumper( \@attributes );
ok( $attributes[13] =~ /^\d{14}$/, 'Timestamp found' )
or print STDERR Dumper( \@attributes );
count(4);
my %attributes = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( scalar keys %attributes == 16, 'Found 16 attributes' )
or print STDERR "Missing attributes -> " . scalar keys %attributes;
ok( $attributes{'_updateTime'} =~ /^\d{14}$/, 'Timestamp found' )
or print STDERR Dumper( \%attributes );
count(3);
diag 'Waiting';
sleep 3;
@ -184,17 +182,15 @@ ok(
),
'POST checkuser'
);
my @attributes2 = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( scalar @attributes2 == 30, 'Found 30 attributes' )
or print STDERR "Missing attributes -> " . scalar @attributes2;
ok( $attributes2[12] eq '_updateTime', '_updateTime' )
or print STDERR Dumper( \@attributes2 );
ok( $attributes2[13] =~ /^\d{14}$/, 'Timestamp found' )
or print STDERR Dumper( \@attributes2 );
count(4);
my %attributes2 = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( scalar keys %attributes2 == 16, 'Found 16 attributes' )
or print STDERR "Missing attributes -> " . scalar keys %attributes2;
ok( $attributes2{'_updateTime'} =~ /^\d{14}$/, 'Timestamp found' )
or print STDERR Dumper( \%attributes2 );
count(3);
ok( $attributes2[13] - $attributes[13] >= 3, '_updateTime has been updated' )
or print STDERR Dumper( \@attributes2 );
ok( $attributes2{_updateTime} - $attributes{_updateTime} >= 3, '_updateTime has been updated' )
or print STDERR Dumper( \%attributes2 );
count(1);
# Log out request

View File

@ -324,25 +324,22 @@ ok( $res->[2]->[0] =~ m%<td class="align-middle">rtyler/dwho</td>%,
or explain( $res->[2]->[0], 'Found rtyler/dwo' );
count(16);
my @attributes = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( scalar @attributes == 62, 'Found 61 attributes' )
or print STDERR ( @attributes < 62 )
? "Missing attributes -> " . scalar @attributes
: "Too much attributes -> " . scalar @attributes;
ok( $attributes[0] eq '_auth', '_auth' ) or print STDERR Dumper( \@attributes );
ok( $attributes[1] eq 'Demo', 'Demo' ) or print STDERR Dumper( \@attributes );
ok( $attributes[2] eq '_httpSession', '_httpSession' )
or print STDERR Dumper( \@attributes );
ok( $attributes[28] eq 'uid', 'uid' ) or print STDERR Dumper( \@attributes );
ok( $attributes[30] eq 'testPrefix__auth', 'testPrefix__auth' )
or print STDERR Dumper( \@attributes );
ok( $attributes[32] eq 'testPrefix__httpSession', 'testPrefix__httpSession' )
or print STDERR Dumper( \@attributes );
ok( $attributes[60] eq 'testPrefix_uid', 'testPrefix_uid' )
or print STDERR Dumper( \@attributes );
ok( $attributes[61] eq 'rtyler', 'rtyler' )
or print STDERR Dumper( \@attributes );
count(9);
my %attributes = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( scalar keys %attributes == 33, 'Found 33 attributes' )
or print STDERR ( keys %attributes < 33 )
? "Missing attributes -> " . scalar keys %attributes
: "Too much attributes -> " . scalar keys %attributes;
ok( $attributes{'_auth'} eq 'Demo', '_auth' ) or print STDERR Dumper( \%attributes );
ok( $attributes{'_httpSession'}, '_httpSession' )
or print STDERR Dumper( \%attributes );
ok( $attributes{'uid'}, 'uid' ) or print STDERR Dumper( \%attributes );
ok( $attributes{'testPrefix__auth'}, 'testPrefix__auth' )
or print STDERR Dumper( \%attributes );
ok( $attributes{'testPrefix__httpSession'}, 'testPrefix__httpSession' )
or print STDERR Dumper( \%attributes );
ok( $attributes{'testPrefix_uid'} eq 'rtyler', 'testPrefix_uid' )
or print STDERR Dumper( \%attributes );
count(7);
$client->logout($id);
clean_sessions();

View File

@ -322,19 +322,16 @@ ok( $res->[2]->[0] =~ m%<td class="align-middle">rtyler/dwho</td>%,
or explain( $res->[2]->[0], 'Found rtyler/dwo' );
count(16);
my @attributes = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( scalar @attributes == 58, 'Found 58 attributes' )
or print STDERR "Missing attributes -> " . scalar @attributes;
ok( $attributes[0] eq '_auth', '_auth' ) or print STDERR Dumper( \@attributes );
ok( $attributes[1] eq 'Demo', 'Demo' ) or print STDERR Dumper( \@attributes );
ok( $attributes[26] eq 'uid', 'uid' ) or print STDERR Dumper( \@attributes );
ok( $attributes[28] eq 'testPrefix__auth', 'testPrefix__auth' )
or print STDERR Dumper( \@attributes );
ok( $attributes[56] eq 'testPrefix_uid', 'testPrefix_uid' )
or print STDERR Dumper( \@attributes );
ok( $attributes[57] eq 'rtyler', 'rtyler' )
or print STDERR Dumper( \@attributes );
count(7);
my %attributes = map /<td class="text-left">(.+)?<\/td>/g, $res->[2]->[0];
ok( keys %attributes == 31, 'Found 31 attributes' )
or print STDERR "Missing attributes -> " . scalar %attributes;
ok( $attributes{'_auth'} eq 'Demo', '_auth' ) or print STDERR Dumper( \%attributes );
ok( $attributes{'uid'}, 'uid' ) or print STDERR Dumper( \%attributes );
ok( $attributes{'testPrefix__auth'}, 'testPrefix__auth' )
or print STDERR Dumper( \%attributes );
ok( $attributes{'testPrefix_uid'} eq 'rtyler', 'testPrefix_uid' )
or print STDERR Dumper( \%attributes );
count(5);
$client->logout($id);
clean_sessions();