diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm index 2c4340340..a60a53f3a 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm @@ -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}; diff --git a/lemonldap-ng-portal/t/04-language-selection.t b/lemonldap-ng-portal/t/04-language-selection.t new file mode 100644 index 000000000..b697daccf --- /dev/null +++ b/lemonldap-ng-portal/t/04-language-selection.t @@ -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() ); diff --git a/lemonldap-ng-portal/t/59-Double-cookies-Refresh-and-Logout.t b/lemonldap-ng-portal/t/59-Double-cookies-Refresh-and-Logout.t index e74a6beeb..486266d6a 100644 --- a/lemonldap-ng-portal/t/59-Double-cookies-Refresh-and-Logout.t +++ b/lemonldap-ng-portal/t/59-Double-cookies-Refresh-and-Logout.t @@ -114,14 +114,12 @@ ok( ), 'POST checkuser' ); -my @attributes = map /(.+)?<\/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>/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>/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>/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 diff --git a/lemonldap-ng-portal/t/68-Impersonation-with-doubleCookies.t b/lemonldap-ng-portal/t/68-Impersonation-with-doubleCookies.t index 43c468c36..7056cca88 100644 --- a/lemonldap-ng-portal/t/68-Impersonation-with-doubleCookies.t +++ b/lemonldap-ng-portal/t/68-Impersonation-with-doubleCookies.t @@ -324,25 +324,22 @@ ok( $res->[2]->[0] =~ m%rtyler/dwho%, or explain( $res->[2]->[0], 'Found rtyler/dwo' ); count(16); -my @attributes = map /(.+)?<\/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>/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(); diff --git a/lemonldap-ng-portal/t/68-Impersonation.t b/lemonldap-ng-portal/t/68-Impersonation.t index 933359905..0625264a7 100644 --- a/lemonldap-ng-portal/t/68-Impersonation.t +++ b/lemonldap-ng-portal/t/68-Impersonation.t @@ -322,19 +322,16 @@ ok( $res->[2]->[0] =~ m%rtyler/dwho%, or explain( $res->[2]->[0], 'Found rtyler/dwo' ); count(16); -my @attributes = map /(.+)?<\/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>/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();