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.

47 lines
1.7 KiB

10 years ago
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use LDV::LDAP;
use File::Slurp;
10 years ago
use Data::Dumper;
10 years ago
use Test::More tests => 16;
10 years ago
my $hash = read_file('conf/ldv.conf');
my $config = eval "$hash";
SKIP: {
10 years ago
skip "Can't load config", 16 unless (ref($config) eq 'HASH');
10 years ago
my $ldap = LDV::LDAP->new($config->{ldap});
isa_ok($ldap, "LDV::LDAP", "LDV::LDAP->new");
can_ok($ldap, qw(create delete get update));
10 years ago
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");
10 years ago
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)");
10 years ago
is($ldap->chpass("test20", "test2"), undef, "change password");
is($ldap->auth("test20", "test2"), 1, "check auth success (new pass)");
is($ldap->auth("test20", "test"), undef, "check auth falure (old pass)");
is($ldap->delete("test20"), undef, "deleting user");
};
exit 0;