diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | tests/client/full-t.in | 161 | ||||
-rw-r--r-- | tests/data/basic.conf (renamed from tests/data/wallet.conf) | 0 | ||||
-rw-r--r-- | tests/data/cmd-wrapper.in | 9 | ||||
-rw-r--r-- | tests/data/full.conf.in | 4 |
6 files changed, 179 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am index 91f4dd8..ba1ff21 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,8 +24,8 @@ EXTRA_DIST = LICENSE autogen client/wallet.pod config/allow-extract \ 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-netdb.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/allow-extract tests/data/basic.conf tests/data/cmd-fake \ + tests/data/fake-data tests/data/fake-kadmin tests/data/fake-keytab \ tests/data/fake-keytab-2 tests/data/fake-keytab-merge \ tests/data/fake-keytab-old tests/data/fake-srvtab \ tests/data/wallet.conf tests/libtest.sh diff --git a/configure.ac b/configure.ac index e559b2d..3ef580a 100644 --- a/configure.ac +++ b/configure.ac @@ -60,9 +60,11 @@ dnl Needed to get prototypes for functions like asprintf on Linux. AC_DEFINE([_GNU_SOURCE], [1], [Define to 1 on Linux to get full prototypes.]) AC_CONFIG_HEADER([config.h]) -AC_CONFIG_FILES([Makefile perl/Makefile.PL]) +AC_CONFIG_FILES([Makefile perl/Makefile.PL tests/data/full.conf]) AC_CONFIG_FILES([tests/client/basic-t], [chmod +x tests/client/basic-t]) +AC_CONFIG_FILES([tests/client/full-t], [chmod +x tests/client/full-t]) AC_CONFIG_FILES([tests/client/pod-t], [chmod +x tests/client/pod-t]) +AC_CONFIG_FILES([tests/data/cmd-wrapper], [chmod +x tests/data/cmd-wrapper]) AC_CONFIG_FILES([tests/server/admin-t], [chmod +x tests/server/admin-t]) AC_CONFIG_FILES([tests/server/backend-t], [chmod +x tests/server/backend-t]) AC_CONFIG_FILES([tests/server/keytab-t], [chmod +x tests/server/keytab-t]) diff --git a/tests/client/full-t.in b/tests/client/full-t.in new file mode 100644 index 0000000..bae7aa3 --- /dev/null +++ b/tests/client/full-t.in @@ -0,0 +1,161 @@ +#!/usr/bin/perl -w +# $Id$ +# +# tests/client/full-t -- End-to-end tests for the wallet client. +# +# Written by Russ Allbery <rra@stanford.edu> +# Copyright 2008 Board of Trustees, Leland Stanford Jr. University +# +# See LICENSE for licensing terms. + +# Point to our server configuration. This must be done before Wallet::Config +# is loaded, and it's pulled in as a prerequisite for Wallet::Admin. +BEGIN { $ENV{WALLET_CONFIG} = '@abs_top_srcdir@/tests/data/wallet.conf' } + +BEGIN { our $total = 1 } +use Test::More tests => $total; + +use lib '@abs_top_srcdir@/perl'; +use Wallet::Admin; + +use lib '@abs_top_srcdir@/perl/t/lib'; +use Util; + +# Make a call to the wallet client. Takes the principal used by the server +# and the command. Returns the standard output, the standard error, and the +# exit status as a list. +sub wallet { + my ($principal, @command) = @_; + my $pid = fork; + if (not defined $pid) { + die "cannot fork: $!\n"; + } elsif ($pid == 0) { + open (STDOUT, '>', 'wallet.out') + or die "cannot create wallet.out: $!\n"; + open (STDERR, '>', 'wallet.err') + or die "cannot create wallet.err: $!\n"; + exec ('@abs_top_builddir@/client/wallet', '-k', $principal, '-p', + '14373', '-s', 'localhost', @command) + or die "cannot run @abs_top_builddir@/client/wallet: $!\n"; + } else { + waitpid ($pid, 0); + } + my $status = $?; + local $/; + open (OUT, '<', 'wallet.out') or die "cannot open wallet.out: $!\n"; + my $output = <OUT>; + close OUT; + open (ERR, '<', 'wallet.err') or die "cannot open wallet.err: $!\n"; + my $error = <ERR>; + close ERR; + unlink ('wallet.out', 'wallet.err'); + return ($output, $error, $status); +} + +# Use this to accumulate the history traces so that we can check history. +my $history = ''; +my $date = strftime ('%Y-%m-%d %H:%M:%S', localtime $trace[2]); + +SKIP: { + skip 'no keytab configuration', $total + unless -f '@abs_top_builddir@/tests/data/test.keytab'; + my $remctld = '@REMCTLD@'; + skip 'remctld not found', $total unless $remctld; + + # Spawn remctld and get local tickets. Don't destroy the user's Kerberos + # ticket cache. + unlink ('krb5cc_test', 'test-pid'); + my $principal = contents ('@abs_top_builddir@/tests/data/test.principal'); + remctld_spawn ($remctld, $principal, + '@abs_top_builddir@/tests/data/test.keytab', + '@abs_top_builddir@/tests/data/full.conf.in'); + $ENV{KRB5CCNAME} = 'krb5cc_test'; + getcreds ('@abs_top_builddir@/tests/data/test.keytab', $principal); + + # Use Wallet::Admin to set up the database. + db_setup; + my $admin = eval { Wallet::Admin->new }; + is ($@, '', 'Database connection succeeded'); + is ($admin->reinitialize ($principal), 1, + 'Database initialization succeeded'); + my $dbh = $admin->dbh; + + # Create the file bucket. + system ('rm', '-r', 'test-files'); + mkdir ('test-files', 0777) or die "cannot create file-bucket: $!\n"; + + # Now, start testing. First, create an object, create an ACL, assign an + # owner, store the contents, and then get the contents and make sure all + # of that works as expected. + my ($out, $err, $status) = wallet ('create', 'file', 'test'); + is ($status, 0, 'Object creation succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('acl', 'create', 'user/test'); + is ($status, 0, 'ACL creation succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('acl', 'add', 'user/test', 'krb5', + $principal); + is ($status, 0, 'ACL population succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('acl', 'show', 'user/test'); + is ($status, 0, 'ACL show succeeds'); + is ($out, "Members of ACL user/test (id: 2) are:\n krb5 $principal", + ' with the right output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('owner', 'file', 'test', 'user/test'); + is ($status, 0, 'Object owner succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('store', 'file', 'test', "foo\nbar\n"); + is ($status, 0, 'Object store succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('get', 'file', 'test'); + is ($status, 0, 'Object get succeeds'); + is ($out, "foo\nbar\n", ' and returns the right data'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('store', 'file', 'test', ''); + is ($status, 0, 'Store of empty object succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('get', 'file', 'test'); + is ($status, 0, 'Get of empty object succeeds'); + is ($out, '', ' and returns an empty object'); + is ($err, '', ' with no error'); + ($out, $err, $status) = wallet ('destroy', 'file', 'test'); + is ($status, 0, 'Object destroy succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('get', 'file', 'test'); + isnt ($status, 0, 'Object get now fails'); + is ($out, '', ' with no output'); + is ($err, "wallet: cannot find file:test\n", ' and the right error'); + + # Try auto-creation. + ($out, $err, $status) = wallet ('get', 'file', 'auto'); + isnt ($status, 0, 'Object autocreation get fails'); + is ($out, '', ' with no output'); + is ($err, "wallet: cannot get file:auto: object has not been stored\n", + ' and the right error'); + ($out, $err, $status) = wallet ('destroy', 'file', 'auto'); + is ($status, 0, 'Object destroy succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('store', 'file', 'auto', "baz\nboo\n"); + is ($status, 0, 'Object autocreation store succeeds'); + is ($out, '', ' with no output'); + is ($err, '', ' and no error'); + ($out, $err, $status) = wallet ('get', 'file', 'auto'); + is ($status, 0, 'Object get now succeeds'); + is ($out, "baz\nboo\n", ' with the right output'); + is ($err, '', ' and no error'); + + # All done. + remctld_stop; + $admin->destroy; + unlink ('wallet-db', 'krb5cc_test', 'test-pid'); + system ('rm', '-r', 'test-files'); +} diff --git a/tests/data/wallet.conf b/tests/data/basic.conf index 7ad998f..7ad998f 100644 --- a/tests/data/wallet.conf +++ b/tests/data/basic.conf diff --git a/tests/data/cmd-wrapper.in b/tests/data/cmd-wrapper.in new file mode 100644 index 0000000..d50816c --- /dev/null +++ b/tests/data/cmd-wrapper.in @@ -0,0 +1,9 @@ +#!/bin/sh +# $Id$ +# +# Wrapper around the standard wallet-backend script that sets the Perl INC +# path and the WALLET_CONFIG environment variable appropriately. + +WALLET_CONFIG='@abs_top_srcdir@/tests/data/wallet.conf' +export WALLET_CONFIG +exec perl -I'@abs_top_srcdir@/perl' '@abs_top_srcdir@/server/wallet-backend' diff --git a/tests/data/full.conf.in b/tests/data/full.conf.in new file mode 100644 index 0000000..b97a4bc --- /dev/null +++ b/tests/data/full.conf.in @@ -0,0 +1,4 @@ +# remctl configuration for full wallet client tests. +# $Id$ + +wallet ALL @abs_top_builddir@/tests/data/cmd-wrapper ANYUSER |