aboutsummaryrefslogtreecommitdiff
path: root/perl/t/kadmin.t
blob: 7423ed1d6de793f38c9f7a7af68879854c4caf20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl -w
#
# t/kadmin.t -- Tests for the kadmin object implementation.
#
# Written by Jon Robertson <jonrober@stanford.edu>
# Copyright 2009 Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.

use POSIX qw(strftime);
use Test::More tests => 15;

use Wallet::Admin;
use Wallet::Config;
use Wallet::Kadmin;
use Wallet::Kadmin::Heimdal;
use Wallet::Kadmin::MIT;

use lib 't/lib';
use Util;

# We test a Wallet::Kadmin::* module's actual workings in the keytab.t tests.
# The only things we want to test here are that each module is found, that
# Wallet::Kadmin itself delegates to them, and that the private MIT principal 
# validation works as it should.
for my $bad (qw{service\* = host/foo+bar host/foo/bar /bar bar/
                rcmd.foo}) {
    ok (! Wallet::Kadmin::MIT->valid_principal ($bad),
        "Invalid principal name $bad");
}
for my $good (qw{service service/foo bar foo/bar host/example.org
                 aservice/foo}) {
    ok (Wallet::Kadmin::MIT->valid_principal ($good),
        "Valid principal name $good");
}

# Test creating an MIT object.  We don't care about anything but correctly
# creating it -- testing operations is for the keytab tests.
$Wallet::Config::KEYTAB_KRBTYPE = 'MIT';
my $kadmin = Wallet::Kadmin->new ();
ok (defined ($kadmin), 'MIT kadmin object created');

# Test creating a Heimdal object.  For us to test a working Heimdal object,
# we need a properly configured Heimdal KDC.  So instead, we deliberately
# connect without configuration to get the error.  That at least tests that
# we can find the Heimdal module and it dies how it should.
undef $Wallet::Config::KEYTAB_PRINCIPAL;
undef $Wallet::Config::KEYTAB_FILE;
undef $Wallet::Config::KEYTAB_REALM;
undef $kadmin;
$Wallet::Config::KEYTAB_KRBTYPE = 'Heimdal';
$kadmin = eval { Wallet::Kadmin->new () };
is ($kadmin, undef, 'Heimdal fails properly.');