Add simple test for auth presistent data (#1461)
parent
55cd51f27f
commit
4074b1b482
@ -0,0 +1,53 @@ |
||||
use Test::More; |
||||
use strict; |
||||
use IO::String; |
||||
|
||||
require 't/test-lib.pm'; |
||||
|
||||
my $res; |
||||
my $tmp; |
||||
|
||||
my $client = LLNG::Manager::Test->new( |
||||
{ |
||||
ini => { |
||||
logLevel => 'error', |
||||
customPlugins => 't::pdata', |
||||
} |
||||
} |
||||
); |
||||
|
||||
# Two simple access to see if pdata is set and restored |
||||
ok( $res = $client->_get( '/', ), 'Simple access' ); |
||||
$tmp = expectCookie( $res, 'lemonldappdata' ); |
||||
ok( $tmp eq '{"mytest":1}', 'Pdata is {"mytest":1}' ) |
||||
or explain( $tmp, '{"mytest":1}' ); |
||||
count(2); |
||||
|
||||
ok( $res = $client->_get( '/', cookie => 'lemonldappdata={"mytest":1}', ), |
||||
'Second simple access' ); |
||||
$tmp = expectCookie( $res, 'lemonldappdata' ); |
||||
ok( $tmp eq '{"mytest":2}', 'Pdata is {"mytest":2}' ) |
||||
or explain( $tmp, '{"mytest":1}' ); |
||||
count(2); |
||||
|
||||
# Try to authenticate |
||||
# ------------------- |
||||
ok( |
||||
$res = $client->_post( |
||||
'/', |
||||
IO::String->new('user=dwho&password=dwho'), |
||||
cookie => 'lemonldappdata={"mytest":1}', |
||||
length => 23 |
||||
), |
||||
'Auth query' |
||||
); |
||||
count(1); |
||||
expectOK($res); |
||||
|
||||
$tmp = expectCookie( $res, 'lemonldappdata' ); |
||||
ok( $tmp eq '', 'Pdata is ""' ) or explain( $res, 'lemonldappdata=;' ); |
||||
count(1); |
||||
|
||||
clean_sessions(); |
||||
|
||||
done_testing( count() ); |
@ -0,0 +1,20 @@ |
||||
package t::pdata; |
||||
|
||||
use strict; |
||||
use Mouse; |
||||
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK); |
||||
|
||||
extends 'Lemonldap::NG::Portal::Main::Plugin'; |
||||
|
||||
sub init {1} |
||||
|
||||
use constant beforeAuth => 'insert'; |
||||
|
||||
sub insert { |
||||
my($self,$req) = @_; |
||||
$req->pdata->{mytest} ||= 0; |
||||
$req->pdata->{mytest}++; |
||||
return PE_OK; |
||||
} |
||||
|
||||
1; |
Loading…
Reference in new issue