diff options
author | Russ Allbery <rra@stanford.edu> | 2008-01-23 19:17:09 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2008-01-23 19:17:09 +0000 |
commit | 45e33ff74717f39c421091f1a74f7d895e38bf57 (patch) | |
tree | b2d6e6e2ce21612eae18ecde213e372787e58711 | |
parent | 77b6875f95aa54fe9c648ba114e06d85cf655bb1 (diff) |
Add a destroy() method to the Wallet::Admin object and use that instead
of Wallet::Schema::drop in the test suite.
-rw-r--r-- | perl/Wallet/Admin.pm | 22 | ||||
-rwxr-xr-x | perl/t/acl.t | 3 | ||||
-rwxr-xr-x | perl/t/init.t | 10 | ||||
-rwxr-xr-x | perl/t/keytab.t | 3 | ||||
-rwxr-xr-x | perl/t/object.t | 3 | ||||
-rwxr-xr-x | perl/t/server.t | 4 |
6 files changed, 29 insertions, 16 deletions
diff --git a/perl/Wallet/Admin.pm b/perl/Wallet/Admin.pm index 400068d..258077a 100644 --- a/perl/Wallet/Admin.pm +++ b/perl/Wallet/Admin.pm @@ -90,17 +90,25 @@ sub initialize { } # The same as initialize, but also drops any existing tables first before -# creating the schema. Takes the same arguments and throws an exception on -# failure. +# creating the schema. Takes the same arguments. Returns true on success and +# false on failure. sub reinitialize { my ($self, $user) = @_; + return unless $self->destroy; + return $self->initialize ($user); +} + +# Drop the database, including all of its data. Returns true on success and +# false on failure. +sub destroy { + my ($self) = @_; my $schema = Wallet::Schema->new; eval { $schema->drop ($self->{dbh}) }; if ($@) { $self->error ($@); return; } - return $self->initialize ($user); + return 1; } 1; @@ -152,6 +160,11 @@ failure to get the error message. =over 4 +=item destroy() + +Destroys the database, deleting all of its data and all of the tables used +by the wallet server. Returns true on success and false on failure. + =item initialize(PRINCIPAL) Initializes the database as configured in Wallet::Config and loads the @@ -159,6 +172,7 @@ wallet database schema. Then, creates an ACL with the name ADMIN and adds an ACL entry of scheme C<krb5> and instance PRINCIPAL to that ACL. This bootstraps the authorization system and lets that Kerberos identity make further changes to the ADMIN ACL and the rest of the wallet database. +Returns true on success and false on failure. initialize() uses C<localhost> as the hostname and PRINCIPAL as the user when logging the history of the ADMIN ACL creation and for any subsequent @@ -176,6 +190,8 @@ Performs the same actions as initialize(), but first drops any existing wallet database tables from the database, allowing this function to be called on a prior wallet database. All data stored in the database will be deleted and a fresh set of wallet database tables will be created. +This method is equivalent to calling destroy() followed by initialize(). +Returns true on success and false on failure. =back diff --git a/perl/t/acl.t b/perl/t/acl.t index 15796d2..59e1071 100755 --- a/perl/t/acl.t +++ b/perl/t/acl.t @@ -227,6 +227,5 @@ is ($acl->name, 'example', ' and the right name'); is ($acl->id, 3, ' and a new ID'); # Clean up. -my $schema = Wallet::Schema->new; -$schema->drop ($dbh); +$setup->destroy; unlink 'wallet-db'; diff --git a/perl/t/init.t b/perl/t/init.t index 9e1b600..df2836b 100755 --- a/perl/t/init.t +++ b/perl/t/init.t @@ -8,7 +8,7 @@ # # See LICENSE for licensing terms. -use Test::More tests => 16; +use Test::More tests => 18; use Wallet::ACL; use Wallet::Admin; @@ -50,7 +50,9 @@ isnt ($entries[0], undef, ' which is a valid entry'); is ($entries[0][0], 'krb5', ' of krb5 scheme'); is ($entries[0][1], 'admin@EXAMPLE.ORG', ' with the right user'); -# Clean up. -my $schema = Wallet::Schema->new; -$schema->drop ($admin->dbh); +# Test cleanup. +is ($admin->destroy, 1, 'Destroying the database works'); +$acl = eval { Wallet::ACL->new ('ADMIN', $admin->dbh) }; +like ($@, qr/^cannot search for ACL ADMIN: /, + ' and now the database is gone'); unlink 'wallet-db'; diff --git a/perl/t/keytab.t b/perl/t/keytab.t index a40332a..503b5c9 100755 --- a/perl/t/keytab.t +++ b/perl/t/keytab.t @@ -892,6 +892,5 @@ EOO } # Clean up. -my $schema = Wallet::Schema->new; -$schema->drop ($dbh); +$admin->destroy; unlink ('wallet-db', 'krb5cc_temp', 'krb5cc_test', 'test-acl', 'test-pid'); diff --git a/perl/t/object.t b/perl/t/object.t index 48604bc..94fe22b 100755 --- a/perl/t/object.t +++ b/perl/t/object.t @@ -320,6 +320,5 @@ EOO is ($object->history, $output, ' and the history is correct'); # Clean up. -my $schema = Wallet::Schema->new; -$schema->drop ($dbh); +$admin->destroy; unlink 'wallet-db'; diff --git a/perl/t/server.t b/perl/t/server.t index 5378969..a7b3cc5 100755 --- a/perl/t/server.t +++ b/perl/t/server.t @@ -31,7 +31,6 @@ db_setup; my $setup = eval { Wallet::Admin->new }; is ($@, '', 'Database initialization did not die'); is ($setup->reinitialize ($admin), 1, 'Database initialization succeeded'); -undef $setup; # Now test the new method. $server = eval { Wallet::Server->new (@trace) }; @@ -936,8 +935,7 @@ is ($server->error, 'base:host/default.stanford.edu rejected: host' ' with the right error'); # Clean up. -$schema = Wallet::Schema->new; -$schema->drop ($server->dbh); +$setup->destroy; unlink 'wallet-db'; # Now test handling of some configuration errors. |