lemonldap-ng/lemonldap-ng-portal/t/21-Auth-LDAP-attributes.t

89 lines
2.8 KiB
Perl
Raw Permalink Normal View History

2017-03-02 07:35:15 +01:00
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
2020-12-07 17:49:09 +01:00
my $maintests = 11;
2017-03-02 07:35:15 +01:00
SKIP: {
2018-02-08 21:55:21 +01:00
skip 'LLNGTESTLDAP is not set', $maintests unless ( $ENV{LLNGTESTLDAP} );
2017-03-02 07:35:15 +01:00
require 't/test-ldap.pm';
2019-02-07 09:27:56 +01:00
my $client = LLNG::Manager::Test->new( {
2017-03-02 07:35:15 +01:00
ini => {
2017-03-03 08:41:59 +01:00
logLevel => 'error',
2017-03-02 07:35:15 +01:00
useSafeJail => 1,
authentication => 'LDAP',
portal => 'http://auth.example.com/',
userDB => 'Same',
passwordDB => 'LDAP',
portalRequireOldPassword => 1,
ldapServer => 'ldap://127.0.0.1:19389/',
2017-03-03 08:41:59 +01:00
ldapBase => 'ou=users,dc=example,dc=com',
2017-03-02 07:35:15 +01:00
managerDn => 'cn=admin,dc=example,dc=com',
managerPassword => 'admin',
restSessionServer => 1,
ldapExportedVars => {
2020-12-07 17:49:09 +01:00
cn => 'cn',
displayName => 'displayName',
roomNumber => 'roomNumber',
2017-03-02 07:35:15 +01:00
},
}
}
);
2022-02-16 17:43:29 +01:00
# my $postString = 'user='
# . ( $ENV{LDAPACCOUNT} || 'dwho' )
# . '&password='
# . ( $ENV{LDAPPWD} || 'dwho' );
2017-03-02 07:35:15 +01:00
# Try yo authenticate
# -------------------
# 1- Characters available in ISO and UTF-8
ok(
$res = $client->_post(
'/', IO::String->new('user=french&password=french'),
length => 27
),
'Auth query'
);
expectOK($res);
my $id = expectCookie($res);
ok( $res = $client->_get("/sessions/global/$id"), 'Get UTF-8' );
expectOK($res);
ok( $res = eval { JSON::from_json( $res->[2]->[0] ) }, ' GET JSON' )
or print STDERR $@;
ok( $res->{cn} eq 'Frédéric Accents', 'UTF-8 values' )
or explain( $res, 'cn => Frédéric Accents' );
2020-12-07 17:49:09 +01:00
ok( exists $res->{displayName}, 'displayName is present' );
2017-03-02 07:35:15 +01:00
# 2- Characters UTF-8 only
ok(
$res = $client->_post(
'/', IO::String->new('user=russian&password=russian'),
length => 29
),
'Auth query'
);
expectOK($res);
$id = expectCookie($res);
ok( $res = $client->_get("/sessions/global/$id"), 'Get UTF-8' );
expectOK($res);
ok( $res = eval { JSON::from_json( $res->[2]->[0] ) }, ' GET JSON' )
or print STDERR $@;
ok( $res->{cn} eq 'Русский', 'UTF-8 values' )
or explain( $res, 'cn => Русский' );
2020-12-07 17:49:09 +01:00
is( $res->{roomNumber}, 0, 'attribute with value of 0 present' );
ok( !exists $res->{displayName}, 'missing LDAP attribute is not stored' );
2017-03-02 07:35:15 +01: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};
2017-03-02 07:35:15 +01:00
done_testing( count() );