diff options
Diffstat (limited to 'tests/client')
| -rw-r--r-- | tests/client/basic-t.in | 268 | ||||
| -rw-r--r-- | tests/client/full-t.in | 46 | ||||
| -rw-r--r-- | tests/client/pod-t.in | 23 | ||||
| -rw-r--r-- | tests/client/prompt-t.in | 29 | 
4 files changed, 134 insertions, 232 deletions
diff --git a/tests/client/basic-t.in b/tests/client/basic-t.in index f18c28e..1ae3a70 100644 --- a/tests/client/basic-t.in +++ b/tests/client/basic-t.in @@ -1,56 +1,23 @@  #! /bin/sh -# $Id$  #  # Test suite for the wallet command-line client.  #  # Written by Russ Allbery <rra@stanford.edu> -# Copyright 2006, 2007, 2008 Board of Trustees, Leland Stanford Jr. University +# Copyright 2006, 2007, 2008, 2010 +#     Board of Trustees, Leland Stanford Jr. University  #  # See LICENSE for licensing terms.  # Load the test library. -. "@abs_top_srcdir@/tests/libtest.sh" - -# Print the number of tests. -total=35 -count=1 -echo "$total" - -# Find the client program. -chdir_data '../client/wallet' -if [ ! -f 'data/test.keytab' ] || [ -z '@REMCTLD@' ] ; then -    skip 1 "$total" 'no Kerberos configuration' -    exit 0 -fi -wallet='../client/wallet' - -# Start the remctld daemon and wait for it to start. -principal=`cat data/test.principal` -rm -f data/pid -( @REMCTLD@ -m -p 14373 -s "$principal" -P data/pid -f data/basic.conf \ -  -S -F -k data/test.keytab &) -KRB5CCNAME=data/test.cache; export KRB5CCNAME -kinit -k -t data/test.keytab "$principal" > /dev/null 2>&1 -if [ $? != 0 ] ; then -    kinit -t data/test.keytab "$principal" > /dev/null 2>&1 -fi -if [ $? != 0 ] ; then -    kinit -T /bin/true -k -K data/test.keytab "$principal" > /dev/null 2>&1 -fi -if [ $? != 0 ] ; then -    echo 'Unable to obtain Kerberos tickets' >&2 -    exit 1 -fi -[ -f data/pid ] || sleep 1 -if [ ! -f data/pid ] ; then -    echo 'remctld did not start' >&2 -    exit 1 -fi - -# We need a modified krb5.conf file for the srvtab test to work, since we need -# to add a v4_realm setting for the test-k5.stanford.edu realm that the keytab -# is for.  Despite all the Stanford hard-coding, this test isn't -# Stanford-specific.  It just matches the data files shipped with the package. +. "$SOURCE/tap/libtap.sh" +. "$SOURCE/tap/kerberos.sh" +. "$SOURCE/tap/remctl.sh" +cd "$SOURCE" + +# We need a modified krb5.conf file to test wallet configuration settings in +# krb5.conf.  Despite the hard-coding of test-k5.stanford.edu, this test isn't +# Stanford-specific; it just matches the files that are distributed with the +# package.  krb5conf=  for p in /etc/krb5.conf /usr/local/etc/krb5.conf data/krb5.conf ; do      if [ -r "$p" ] ; then @@ -64,7 +31,7 @@ for p in /etc/krb5.conf /usr/local/etc/krb5.conf data/krb5.conf ; do  [realms]      test-k5.stanford.edu = { -        v4_realm = TEST.STANFORD.EDU +        v4_realm = test-k5.stanford.edu      }  EOF          KRB5_CONFIG="./krb5.conf" @@ -73,44 +40,39 @@ EOF      fi  done  if [ -z "$krb5conf" ] ; then -    echo 'No krb5.conf found -- put one in tests/data/krb5.conf' >&2 -    exit 1 +    skip_all 'no krb5.conf found, put one in tests/data/krb5.conf'  fi +# Test setup. +kerberos_setup +if [ $? != 0 ] ; then +    skip_all 'Kerberos tests not configured' +elif [ -z '@REMCTLD@' ] ; then +    skip_all 'No remctld found' +else +    plan 36 +fi +remctld_start '@REMCTLD@' "$SOURCE/data/basic.conf" +wallet="$BUILD/../client/wallet" +  # Make sure everything's clean. -rm -f output output.bak keytab keytab.bak srvtab srvtab.bak sync-kaserver \ -    autocreated +rm -f output output.bak keytab keytab.bak srvtab srvtab.bak autocreated  # Now, we can finally run our tests.  First, basic operations. -runsuccess "" "$wallet" -k "$principal" -p 14373 -s localhost -c fake-wallet \ -    -f output get file fake-test -if cmp output data/fake-data >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi -if [ -f output.bak ] || [ -f output.new ] ; then -    printcount "not ok" -else -    printcount "ok" -fi -if [ -f autocreated ] ; then -    printcount "ok" -else -    printcount "not ok" -fi -runsuccess "" "$wallet" -k "$principal" -p 14373 -s localhost -c fake-wallet \ -    -f output get file fake-test -if cmp output data/fake-data >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi -if [ -f output.new ] || [ ! -f output.bak ] ; then -    printcount "not ok" -else -    printcount "ok" -fi +ok_program 'get file' 0 '' \ +    "$wallet" -k "$principal" -p 14373 -s localhost -c fake-wallet -f output \ +    get file fake-test +ok '...and file is correct' cmp output data/fake-data +ok '...and no backup files' [ ! -f output.bak ] +ok '...and no new files' [ ! -f output.new ] +ok '...and we tried autocreation' [ -f autocreated ] +ok_program 'get file again' 0 '' \ +   "$wallet" -k "$principal" -p 14373 -s localhost -c fake-wallet -f output \ +    get file fake-test +ok '...and file is correct' cmp output data/fake-data +ok '...and now there is a backup file' [ -f output.bak ] +ok '...which has the right contents' cmp output.bak data/fake-data +ok '...but there is no new file' [ ! -f output.new ]  # Now, append configuration to krb5.conf and test getting configuration from  # there. @@ -124,138 +86,86 @@ cat >> krb5.conf <<EOF          wallet_principal = $principal      }  EOF -runsuccess "" "$wallet" -f output get file fake-test -if cmp output data/fake-data >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi +ok_program 'get file with configuration' 0 '' \ +    "$wallet" -f output get file fake-test +ok '...and file is correct' cmp output data/fake-data  rm -f output output.bak  # Test keytab support. -runsuccess "" "$wallet" -f keytab get keytab service/fake-srvtab -if cmp keytab data/fake-keytab >/dev/null 2>&1 ; then -    printcount "ok" -    rm keytab -else -    printcount "not ok" -fi -if [ ! -f sync-kaserver ] ; then -    printcount "ok" -else -    printcount "not ok" -fi +ok_program 'get keytab' 0 '' \ +    "$wallet" -f keytab get keytab service/fake-srvtab +ok '...and keytab is correct' cmp keytab data/fake-keytab +rm -f keytab  # Test srvtab support. -runsuccess "" "$wallet" -f keytab -S srvtab get keytab service/fake-srvtab -if cmp keytab data/fake-keytab >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi -rm keytab -if [ -f sync-kaserver ] ; then -    printcount "ok" -else -    printcount "not ok" -fi -runsuccess "" "$wallet" -f keytab -S srvtab get keytab service/fake-srvtab -if cmp keytab data/fake-keytab >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi -if [ -f sync-kaserver ] ; then -    printcount "ok" -    rm sync-kaserver -else -    printcount "not ok" -fi -if cmp srvtab data/fake-srvtab >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi -if cmp srvtab.bak data/fake-srvtab >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi +ok_program 'get srvtab' 0 '' \ +    "$wallet" -f keytab -S srvtab get keytab service/fake-srvtab +ok '...and keytab is correct' cmp keytab data/fake-keytab +rm -f keytab +ok_program 'get srvtab again' 0 '' \ +    "$wallet" -f keytab -S srvtab get keytab service/fake-srvtab +ok '...and keytab is correct' cmp keytab data/fake-keytab +ok '...and srvtab is correct' cmp srvtab data/fake-srvtab +ok '...and srvtab backup is correct' cmp srvtab.bak data/fake-srvtab  rm -f srvtab srvtab.bak  # Test keytab merging. -runsuccess "" "$wallet" -f keytab get keytab service/fake-keytab +ok_program 'keytab merging' 0 '' \ +    "$wallet" -f keytab get keytab service/fake-keytab  (klist -keK keytab 2>&1) | sed '/Keytab name:/d' > klist-seen  (klist -keK data/fake-keytab-merge 2>&1) | sed '/Keytab name:/d' > klist-good -if cmp klist-seen klist-good >/dev/null 2>&1 ; then -    printcount "ok" -    rm -f keytab klist-seen klist-good -else -    printcount "not ok" -fi +ok '...and the merged keytab is correct' cmp klist-seen klist-good +rm -f keytab klist-seen klist-good  # Test srvtab download into a merged keytab with an older version.  cp data/fake-keytab-old keytab -runsuccess "" "$wallet" -f keytab -S srvtab get keytab service/fake-srvtab -if [ -f sync-kaserver ] ; then -    printcount "ok" -    rm sync-kaserver -else -    printcount "not ok" -fi -if cmp srvtab data/fake-srvtab >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi +ok_program 'keytab merging with srvtab creation' 0 '' \ +    "$wallet" -f keytab -S srvtab get keytab service/fake-srvtab +ok '...and the srvtab is correct' cmp srvtab data/fake-srvtab  rm -f keytab srvtab  # Test store from standard input. -echo "This is a test of store" | runsuccess "" "$wallet" store file fake-test -count=`expr $count + 1` +echo "This is a test of store" > input +ok_program 'store from stdin' 0 '' "$wallet" store file fake-test < input +rm -f input  echo "file fake-test" > store-correct  echo "This is a test of store" >> store-correct -if cmp store-output store-correct >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -    echo == store-output == -    cat store-output -    echo == store-correct == -    cat store-correct -fi +ok '...and the correct data was stored' diff store-output store-correct  rm -f store-output store-correct  # Test store with -f.  echo "This is more store input" > store-input  echo "file fake-test" > store-correct  cat store-input >> store-correct -runsuccess "" "$wallet" -f store-input store file fake-test -if cmp store-output store-correct >/dev/null 2>&1 ; then -    printcount "ok" -else -    printcount "not ok" -fi +ok_program 'store from a file' 0 '' \ +    "$wallet" -f store-input store file fake-test +ok '...and the correct data was stored' cmp store-output store-correct +rm -f store-input store-output store-correct +printf 'This is store input\000with a nul character' > store-input +echo 'file fake-nul' > store-correct +cat store-input >> store-correct +ok_program 'store from a file with a nul' 0 '' \ +    "$wallet" -f store-input store file fake-nul +ok '...and the correct data was stored' cmp store-output store-correct  rm -f store-input store-output store-correct  # Test various other client functions and errors. -runsuccess "This is a fake keytab." "$wallet" get keytab service/fake-output -runsuccess "Some stuff about file fake-test" \ +ok_program 'get output to stdout' 0 'This is a fake keytab.' \ +    "$wallet" get keytab service/fake-output +ok_program 'show output' 0 'Some stuff about file fake-test' \      "$wallet" show file fake-test -runfailure 1 "wallet: Unknown object type srvtab" \ +ok_program 'unknown object type' 1 'wallet: Unknown object type srvtab' \      "$wallet" get srvtab service/fake-test -runfailure 1 "wallet: Unknown keytab service/unknown" \ +ok_program 'unknown keytab name in show' 1 \ +    'wallet: Unknown keytab service/unknown' \      "$wallet" show keytab service/unknown -runfailure 1 "wallet: Unknown keytab service/unknown" \ +ok_program 'unknown keytab name in get' 1 \ +    'wallet: Unknown keytab service/unknown' \      "$wallet" get keytab service/unknown -runsuccess "Expiration date of keytab service/fake-test" \ +ok_program 'expiration date' 0 'Expiration date of keytab service/fake-test' \      "$wallet" expires keytab service/fake-test  # Clean up. -KRB5_CONFIG= -rm krb5.conf -rm -f autocreated data/test.cache -if [ -f data/pid ] ; then -    kill `cat data/pid` -    rm -f data/pid -fi +rm -f autocreated krb5.conf +remctld_stop +kerberos_cleanup diff --git a/tests/client/full-t.in b/tests/client/full-t.in index f4ef1d3..ce2789d 100644 --- a/tests/client/full-t.in +++ b/tests/client/full-t.in @@ -1,24 +1,23 @@  #!/usr/bin/perl -w -# $Id$  # -# tests/client/full-t -- End-to-end tests for the wallet client. +# End-to-end tests for the wallet client.  #  # Written by Russ Allbery <rra@stanford.edu> -# Copyright 2008 Board of Trustees, Leland Stanford Jr. University +# Copyright 2008, 2010 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 { $ENV{WALLET_CONFIG} = "$ENV{SOURCE}/data/wallet.conf" } -BEGIN { our $total = 53 } +BEGIN { our $total = 59 }  use Test::More tests => $total; -use lib '@abs_top_srcdir@/perl'; +use lib "$ENV{SOURCE}/../perl";  use Wallet::Admin; -use lib '@abs_top_srcdir@/perl/t/lib'; +use lib "$ENV{SOURCE}/../perl/t/lib";  use Util;  # Make a call to the wallet client.  Takes the principal used by the server @@ -34,9 +33,9 @@ sub wallet {              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', +        exec ("$ENV{BUILD}/../client/wallet", '-k', $principal, '-p',                '14373', '-s', 'localhost', @command) -            or die "cannot run @abs_top_builddir@/client/wallet: $!\n"; +            or die "cannot run $ENV{BUILD}/client/wallet: $!\n";      } else {          waitpid ($pid, 0);      } @@ -52,21 +51,24 @@ sub wallet {      return ($output, $error, $status);  } +# cd to the correct directory. +chdir "$ENV{SOURCE}" or die "Cannot chdir to $ENV{SOURCE}: $!\n"; +  SKIP: {      skip 'no keytab configuration', $total -        unless -f '@abs_top_builddir@/tests/data/test.keytab'; +        unless -f "$ENV{BUILD}/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'); +    my $principal = contents ("$ENV{BUILD}/data/test.principal");      remctld_spawn ($remctld, $principal, -                   '@abs_top_builddir@/tests/data/test.keytab', -                   '@abs_top_builddir@/tests/data/full.conf'); +                   "$ENV{BUILD}/data/test.keytab", +                   "$ENV{SOURCE}/data/full.conf");      $ENV{KRB5CCNAME} = 'krb5cc_test'; -    getcreds ('@abs_top_builddir@/tests/data/test.keytab', $principal); +    getcreds ("$ENV{BUILD}/data/test.keytab", $principal);      # Use Wallet::Admin to set up the database.      db_setup; @@ -166,6 +168,22 @@ SKIP: {      is ($out, '-q', ' with the right output');      is ($err, '', ' and no error'); +    # Store data containing nul characters. +    my $data = "Some data\000with a nul"; +    open (IN, '>', 'tmp-file') or BAIL_OUT ("cannot create tmp-file: $!"); +    print IN $data; +    close IN; +    ($out, $err, $status) = wallet ($principal, '-f', 'tmp-file', 'store', +                                    'file', 'auto'); +    unlink ('tmp-file'); +    is ($status, 0, 'Storing data with a nul succeeds'); +    is ($out, '', ' with no output'); +    is ($err, '', ' and no error'); +    ($out, $err, $status) = wallet ($principal, 'get', 'file', 'auto'); +    is ($status, 0, 'Object get succeeds'); +    is ($out, $data, ' with the right output'); +    is ($err, '', ' and no error'); +      # All done.      remctld_stop;      $admin->destroy; diff --git a/tests/client/pod-t.in b/tests/client/pod-t.in deleted file mode 100644 index 98c34c7..0000000 --- a/tests/client/pod-t.in +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/perl -# $Id$ -# -# Test POD formatting for client documentation. -# -# Written by Russ Allbery <rra@stanford.edu> -# Copyright 2008 Board of Trustees, Leland Stanford Jr. University -# -# See LICENSE for licensing terms. - -use Test::More; - -my @files = qw(wallet.pod); -my $total = scalar (@files); -plan tests => $total; - -eval 'use Test::Pod 1.00'; -SKIP: { -    skip $total, 'Test::Pod 1.00 required for testing POD' if $@; -    for my $file (@files) { -        pod_file_ok ("@abs_top_srcdir@/client/$file", "client/$file"); -    } -} diff --git a/tests/client/prompt-t.in b/tests/client/prompt-t.in index 2d6097d..1d8b079 100644 --- a/tests/client/prompt-t.in +++ b/tests/client/prompt-t.in @@ -1,29 +1,27 @@  #!/usr/bin/perl -w -# $Id$  # -# tests/client/prompt-t -- Password prompting tests for the wallet client. +# Password prompting tests for the wallet client.  #  # Written by Russ Allbery <rra@stanford.edu> -# Copyright 2008 Board of Trustees, Leland Stanford Jr. University +# Copyright 2008, 2010 Board of Trustees, Leland Stanford Jr. University  #  # See LICENSE for licensing terms.  BEGIN { our $total = 5 }  use Test::More tests => $total; -use lib '@abs_top_srcdir@/perl'; +use lib "$ENV{SOURCE}/..//perl";  use Wallet::Admin; -use lib '@abs_top_srcdir@/perl/t/lib'; +use lib "$ENV{SOURCE}/../perl/t/lib";  use Util;  # cd to the correct directory. -chdir '@abs_top_srcdir@/tests' -    or die "Cannot chdir to @abs_top_srcdir@/tests: $!\n"; +chdir "$ENV{SOURCE}" or die "Cannot chdir to $ENV{SOURCE}: $!\n";  SKIP: {      skip 'no password configuration', $total -        unless -f '@abs_top_builddir@/tests/data/test.password'; +        unless -f "$ENV{BUILD}/data/test.password";      my $remctld = '@REMCTLD@';      skip 'remctld not found', $total unless $remctld;      eval { require Expect }; @@ -36,22 +34,21 @@ SKIP: {      # Spawn remctld and set up with a different 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/basic.conf'); +    my $principal = contents ("$ENV{BUILD}/data/test.principal"); +    remctld_spawn ($remctld, $principal, "$ENV{BUILD}/data/test.keytab", +                   "$ENV{SOURCE}/data/basic.conf");      $ENV{KRB5CCNAME} = 'krb5cc_test';      # Read in the principal and password. -    open (PASS, '<', '@abs_top_builddir@/tests/data/test.password') -        or die "Cannot open @abs_top_builddir@/tests/data/test.password: $!\n"; +    open (PASS, '<', "$ENV{BUILD}/data/test.password") +        or die "Cannot open $ENV{BUILD}/data/test.password: $!\n";      my $user = <PASS>;      my $password = <PASS>;      close PASS;      chomp ($user, $password);      # Spawn wallet and check an invalid password. -    my $wallet = Expect->spawn ('@abs_top_builddir@/client/wallet', '-k', +    my $wallet = Expect->spawn ("$ENV{BUILD}/../client/wallet", '-k',                                  $principal, '-p', 14373, '-s', 'localhost',                                  '-c', 'fake-wallet', '-u', $user, 'get',                                  'keytab', 'service/fake-output'); @@ -62,7 +59,7 @@ SKIP: {      $wallet->soft_close;      # Now check a valid password. -    $wallet = Expect->spawn ('@abs_top_builddir@/client/wallet', '-k', +    $wallet = Expect->spawn ("$ENV{BUILD}/../client/wallet", '-k',                               $principal, '-p', 14373, '-s', 'localhost',                               '-c', 'fake-wallet', '-u', $user, 'get',                               'keytab', 'service/fake-output');  | 
