Update unit tests (#2611)

This commit is contained in:
Maxime Besson 2021-09-10 12:22:30 +02:00
parent 7dc4fc54e4
commit 83e95cd053
4 changed files with 148 additions and 6 deletions

View File

@ -170,6 +170,7 @@ sub getDisplayType {
sub setSecurity {
my ( $self, $req ) = @_;
return if $req->data->{skipToken};
# If captcha is enable, prepare it
if ( $self->captcha ) {

View File

@ -17,11 +17,11 @@ my $debug = 'error';
# Initialization
my $op = LLNG::Manager::Test->new( {
ini => {
logLevel => $debug,
domain => 'op.com',
portal => 'http://auth.op.com',
macros => {
logLevel => $debug,
domain => 'op.com',
portal => 'http://auth.op.com',
requireToken => 1,
macros => {
gender => '"32"',
_whatToTrace => '$uid',
nickname => '"froggie; frenchie"',

View File

@ -0,0 +1,126 @@
use Test::More;
use strict;
use IO::String;
use MIME::Base64;
use JSON;
require 't/test-lib.pm';
my $res;
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
useSafeJail => 1,
requireToken => 1,
restAuthServer => 1,
restPasswordServer => 1,
authentication => 'Combination',
userDB => 'Same',
combination => '[K,Dm] or [Dm]',
combModules => {
K => {
for => 1,
type => 'Kerberos',
},
Dm => {
for => 0,
type => 'Demo',
},
},
krbKeytab => '/etc/keytab',
krbByJs => 1,
}
}
);
# Test pwdConfirm endpoint
my $res = expectJSON(
postJSON(
$client,
"/proxy/pwdConfirm",
{
user => "dwho",
password => "dwho",
}
)
);
is( $res->{result}, 1, "Correct password is accepted" );
count(1);
my $res = expectJSON(
postJSON(
$client,
"/proxy/pwdConfirm",
{
user => "waldo",
password => "dwho",
}
)
);
is( $res->{result}, 0, "Incorrect user is rejected" );
count(1);
my $res = expectJSON(
postJSON(
$client,
"/proxy/pwdConfirm",
{
user => "dwho",
password => "wrongpass",
}
)
);
is( $res->{result}, 0, "Incorrect password is rejected" );
count(1);
# Test getUser endpoint
# Existing user
my $res = expectJSON(
postJSON(
$client,
"/proxy/getUser",
{
user => "dwho",
}
)
);
is( $res->{result}, 1, "Correct result" );
is( $res->{info}->{cn}, "Doctor Who", "Correct attributes" );
is( $res->{info}->{_whatToTrace}, "dwho", "Correct macro" );
count(3);
# Missing user
my $res = expectJSON(
postJSON(
$client,
"/proxy/getUser",
{
user => "notfound",
}
)
);
is( $res->{result}, 0, "Correct result" );
is( $res->{info}, undef, "No attributes" );
count(2);
clean_sessions();
done_testing( count() );
sub postJSON {
my ( $portal, $url, $payload ) = @_;
my $string_payload = to_json($payload);
return $portal->_post(
$url,
IO::String->new($string_payload),
accept => 'application/json',
type => 'application/json',
length => length($string_payload)
);
}

View File

@ -8,10 +8,25 @@ my $res;
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
authentication => 'Demo',
requireToken => 1,
checkStateSecret => 'x',
checkState => 1,
authentication => 'Combination',
userDB => 'Same',
combination => '[K,Dm] or [Dm]',
combModules => {
K => {
for => 1,
type => 'Kerberos',
},
Dm => {
for => 0,
type => 'Demo',
},
},
krbKeytab => '/etc/keytab',
krbByJs => 1,
}
}
);