diff options
author | Russ Allbery <rra@stanford.edu> | 2007-09-15 00:48:20 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2007-09-15 00:48:20 +0000 |
commit | b2285aff21d379b680cabb1259d31e5bf5b57a69 (patch) | |
tree | 9cdfe75dadb3106b69ea3aef246da4135bf8a2e0 /tests/server | |
parent | 4c4cb52999c9f4d7bbd31b958decfbf8a5012cbc (diff) |
Add a test suite for keytab-backend.
Diffstat (limited to 'tests/server')
-rw-r--r-- | tests/server/keytab-t.in | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/server/keytab-t.in b/tests/server/keytab-t.in new file mode 100644 index 0000000..4a8be77 --- /dev/null +++ b/tests/server/keytab-t.in @@ -0,0 +1,75 @@ +#!/usr/bin/perl -w +# $Id: backend-t.in 3547 2007-09-14 23:18:48Z rra $ +# +# t/keytab.t -- Tests for the keytab-backend dispatch code. + +use strict; +use vars qw($CONFIG $KADMIN $SYSLOG $TMP); + +use IO::String; +use Test::More tests => 43; + +# Load the keytab-backend code and override various settings. +$SYSLOG = 0; +eval { do '@abs_top_srcdir@/server/keytab-backend' }; +$CONFIG = '@abs_top_srcdir@/tests/data/allow-extract'; +$KADMIN = '@abs_top_srcdir@/tests/data/fake-kadmin'; +$TMP = '.'; + +# Run the keytab backend. +sub run_backend { + my (@args) = @_; + my $result; + my $output = IO::String->new (\$result); + $output->autoflush (1); + select $output; + eval { download (@args) }; + my $error = $@; + select STDOUT; + return ($result, $error); +} + +# The actual tests. +$ENV{REMOTE_USER} = 'admin'; +my ($out, $err) = run_backend (); +is ($err, "keytab-backend: invalid arguments: \n", 'Fails with no arguments'); +is ($out, '', ' and produces no output'); +($out, $err) = run_backend ('foo', 'bar', 'baz'); +is ($err, "keytab-backend: invalid arguments: foo bar baz\n", + 'Fails with three arguments'); +is ($out, '', ' and produces no output'); +for my $bad (qw{service service\*@example =@example host/foo+bar@example + rcmd.foo@EXAMPLE host/foo/bar@EXAMPLE /bar@EXAMPLE.NET + bar/@EXAMPLE.NET bar/bar@}) { + ($out, $err) = run_backend ('keytab', $bad); + is ($err, "keytab-backend: bad principal name $bad\n", + "Invalid principal $bad"); + is ($out, '', ' and produces no output'); +} +for my $bad (qw{service/foo@EXAMPLE.ORGA bar@EXAMPLE.NET + host/example.net@EXAMPLE.ORG aservice/foo@EXAMPLE.ORG}) { + ($out, $err) = run_backend ('keytab', $bad); + is ($err, + "keytab-backend: permission denied: admin may not retrieve $bad\n", + "Permission denied for $bad"); + is ($out, '', ' and produces no output'); +} +for my $good (qw{service/foo@EXAMPLE.ORG foo/bar@EXAMPLE.NET + host/example.org@EXAMPLE.ORG}) { + ($out, $err) = run_backend ($good); + is ($err, '', "Success for good keytab $good"); + is ($out, "$good\n", ' and the right output'); + ok (! -f "$TMP/keytab$$", ' and the file is gone'); +} +($out, $err) = run_backend ('keytab', 'error@EXAMPLE.ORG'); +is ($err, "keytab-backend: retrieve of error\@EXAMPLE.ORG failed for" + . " admin: kadmin.local exited with status 1\n", + 'Good error on kadmin failure'); +is ($out, '', ' and no output'); + +# Test a configuration failure. +$CONFIG = '/path/to/bad/file'; +($out, $err) = run_backend ('get', 'service/foo@EXAMPLE.ORG'); +like ($err, qr{^keytab-backend: cannot open /path/to/bad/file: }, + 'Fails with bad configuration file'); +is ($out, '', ' and produces no output'); |