Append Choice unit tests (#1976)
This commit is contained in:
parent
c0f71ee0f1
commit
0b750fb6cc
|
@ -676,6 +676,8 @@ t/68-ContextSwitching-with-Logout.t
|
|||
t/68-ContextSwitching-with-TOTP-and-Notification.t
|
||||
t/68-ContextSwitching-with-UnrestrictedUser.t
|
||||
t/68-ContextSwitching.t
|
||||
t/68-FindUser-with-BadChoice-and-token.t
|
||||
t/68-FindUser-with-Choice-and-token.t
|
||||
t/68-FindUser-with-DBI.t
|
||||
t/68-FindUser-with-Demo-and-token.t
|
||||
t/68-FindUser-with-Demo.t
|
||||
|
|
|
@ -119,10 +119,10 @@ sub checkChoice {
|
|||
|
||||
# Check with other methods
|
||||
$name ||=
|
||||
$req->param( $self->conf->{authChoiceParam} )
|
||||
$req->data->{findUserChoice}
|
||||
|| $req->param( $self->conf->{authChoiceParam} )
|
||||
|| $req->userData->{_choice}
|
||||
|| $req->sessionInfo->{_choice}
|
||||
|| $req->data->{findUserChoice}
|
||||
or return 0;
|
||||
$self->logger->debug("Choice $name selected");
|
||||
}
|
||||
|
|
77
lemonldap-ng-portal/t/68-FindUser-with-BadChoice-and-token.t
Normal file
77
lemonldap-ng-portal/t/68-FindUser-with-BadChoice-and-token.t
Normal file
|
@ -0,0 +1,77 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use JSON;
|
||||
use IO::String;
|
||||
|
||||
require 't/test-lib.pm';
|
||||
|
||||
my $res;
|
||||
my $json;
|
||||
my $client = LLNG::Manager::Test->new( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
authentication => 'Choice',
|
||||
userDB => 'Same',
|
||||
passwordDB => 'Choice',
|
||||
authChoiceModules => {
|
||||
'1_demo' => 'Demo;Demo;Null',
|
||||
'2_ssl' => 'SSL;Demo;Null',
|
||||
},
|
||||
authChoiceFindUser => '1_dem',
|
||||
useSafeJail => 1,
|
||||
requireToken => 1,
|
||||
findUser => 1,
|
||||
impersonationRule => 1,
|
||||
findUserSearchingAttributes =>
|
||||
{ uid => 'Login', guy => 'Kind', cn => 'Name' },
|
||||
findUserExcludingAttributes =>
|
||||
{ type => 'mutant', uid => 'rtyler' },
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
## Simple access
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
|
||||
my ( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'user', 'password', 'spoofId', 'token' );
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'uid', 'guy', 'cn', 'token' );
|
||||
my @form = ( $res->[2]->[0] =~ m#<form.*?</form>#sg );
|
||||
ok( @form == 3, 'Display 3 forms' );
|
||||
count(2);
|
||||
|
||||
$query =~ s/uid=/uid=dwho/;
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/finduser', IO::String->new($query),
|
||||
accept => 'text/html',
|
||||
length => length($query)
|
||||
),
|
||||
'Post FindFuser request'
|
||||
);
|
||||
ok(
|
||||
$res->[2]->[0] =~
|
||||
m%<input id="spoofIdfield" name="spoofId" type="text" class="form-control" value="" autocomplete="off"%,
|
||||
'value=""'
|
||||
) or explain( $res->[2]->[0], 'value=""' );
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'user', 'guy', 'cn', 'token' );
|
||||
$query =~ s/user=/user=rtyler/;
|
||||
$query =~ s/password=/password=rtyler/;
|
||||
$query =~ s/2_ssl/1_demo/;
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/',
|
||||
IO::String->new($query),
|
||||
length => length($query),
|
||||
accept => 'text/html',
|
||||
),
|
||||
'Auth query'
|
||||
);
|
||||
my $id = expectCookie($res);
|
||||
expectRedirection( $res, 'http://auth.example.com/' );
|
||||
$client->logout($id);
|
||||
count(3);
|
||||
|
||||
clean_sessions();
|
||||
done_testing( count() );
|
80
lemonldap-ng-portal/t/68-FindUser-with-Choice-and-token.t
Normal file
80
lemonldap-ng-portal/t/68-FindUser-with-Choice-and-token.t
Normal file
|
@ -0,0 +1,80 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use JSON;
|
||||
use IO::String;
|
||||
|
||||
require 't/test-lib.pm';
|
||||
|
||||
my $res;
|
||||
my $json;
|
||||
my $client = LLNG::Manager::Test->new( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
authentication => 'Choice',
|
||||
userDB => 'Same',
|
||||
passwordDB => 'Choice',
|
||||
authChoiceModules => {
|
||||
'1_demo' => 'Demo;Demo;Null',
|
||||
'2_ssl' => 'SSL;Demo;Null',
|
||||
},
|
||||
authChoiceFindUser => '1_demo',
|
||||
useSafeJail => 1,
|
||||
requireToken => 1,
|
||||
findUser => 1,
|
||||
impersonationRule => 1,
|
||||
findUserSearchingAttributes =>
|
||||
{ uid => 'Login', guy => 'Kind', cn => 'Name' },
|
||||
findUserExcludingAttributes =>
|
||||
{ type => 'mutant', uid => 'rtyler' },
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
## Simple access
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
|
||||
my ( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'user', 'password', 'spoofId', 'token' );
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'uid', 'guy', 'cn', 'token' );
|
||||
my @form = ( $res->[2]->[0] =~ m#<form.*?</form>#sg );
|
||||
ok( @form == 3, 'Display 3 forms' );
|
||||
count(2);
|
||||
|
||||
$query =~ s/uid=/uid=dwho/;
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/finduser', IO::String->new($query),
|
||||
accept => 'application/json',
|
||||
length => length($query)
|
||||
),
|
||||
'Post FindFuser request'
|
||||
);
|
||||
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
||||
or print STDERR "$@\n" . Dumper($res);
|
||||
ok( $json->{user} eq 'dwho', ' Good user' )
|
||||
or explain( $json, 'user => dwho' );
|
||||
count(3);
|
||||
|
||||
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, '#', undef, 'user', 'guy', 'cn', 'token' );
|
||||
Time::Fake->offset("+150s");
|
||||
$query =~ s/uid=/uid=dwho/;
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/finduser', IO::String->new($query),
|
||||
accept => 'application/json',
|
||||
length => length($query)
|
||||
),
|
||||
'Post expired FindFuser request'
|
||||
);
|
||||
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
||||
or print STDERR "$@\n" . Dumper($res);
|
||||
ok( $json->{error} == 82, ' Token expired' )
|
||||
or explain( $json, 'Token expired' );
|
||||
ok( $json->{result} == 0, ' result => 0' )
|
||||
or explain( $json, 'Result => 0' );
|
||||
count(5);
|
||||
|
||||
clean_sessions();
|
||||
done_testing( count() );
|
|
@ -100,7 +100,7 @@ ok(
|
|||
accept => 'application/json',
|
||||
length => length($query)
|
||||
),
|
||||
'Post FindFuser request without token'
|
||||
'Post FindFuser request with token'
|
||||
);
|
||||
my $id = expectCookie($res);
|
||||
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
|
||||
|
|
Loading…
Reference in New Issue
Block a user