summaryrefslogtreecommitdiff
path: root/perl/t/config.t
blob: 1377cb8b69ac92cf59c34cd78e44584e7d1d4fa3 (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
#!/usr/bin/perl -w
#
# t/config.t -- Tests for the wallet server configuration.
#
# Written by Russ Allbery <rra@stanford.edu>
# Copyright 2008, 2010 Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.

use Test::More tests => 6;

# Silence warnings since we're not using use.
package Wallet::Config;
our $DB_DRIVER;
our $KEYTAB_AFS_KASETKEY;
our $KEYTAB_FLAGS;
our $KEYTAB_KADMIN;
package main;

# Load with a nonexistent file.
$ENV{WALLET_CONFIG} = '/path/to/nonexistent/file';
eval { require Wallet::Config };
is ($@, '', 'Loading Wallet::Config with nonexistent config file works');
is ($Wallet::Config::KEYTAB_FLAGS, '-clearpolicy',
    ' and KEYTAB_FLAGS is correct');
is ($Wallet::Config::KEYTAB_KADMIN, 'kadmin',
    ' and KEYTAB_KADMIN is correct');
is ($Wallet::Config::DB_DRIVER, undef, ' and DB_DRIVER is unset');

# Create a configuration file with a single setting.
open (CONFIG, '>', 'test-wallet.conf')
    or die "$0: cannot create test-wallet.conf: $!\n";
print CONFIG '$DB_DRIVER = "mysql";', "\n";
print CONFIG "1;\n";
close CONFIG;
$ENV{WALLET_CONFIG} = './test-wallet.conf';

# Reload the module and be sure it picks up that configuration file.
delete $INC{'Wallet/Config.pm'};
eval { require Wallet::Config };
is ($@, '', 'Loading Wallet::Config with new config file works');
is ($Wallet::Config::DB_DRIVER, 'mysql', ' and now DB_DRIVER is set');
unlink 'test-wallet.conf';