aboutsummaryrefslogtreecommitdiff
path: root/perl/t/init.t
blob: 18f8e3b6c3e13bd87735889905349501bb58a451 (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
54
#!/usr/bin/perl -w
# $Id$
#
# t/init.t -- Tests for database initialization.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2007 Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.

use Test::More tests => 16;

use Wallet::ACL;
use Wallet::Config;
use Wallet::Server;

use lib 't/lib';
use Util;

# Use Wallet::Server to set up the database.
db_setup;
my $server = eval { Wallet::Server->initialize ('admin@EXAMPLE.COM') };
is ($@, '', 'Database initialization did not die');
ok ($server->isa ('Wallet::Server'), ' and returned the right class');

# Check whether the database entries that should be created were.
my $acl = eval { Wallet::ACL->new ('ADMIN', $server->dbh) };
is ($@, '', 'Retrieving ADMIN ACL successful');
ok ($acl->isa ('Wallet::ACL'), ' and is the right class');
my @entries = $acl->list;
is (scalar (@entries), 1, ' and has only one entry');
isnt ($entries[0], undef, ' which is a valid entry');
is ($entries[0][0], 'krb5', ' of krb5 scheme');
is ($entries[0][1], 'admin@EXAMPLE.COM', ' with the right user');

# Test reinitialization.
$server = eval { Wallet::Server->reinitialize ('admin@EXAMPLE.COM') };
is ($@, '', 'Reinitialization did not die');
ok ($server->isa ('Wallet::Server'), ' and returned the right class');

# Now repeat the database content checks.
$acl = eval { Wallet::ACL->new ('ADMIN', $server->dbh) };
is ($@, '', 'Retrieving ADMIN ACL successful');
ok ($acl->isa ('Wallet::ACL'), ' and is the right class');
@entries = $acl->list;
is (scalar (@entries), 1, ' and has only one entry');
isnt ($entries[0], undef, ' which is a valid entry');
is ($entries[0][0], 'krb5', ' of krb5 scheme');
is ($entries[0][1], 'admin@EXAMPLE.COM', ' with the right user');

# Clean up.
my $schema = Wallet::Schema->new;
$schema->drop ($server->dbh);
unlink 'wallet-db';