diff options
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | TODO | 5 | ||||
-rwxr-xr-x | perl/t/acl.t | 7 | ||||
-rw-r--r-- | perl/t/data/README | 14 | ||||
-rwxr-xr-x | perl/t/init.t | 7 | ||||
-rwxr-xr-x | perl/t/keytab.t | 20 | ||||
-rw-r--r-- | perl/t/lib/Util.pm | 67 | ||||
-rwxr-xr-x | perl/t/object.t | 7 | ||||
-rwxr-xr-x | perl/t/schema.t | 20 | ||||
-rwxr-xr-x | perl/t/server.t | 7 | ||||
-rwxr-xr-x | perl/t/verifier.t | 11 |
12 files changed, 126 insertions, 52 deletions
diff --git a/Makefile.am b/Makefile.am index e04353a..1d2e241 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,11 +17,11 @@ EXTRA_DIST = LICENSE autogen client/wallet.pod config/allow-extract \ perl/Wallet/Schema.pm perl/Wallet/Server.pm perl/t/acl.t \ perl/t/data/README perl/t/data/keytab-fake perl/t/data/keytab.conf \ perl/t/data/netdb.conf perl/t/data/netdb-fake perl/t/init.t \ - perl/t/keytab.t perl/t/object.t perl/t/pod.t perl/t/schema.t \ - perl/t/server.t perl/t/verifier.t tests/TESTS tests/data/README \ - tests/data/allow-extract tests/data/cmd-fake tests/data/fake-data \ - tests/data/fake-kadmin tests/data/fake-keytab tests/data/fake-srvtab \ - tests/data/wallet.conf + perl/t/keytab.t perl/t/lib/Util.pm perl/t/object.t perl/t/pod.t \ + perl/t/schema.t perl/t/server.t perl/t/verifier.t tests/TESTS \ + tests/data/README tests/data/allow-extract tests/data/cmd-fake \ + tests/data/fake-data tests/data/fake-kadmin tests/data/fake-keytab \ + tests/data/fake-srvtab tests/data/wallet.conf noinst_LIBRARIES = portable/libportable.a util/libutil.a portable_libportable_a_SOURCES = portable/dummy.c @@ -21,6 +21,9 @@ wallet 0.3 (unreleased) The keytab backend now supports limiting generated keytabs to particular enctypes by setting an attribute on the object. + The wallet backend test suite now supports using a database other than + SQLite for testing. + wallet 0.2 (2007-10-08) First public alpha release. Only tested with SQLite 3, no history @@ -2,11 +2,6 @@ Minimum required to replace leland_srvtab: -* Add support to the test suite for specifying a different database than - SQLite for testing. For MySQL and other database types that we can't - just delete, also requires adding a method to Wallet::Schema to drop all - of our tables and indices in reverse order of creation. - * Write the remctl configuration and finish Debian packaging of the wallet client and server. 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 { |