You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.4 KiB

#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use LDV::LDAP;
use File::Slurp;
use Data::Dumper;
use Test::More tests => 13;
my $hash = read_file('conf/ldv.conf');
my $config = eval "$hash";
SKIP: {
skip "Can't load config", 13 unless (ref($config) eq 'HASH');
my $ldap = LDV::LDAP->new($config->{ldap});
isa_ok($ldap, "LDV::LDAP", "LDV::LDAP->new");
can_ok($ldap, qw(create delete get update));
is($ldap->get("test20"), undef, "get non-existing user");
is($ldap->create("test20"), undef, "creating user");
my $attrs = {uid => 'test20', cn => 'just', sn => 'created'};
is_deeply($ldap->get("test20"), $attrs, "getting data of newly created user");
$attrs = {uid => 'test20', cn => 'Полиграф', sn => 'Шариков'};
is($ldap->update("test20", $attrs), undef, "updating user data");
is($ldap->update("test20", {mail => 'abigvalg@example.com'}), undef, "updating user data");
$attrs->{mail} = 'abigvalg@example.com';
is_deeply($ldap->get("test20"), $attrs, "getting data of updated user");
my $pass = '{SSHA}K/LOxZB1fnNtQuRc1mApdoL7CGR2Akn/'; # 'test'
is($ldap->update("test20", {userPassword => $pass}), undef, "updating user password");
is($ldap->auth("test20", "test"), 1, "check auth success");
is($ldap->auth("test20", "test1"), undef, "check auth falure (wrong pass)");
is($ldap->auth("test20", undef), undef, "check auth falure (empty pass)");
is($ldap->delete("test20"), undef, "deleting user");
};
exit 0;