aboutsummaryrefslogtreecommitdiff
path: root/perl
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2007-12-01 00:42:46 +0000
committerRuss Allbery <rra@stanford.edu>2007-12-01 00:42:46 +0000
commitc9948c8f68b11a1e897afe9c9f2dd2fcb6934f8d (patch)
treef15323beb5ceac6a2b81df8634f5f9f23ad239c8 /perl
parent1e13c0c60c96dd1719e7c4c3931b4196c2b5bc61 (diff)
The wallet backend test suite now supports using a database other than
SQLite for testing. Also start a new Util.pm module for the test suite and move the contents sub into that module. More to follow.
Diffstat (limited to 'perl')
-rwxr-xr-xperl/t/acl.t7
-rw-r--r--perl/t/data/README14
-rwxr-xr-xperl/t/init.t7
-rwxr-xr-xperl/t/keytab.t20
-rw-r--r--perl/t/lib/Util.pm67
-rwxr-xr-xperl/t/object.t7
-rwxr-xr-xperl/t/schema.t20
-rwxr-xr-xperl/t/server.t7
-rwxr-xr-xperl/t/verifier.t11
9 files changed, 118 insertions, 42 deletions
diff --git a/perl/t/acl.t b/perl/t/acl.t
index bd055d2..64eb15c 100755
--- a/perl/t/acl.t
+++ b/perl/t/acl.t
@@ -15,10 +15,8 @@ use Wallet::ACL;
use Wallet::Config;
use Wallet::Server;
-# Use a local SQLite database for testing.
-$Wallet::Config::DB_DRIVER = 'SQLite';
-$Wallet::Config::DB_INFO = 'wallet-db';
-unlink 'wallet-db';
+use lib 't/lib';
+use Util;
# Some global defaults to use.
my $admin = 'admin@EXAMPLE.COM';
@@ -28,6 +26,7 @@ my $host = 'localhost';
my @trace = ($admin, $host, time);
# Use Wallet::Server to set up the database.
+db_setup;
my $server = eval { Wallet::Server->initialize ($admin) };
is ($@, '', 'Database initialization did not die');
ok ($server->isa ('Wallet::Server'), ' and returned the right class');
diff --git a/perl/t/data/README b/perl/t/data/README
index 8b68db9..bd57aad 100644
--- a/perl/t/data/README
+++ b/perl/t/data/README
@@ -1,5 +1,19 @@
This directory contains additional data files needed to run some tests.
+By default, all the tests are done using a SQLite database. To test
+against another database, create a file named test.database. The first
+line of the file should contain the database driver name (mysql, for
+example, for DBD::mysql). The second line should contain the DBI connect
+string, normally of the form:
+
+ database=<name>;host=<host>;port=<port>
+
+replacing <name>, <host>, and <port> with the parameters for your
+database. The third line should be the username to use, and the fourth
+and last line should be the password. If this file is present, all tests
+except part of the schema test will be run against this database instead
+of a local SQLite database.
+
In order to run the keytab tests, you will need to grant the test
processes access to create, download, and remove principals in a test KDC.
This should not be pointed at a production KDC! Then, create the
diff --git a/perl/t/init.t b/perl/t/init.t
index 81c034d..18f8e3b 100755
--- a/perl/t/init.t
+++ b/perl/t/init.t
@@ -14,12 +14,11 @@ use Wallet::ACL;
use Wallet::Config;
use Wallet::Server;
-# Use a local SQLite database for testing.
-$Wallet::Config::DB_DRIVER = 'SQLite';
-$Wallet::Config::DB_INFO = 'wallet-db';
-unlink 'wallet-db';
+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');
diff --git a/perl/t/keytab.t b/perl/t/keytab.t
index f08bd31..c7b333c 100755
--- a/perl/t/keytab.t
+++ b/perl/t/keytab.t
@@ -15,6 +15,9 @@ use Wallet::Config;
use Wallet::Object::Keytab;
use Wallet::Server;
+use lib 't/lib';
+use Util;
+
# Mapping of klist -ke encryption type names to the strings that Kerberos uses
# internally. It's very annoying to have to maintain this, and it probably
# breaks with Heimdal.
@@ -25,11 +28,6 @@ my %enctype =
'aes-256 cts mode with 96-bit sha-1 hmac' => 'aes256-cts',
'arcfour with hmac/md5' => 'rc4-hmac');
-# Use a local SQLite database for testing.
-$Wallet::Config::DB_DRIVER = 'SQLite';
-$Wallet::Config::DB_INFO = 'wallet-db';
-unlink ('wallet-db', 'krb5cc_temp', 'krb5cc_test', 'test-acl', 'test-pid');
-
# Some global defaults to use.
my $user = 'admin@EXAMPLE.COM';
my $host = 'localhost';
@@ -38,16 +36,6 @@ my @trace = ($user, $host, time);
# Flush all output immediately.
$| = 1;
-# Returns the one-line contents of a file as a string, removing the newline.
-sub contents {
- my ($file) = @_;
- open (FILE, '<', $file) or die "cannot open $file: $!\n";
- my $data = <FILE>;
- close FILE;
- chomp $data;
- return $data;
-}
-
# Run a command and throw away the output, returning the exit status.
sub system_quiet {
my ($command, @args) = @_;
@@ -200,6 +188,8 @@ sub stop_remctld {
}
# Use Wallet::Server to set up the database.
+unlink ('krb5cc_temp', 'krb5cc_test', 'test-acl', 'test-pid');
+db_setup;
my $server = eval { Wallet::Server->reinitialize ($user) };
is ($@, '', 'Database initialization did not die');
ok ($server->isa ('Wallet::Server'), ' and returned the right class');
diff --git a/perl/t/lib/Util.pm b/perl/t/lib/Util.pm
new file mode 100644
index 0000000..6566ca4
--- /dev/null
+++ b/perl/t/lib/Util.pm
@@ -0,0 +1,67 @@
+# Util -- Utility class for wallet tests.
+# $Id$
+#
+# Written by Russ Allbery <rra@stanford.edu>
+# Copyright 2007 Board of Trustees, Leland Stanford Jr. University
+#
+# See LICENSE for licensing terms.
+
+package Util;
+require 5.006;
+
+use strict;
+use vars qw(@ISA @EXPORT $VERSION);
+
+use Wallet::Config;
+
+# This version should be increased on any code change to this module. Always
+# use two digits for the minor version with a leading zero if necessary so
+# that it will sort properly.
+$VERSION = '0.01';
+
+use Exporter ();
+@ISA = qw(Exporter);
+@EXPORT = qw(contents db_setup);
+
+##############################################################################
+# General utility functions
+##############################################################################
+
+# Returns the one-line contents of a file as a string, removing the newline.
+sub contents {
+ my ($file) = @_;
+ open (FILE, '<', $file) or die "cannot open $file: $!\n";
+ my $data = <FILE>;
+ close FILE;
+ chomp $data;
+ return $data;
+}
+
+##############################################################################
+# User test configuration
+##############################################################################
+
+# Set up the database configuration parameters. Use a local SQLite database
+# for testing by default, but support t/data/test.database as a configuration
+# file to use another database backend.
+sub db_setup {
+ if (-f 't/data/test.database') {
+ open (DB, '<', 't/data/test.database')
+ or die "cannot open t/data/test.database: $!";
+ my $driver = <DB>;
+ my $info = <DB>;
+ my $user = <DB>;
+ my $password = <DB>;
+ chomp ($driver, $info);
+ chomp $user if $user;
+ chomp $password if $password;
+ $Wallet::Config::DB_DRIVER = $driver;
+ $Wallet::Config::DB_INFO = $info;
+ $Wallet::Config::DB_USER = $user if $user;
+ $Wallet::Config::DB_PASSWORD = $password if $password;
+ } else {
+ $Wallet::Config::DB_DRIVER = 'SQLite';
+ $Wallet::Config::DB_INFO = 'wallet-db';
+ unlink 'wallet-db';
+ }
+}
diff --git a/perl/t/object.t b/perl/t/object.t
index 42700d0..3591885 100755
--- a/perl/t/object.t
+++ b/perl/t/object.t
@@ -16,10 +16,8 @@ use Wallet::Config;
use Wallet::Object::Base;
use Wallet::Server;
-# Use a local SQLite database for testing.
-$Wallet::Config::DB_DRIVER = 'SQLite';
-$Wallet::Config::DB_INFO = 'wallet-db';
-unlink 'wallet-db';
+use lib 't/lib';
+use Util;
# Some global defaults to use.
my $user = 'admin@EXAMPLE.COM';
@@ -28,6 +26,7 @@ my @trace = ($user, $host, time);
my $princ = 'service/test@EXAMPLE.COM';
# Use Wallet::Server to set up the database.
+db_setup;
my $server = eval { Wallet::Server->reinitialize ($user) };
is ($@, '', 'Database initialization did not die');
ok ($server->isa ('Wallet::Server'), ' and returned the right class');
diff --git a/perl/t/schema.t b/perl/t/schema.t
index 9e2d84f..566d67d 100755
--- a/perl/t/schema.t
+++ b/perl/t/schema.t
@@ -8,11 +8,14 @@
#
# See LICENSE for licensing terms.
-use Test::More tests => 8;
+use Test::More tests => 10;
use DBI;
use Wallet::Schema;
+use lib 't/lib';
+use Util;
+
my $schema = Wallet::Schema->new;
ok (defined $schema, 'Wallet::Schema creation');
ok ($schema->isa ('Wallet::Schema'), ' and class verification');
@@ -21,7 +24,6 @@ ok (@sql > 0, 'sql() returns something');
is (scalar (@sql), 26, ' and returns the right number of statements');
# Create a SQLite database to use for create.
-unlink 'wallet-db';
my $dbh = DBI->connect ("DBI:SQLite:wallet-db");
if (not defined $dbh) {
die "cannot create database wallet-db: $DBI::errstr\n";
@@ -48,3 +50,17 @@ is ($@, '', ' and we can run create again');
# Clean up.
eval { $schema->drop ($dbh) };
unlink 'wallet-db';
+
+# Now repeat the test against the configured database in case it's different.
+db_setup;
+my $connect = "DBI:${Wallet::Config::DB_DRIVER}:${Wallet::Config::DB_INFO}";
+$dbh = DBI->connect ($connect);
+if (not defined $dbh) {
+ die "cannot connect to database $connect: $DBI::errstr\n";
+}
+$dbh->{RaiseError} = 1;
+$dbh->{PrintError} = 0;
+eval { $schema->create ($dbh) };
+is ($@, '', "create() against configured database doesn't die");
+eval { $schema->drop ($dbh) };
+is ($@, '', " and drop() doesn't die");
diff --git a/perl/t/server.t b/perl/t/server.t
index 2520e62..f7826b6 100755
--- a/perl/t/server.t
+++ b/perl/t/server.t
@@ -13,10 +13,8 @@ use Test::More tests => 321;
use Wallet::Config;
use Wallet::Server;
-# Use a local SQLite database for testing.
-$Wallet::Config::DB_DRIVER = 'SQLite';
-$Wallet::Config::DB_INFO = 'wallet-db';
-unlink 'wallet-db';
+use lib 't/lib';
+use Util;
# Allow creation of base objects for testing purposes.
$Wallet::Server::MAPPING{base} = 'Wallet::Object::Base';
@@ -29,6 +27,7 @@ my $host = 'localhost';
my @trace = ($admin, $host);
# Use Wallet::Server to set up the database.
+db_setup;
my $server = eval { Wallet::Server->initialize ($admin) };
is ($@, '', 'Database initialization did not die');
ok ($server->isa ('Wallet::Server'), ' and returned the right class');
diff --git a/perl/t/verifier.t b/perl/t/verifier.t
index d401146..8027869 100755
--- a/perl/t/verifier.t
+++ b/perl/t/verifier.t
@@ -15,15 +15,8 @@ use Wallet::ACL::Krb5;
use Wallet::ACL::NetDB;
use Wallet::Config;
-# Returns the one-line contents of a file as a string, removing the newline.
-sub contents {
- my ($file) = @_;
- open (FILE, '<', $file) or die "cannot open $file: $!\n";
- my $data = <FILE>;
- close FILE;
- chomp $data;
- return $data;
-}
+use lib 't/lib';
+use Util;
# Given a keytab file, try authenticating with kinit.
sub getcreds {