lemonldap-ng/lemonldap-ng-portal/t/21-Auth-and-password-LDAP.t

94 lines
2.5 KiB
Perl
Raw Normal View History

2016-05-12 21:02:48 +02:00
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
my $maintests = 4;
2016-05-12 21:02:48 +02:00
SKIP: {
2018-02-08 21:55:21 +01:00
skip 'LLNGTESTLDAP is not set', $maintests unless ( $ENV{LLNGTESTLDAP} );
require 't/test-ldap.pm';
2016-05-12 21:02:48 +02:00
2019-02-07 09:27:56 +01:00
my $client = LLNG::Manager::Test->new( {
2016-11-14 13:34:46 +01:00
ini => {
2017-03-03 18:25:03 +01:00
logLevel => 'error',
useSafeJail => 1,
authentication => 'LDAP',
portal => 'http://auth.example.com/',
userDB => 'Same',
passwordDB => 'LDAP',
2020-04-27 22:13:21 +02:00
portalRequireOldPassword => '$uid eq "dwho"',
2017-03-03 18:25:03 +01:00
ldapServer => 'ldap://127.0.0.1:19389/',
ldapBase => 'ou=users,dc=example,dc=com',
managerDn => 'cn=admin,dc=example,dc=com',
managerPassword => 'admin',
2016-11-14 13:34:46 +01:00
}
2016-05-12 21:02:48 +02:00
}
);
my $postString = 'user='
. ( $ENV{LDAPACCOUNT} || 'dwho' )
. '&password='
. ( $ENV{LDAPPWD} || 'dwho' );
# Try to authenticate with
# the server temporarily offline (#2018)
# --------------------------------------
tempStopLdapServer();
ok(
$res = $client->_post(
'/', IO::String->new($postString),
length => length($postString)
),
'Auth query'
);
expectReject( $res, 401, 6 );
# Try to authenticate with the
# server back online
# ----------------------------
tempStartLdapServer();
2016-05-12 21:02:48 +02:00
ok(
2016-11-14 13:34:46 +01:00
$res = $client->_post(
'/', IO::String->new($postString),
2016-05-30 22:20:50 +02:00
length => length($postString)
2016-05-12 21:02:48 +02:00
),
'Auth query'
);
2016-12-23 07:41:03 +01:00
expectOK($res);
my $id = expectCookie($res);
2017-03-02 07:13:52 +01:00
ok(
$res = $client->_post(
'/',
IO::String->new(
'oldpassword=dwho&newpassword=test&confirmpassword=test'),
cookie => "lemonldap=$id",
accept => 'application/json',
length => 54
),
'Change password'
);
expectOK($res);
2016-11-14 13:34:46 +01:00
$client->logout($id);
2017-03-02 07:13:52 +01:00
ok(
$res = $client->_post(
'/',
IO::String->new('user=dwho&password=test'),
cookie => "lemonldap=$id",
length => 23
),
'Auth query with new password'
);
expectOK($res);
$id = expectCookie($res);
2016-05-12 21:02:48 +02:00
2017-03-02 07:13:52 +01:00
$client->logout($id);
2016-05-12 21:02:48 +02:00
clean_sessions();
}
2018-02-08 21:55:21 +01:00
count($maintests);
2017-03-02 16:56:24 +01:00
stopLdapServer() if $ENV{LLNGTESTLDAP};
2016-05-12 21:02:48 +02:00
done_testing( count() );