2016-05-12 21:02:48 +02:00
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
|
|
|
|
my $res;
|
2018-02-08 21:55:21 +01:00
|
|
|
my $maintests = 3;
|
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} );
|
2017-03-01 23:18:00 +01:00
|
|
|
require 't/test-ldap.pm';
|
2016-05-12 21:02:48 +02:00
|
|
|
|
2016-11-14 13:34:46 +01:00
|
|
|
my $client = LLNG::Manager::Test->new(
|
2016-05-12 21:02:48 +02:00
|
|
|
{
|
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',
|
2017-03-02 07:13:52 +01:00
|
|
|
portalRequireOldPassword => 1,
|
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 yo authenticate
|
|
|
|
# -------------------
|
|
|
|
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() );
|