aboutsummaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2010-02-21 17:45:55 -0800
committerRuss Allbery <rra@stanford.edu>2010-02-21 17:45:55 -0800
commit60210334fa3dbd5dd168199063c6ee850d750d0c (patch)
tree31e832ba6788076075d38e20ffd27ebf09430407 /tests/server
parente571a8eb96f42de5a114cf11ff1c3d63e5a8d301 (diff)
Imported Upstream version 0.10
Diffstat (limited to 'tests/server')
-rwxr-xr-x[-rw-r--r--]tests/server/admin-t (renamed from tests/server/admin-t.in)72
-rwxr-xr-x[-rw-r--r--]tests/server/backend-t (renamed from tests/server/backend-t.in)38
-rwxr-xr-x[-rw-r--r--]tests/server/keytab-t (renamed from tests/server/keytab-t.in)9
-rw-r--r--tests/server/pod-t.in23
-rwxr-xr-xtests/server/report-t151
5 files changed, 199 insertions, 94 deletions
diff --git a/tests/server/admin-t.in b/tests/server/admin-t
index be40880..5bde104 100644..100755
--- a/tests/server/admin-t.in
+++ b/tests/server/admin-t
@@ -1,23 +1,21 @@
#!/usr/bin/perl -w
-# $Id$
#
# Tests for the wallet-admin dispatch code.
#
# Written by Russ Allbery <rra@stanford.edu>
-# Copyright 2008 Board of Trustees, Leland Stanford Jr. University
+# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.
use strict;
-use Test::More tests => 54;
+use Test::More tests => 36;
# Create a dummy class for Wallet::Admin that prints what method was called
# with its arguments and returns data for testing.
package Wallet::Admin;
-use vars qw($empty $error);
+use vars qw($error);
$error = 0;
-$empty = 0;
sub error {
if ($error) {
@@ -45,19 +43,6 @@ sub initialize {
return 1;
}
-sub list_objects {
- print "list_objects\n";
- return if ($error or $empty);
- return ([ keytab => 'host/windlord.stanford.edu' ],
- [ file => 'unix-wallet-password' ]);
-}
-
-sub list_acls {
- print "list_acls\n";
- return if ($error or $empty);
- return ([ 1, 'ADMIN' ], [ 2, 'group/admins' ], [ 4, 'group/users' ]);
-}
-
sub register_object {
shift;
print "register_object @_\n";
@@ -76,7 +61,7 @@ sub register_verifier {
# Wallet::Admin package has already been loaded.
package main;
$INC{'Wallet/Admin.pm'} = 'FAKE';
-eval { do '@abs_top_srcdir@/server/wallet-admin' };
+eval { do "$ENV{SOURCE}/../server/wallet-admin" };
# Run the wallet admin client. This fun hack takes advantage of the fact that
# the wallet admin client is written in Perl so that we can substitute our own
@@ -99,10 +84,9 @@ is ($err, "unknown command foo\n", 'Unknown command');
is ($out, "new\n", ' and nothing ran');
# Check too few and too many arguments for every command.
-my %commands = (destroy => [0, 0],
- initialize => [1, 1],
- list => [1, 1],
- register => [3, 3]);
+my %commands = (destroy => [0, 0],
+ initialize => [1, 1],
+ register => [3, 3]);
for my $command (sort keys %commands) {
my ($min, $max) = @{ $commands{$command} };
if ($min > 0) {
@@ -111,10 +95,12 @@ for my $command (sort keys %commands) {
"Too few arguments for $command");
is ($out, "new\n", ' and nothing ran');
}
- ($out, $err) = run_admin ($command, ('foo') x ($max + 1));
- is ($err, "too many arguments to $command\n",
- "Too many arguments for $command");
- is ($out, "new\n", ' and nothing ran');
+ if ($max >= 0) {
+ ($out, $err) = run_admin ($command, ('foo') x ($max + 1));
+ is ($err, "too many arguments to $command\n",
+ "Too many arguments for $command");
+ is ($out, "new\n", ' and nothing ran');
+ }
}
# Test destroy.
@@ -150,22 +136,6 @@ is ($out, "new\n", ' and nothing was run');
is ($err, '', 'Initialize succeeds with a principal');
is ($out, "new\ninitialize rra\@stanford.edu\n", ' and runs the right code');
-# Test list.
-($out, $err) = run_admin ('list', 'foo');
-is ($err, "only objects or acls are supported for list\n",
- 'List requires a known object');
-is ($out, "new\n", ' and nothing was run');
-($out, $err) = run_admin ('list', 'objects');
-is ($err, '', 'List succeeds for objects');
-is ($out, "new\nlist_objects\n"
- . "keytab host/windlord.stanford.edu\nfile unix-wallet-password\n",
- ' and returns the right output');
-($out, $err) = run_admin ('list', 'acls');
-is ($err, '', 'List succeeds for ACLs');
-is ($out, "new\nlist_acls\n"
- . "ADMIN (ACL ID: 1)\ngroup/admins (ACL ID: 2)\ngroup/users (ACL ID: 4)\n",
- ' and returns the right output');
-
# Test register.
($out, $err) = run_admin ('register', 'foo', 'foo', 'Foo::Bar');
is ($err, "only object or verifier is supported for register\n",
@@ -191,12 +161,6 @@ is ($out, "new\n"
is ($err, "some error\n", 'Error handling succeeds for initialize');
is ($out, "new\ninitialize rra\@stanford.edu\n",
' and calls the right methods');
-($out, $err) = run_admin ('list', 'objects');
-is ($err, "some error\n", 'Error handling succeeds for list objects');
-is ($out, "new\nlist_objects\n", ' and calls the right methods');
-($out, $err) = run_admin ('list', 'acls');
-is ($err, "some error\n", 'Error handling succeeds for list acls');
-is ($out, "new\nlist_acls\n", ' and calls the right methods');
($out, $err) = run_admin ('register', 'object', 'foo', 'Foo::Object');
is ($err, "some error\n", 'Error handling succeeds for register object');
is ($out, "new\nregister_object foo Foo::Object\n",
@@ -205,13 +169,3 @@ is ($out, "new\nregister_object foo Foo::Object\n",
is ($err, "some error\n", 'Error handling succeeds for register verifier');
is ($out, "new\nregister_verifier foo Foo::Verifier\n",
' and calls the right methods');
-
-# Test empty lists.
-$Wallet::Admin::error = 0;
-$Wallet::Admin::empty = 1;
-($out, $err) = run_admin ('list', 'objects');
-is ($err, '', 'list objects runs with an empty list with no errors');
-is ($out, "new\nlist_objects\n", ' and calls the right methods');
-($out, $err) = run_admin ('list', 'acls');
-is ($err, '', 'list acls runs with an empty list and no errors');
-is ($out, "new\nlist_acls\n", ' and calls the right methods');
diff --git a/tests/server/backend-t.in b/tests/server/backend-t
index e1518d8..b58d02c 100644..100755
--- a/tests/server/backend-t.in
+++ b/tests/server/backend-t
@@ -1,15 +1,15 @@
#!/usr/bin/perl -w
-# $Id$
#
# Tests for the wallet-backend dispatch code.
#
# Written by Russ Allbery <rra@stanford.edu>
-# Copyright 2006, 2007, 2008 Board of Trustees, Leland Stanford Jr. University
+# Copyright 2006, 2007, 2008, 2009, 2010
+# Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.
use strict;
-use Test::More tests => 1263;
+use Test::More tests => 1269;
# Create a dummy class for Wallet::Server that prints what method was called
# with its arguments and returns data for testing.
@@ -163,7 +163,8 @@ package main;
$INC{'Wallet/Server.pm'} = 'FAKE';
my $OUTPUT;
our $SYSLOG = \$OUTPUT;
-eval { do '@abs_top_srcdir@/server/wallet-backend' };
+my $INPUT = '';
+eval { do "$ENV{SOURCE}/../server/wallet-backend" };
# Run the wallet backend. This fun hack takes advantage of the fact that the
# wallet backend is written in Perl so that we can substitute our own
@@ -173,6 +174,8 @@ sub run_backend {
my $result = '';
open (OUTPUT, '>', \$result) or die "cannot create output string: $!\n";
select OUTPUT;
+ close STDIN;
+ open (STDIN, '<', \$INPUT) or die "cannot change stdin: $!\n";
local $| = 1;
eval { command (@args) };
my $error = $@;
@@ -224,7 +227,7 @@ my %commands = (autocreate => [2, 2],
setacl => [4, 4],
setattr => [4, 9],
show => [2, 2],
- store => [3, 3]);
+ store => [2, 3]);
my %acl_commands = (add => [3, 3],
create => [1, 1],
destroy => [1, 1],
@@ -326,6 +329,7 @@ for my $command (qw/autocreate create destroy setacl setattr store/) {
$method ||= $command;
my @extra = ('foo') x ($commands{$command}[0] - 2);
my $extra = @extra ? join (' ', '', @extra) : '';
+ $extra = ' ' if $command eq 'store';
($out, $err) = run_backend ($command, 'type', 'name', @extra);
my $ran;
if ($command eq 'store') {
@@ -339,7 +343,11 @@ for my $command (qw/autocreate create destroy setacl setattr store/) {
is ($out, "$new\n$method type name$extra\n",
' and ran the right method');
($out, $err) = run_backend ($command, 'error', 'name', @extra);
- $ran = "$command error name" . (@extra ? " @extra" : '');
+ if ($command eq 'store') {
+ $ran = "$command error name";
+ } else {
+ $ran = "$command error name" . (@extra ? " @extra" : '');
+ }
is ($err, "error count $error\n", "Command $command ran with errors");
is ($OUTPUT, "command $ran from admin (1.2.3.4) failed: error count"
. " $error\n", ' and syslog correct');
@@ -409,7 +417,7 @@ for my $command (qw/check expires get getacl getattr history owner show/) {
' and ran the right method with output');
}
($out, $err) = run_backend ($command, 'error', 'name', @extra);
- my $ran = "$command error name" . (@extra ? " @extra" : '');
+ $ran = "$command error name" . (@extra ? " @extra" : '');
is ($err, "error count $error\n", "Command $command ran with errors");
is ($OUTPUT, "command $ran from admin (1.2.3.4) failed: error count"
. " $error\n", ' and syslog correct');
@@ -464,6 +472,22 @@ for my $command (sort keys %flag_commands) {
$error++;
}
+# Special check for store allowing nul characters on standard input.
+$INPUT = "Some data\000with a nul character";
+($out, $err) = run_backend ('store', 'type', 'name');
+is ($err, '', 'store with nul data ran with no errors');
+is ($OUTPUT, "command store type name from admin (1.2.3.4) succeeded\n",
+ ' and success logged');
+is ($out, "$new\nstore type name $INPUT\n",
+ ' and ran the right method');
+$INPUT = '';
+($out, $err) = run_backend ('store', 'type', 'name');
+is ($err, '', 'store with empty stdin data ran with no errors');
+is ($OUTPUT, "command store type name from admin (1.2.3.4) succeeded\n",
+ ' and success logged');
+is ($out, "$new\nstore type name \n",
+ ' and ran the right method');
+
# Almost done. All that remains is to test the robustness of the bad
# character checks against every possible character and test permitting the
# empty argument.
diff --git a/tests/server/keytab-t.in b/tests/server/keytab-t
index f74267d..2a0ceed 100644..100755
--- a/tests/server/keytab-t.in
+++ b/tests/server/keytab-t
@@ -1,10 +1,9 @@
#!/usr/bin/perl -w
-# $Id: backend-t.in 3547 2007-09-14 23:18:48Z rra $
#
# Tests for the keytab-backend dispatch code.
#
# Written by Russ Allbery <rra@stanford.edu>
-# Copyright 2006, 2007 Board of Trustees, Leland Stanford Jr. University
+# Copyright 2006, 2007, 2010 Board of Trustees, Leland Stanford Jr. University
#
# See LICENSE for licensing terms.
@@ -16,9 +15,9 @@ use Test::More tests => 63;
# Load the keytab-backend code and override various settings.
my $OUTPUT;
$SYSLOG = \$OUTPUT;
-eval { do '@abs_top_srcdir@/server/keytab-backend' };
-$CONFIG = '@abs_top_srcdir@/tests/data/allow-extract';
-$KADMIN = '@abs_top_srcdir@/tests/data/fake-kadmin';
+eval { do "$ENV{SOURCE}/../server/keytab-backend" };
+$CONFIG = "$ENV{SOURCE}/data/allow-extract";
+$KADMIN = "$ENV{SOURCE}/data/fake-kadmin";
$TMP = '.';
# Run the keytab backend.
diff --git a/tests/server/pod-t.in b/tests/server/pod-t.in
deleted file mode 100644
index fd939a5..0000000
--- a/tests/server/pod-t.in
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/perl
-# $Id$
-#
-# tests/server/pod-t -- 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(keytab-backend wallet-admin wallet-backend);
-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@/server/$file", "server/$file");
- }
-}
diff --git a/tests/server/report-t b/tests/server/report-t
new file mode 100755
index 0000000..285ee5a
--- /dev/null
+++ b/tests/server/report-t
@@ -0,0 +1,151 @@
+#!/usr/bin/perl -w
+#
+# Tests for the wallet-report dispatch code.
+#
+# Written by Russ Allbery <rra@stanford.edu>
+# Copyright 2008, 2009, 2010 Board of Trustees, Leland Stanford Jr. University
+#
+# See LICENSE for licensing terms.
+
+use strict;
+use Test::More tests => 32;
+
+# Create a dummy class for Wallet::Report that prints what method was called
+# with its arguments and returns data for testing.
+package Wallet::Report;
+
+use vars qw($empty $error);
+$error = 0;
+$empty = 0;
+
+sub error {
+ if ($error) {
+ return "some error";
+ } else {
+ return;
+ }
+}
+
+sub new {
+ print "new\n";
+ return bless ({}, 'Wallet::Report');
+}
+
+sub acls {
+ shift;
+ print "acls @_\n";
+ return if ($error or $empty);
+ return ([ 1, 'ADMIN' ], [ 2, 'group/admins' ], [ 4, 'group/users' ]);
+}
+
+sub objects {
+ shift;
+ print "objects @_\n";
+ return if ($error or $empty);
+ return ([ keytab => 'host/windlord.stanford.edu' ],
+ [ file => 'unix-wallet-password' ]);
+}
+
+sub owners {
+ shift;
+ print "owners @_\n";
+ return if ($error or $empty);
+ return ([ krb5 => 'admin@EXAMPLE.COM' ]);
+}
+
+# Back to the main package and the actual test suite. Lie about whether the
+# Wallet::Report package has already been loaded.
+package main;
+$INC{'Wallet/Report.pm'} = 'FAKE';
+eval { do "$ENV{SOURCE}/../server/wallet-report" };
+
+# Run the wallet report client. This fun hack takes advantage of the fact
+# that the wallet report client is written in Perl so that we can substitute
+# our own Wallet::Report class.
+sub run_report {
+ my (@args) = @_;
+ my $result = '';
+ open (OUTPUT, '>', \$result) or die "cannot create output string: $!\n";
+ select OUTPUT;
+ local $| = 1;
+ eval { command (@args) };
+ my $error = $@;
+ select STDOUT;
+ return ($result, $error);
+}
+
+# Now for the actual tests. First check for unknown commands.
+my ($out, $err) = run_report ('foo');
+is ($err, "unknown command foo\n", 'Unknown command');
+is ($out, "new\n", ' and nothing ran');
+
+# Check too few and too many arguments for every command.
+my %commands = (acls => [0, 3],
+ objects => [0, 2],
+ owners => [2, 2]);
+for my $command (sort keys %commands) {
+ my ($min, $max) = @{ $commands{$command} };
+ if ($min > 0) {
+ ($out, $err) = run_report ($command, ('foo') x ($min - 1));
+ is ($err, "too few arguments to $command\n",
+ "Too few arguments for $command");
+ is ($out, "new\n", ' and nothing ran');
+ }
+ if ($max >= 0) {
+ ($out, $err) = run_report ($command, ('foo') x ($max + 1));
+ is ($err, "too many arguments to $command\n",
+ "Too many arguments for $command");
+ is ($out, "new\n", ' and nothing ran');
+ }
+}
+
+# Test the report methods.
+($out, $err) = run_report ('acls');
+is ($err, '', 'List succeeds for ACLs');
+is ($out, "new\nacls \n"
+ . "ADMIN (ACL ID: 1)\ngroup/admins (ACL ID: 2)\ngroup/users (ACL ID: 4)\n",
+ ' and returns the right output');
+($out, $err) = run_report ('acls', 'entry', 'foo', 'foo');
+is ($err, '', 'List succeeds for ACLs');
+is ($out, "new\nacls entry foo foo\n"
+ . "ADMIN (ACL ID: 1)\ngroup/admins (ACL ID: 2)\ngroup/users (ACL ID: 4)\n",
+ ' and returns the right output');
+($out, $err) = run_report ('objects');
+is ($err, '', 'List succeeds for objects');
+is ($out, "new\nobjects \n"
+ . "keytab host/windlord.stanford.edu\nfile unix-wallet-password\n",
+ ' and returns the right output');
+($out, $err) = run_report ('objects', 'type', 'foo');
+is ($err, '', 'List succeeds for objects type foo');
+is ($out, "new\nobjects type foo\n"
+ . "keytab host/windlord.stanford.edu\nfile unix-wallet-password\n",
+ ' and returns the right output');
+($out, $err) = run_report ('owners', '%', '%');
+is ($err, '', 'Report succeeds for owners');
+is ($out, "new\nowners % %\nkrb5 admin\@EXAMPLE.COM\n",
+ ' and returns the right output');
+
+# Test error handling.
+$Wallet::Report::error = 1;
+($out, $err) = run_report ('acls');
+is ($err, "some error\n", 'Error handling succeeds for list acls');
+is ($out, "new\nacls \n", ' and calls the right methods');
+($out, $err) = run_report ('objects');
+is ($err, "some error\n", 'Error handling succeeds for list objects');
+is ($out, "new\nobjects \n", ' and calls the right methods');
+($out, $err) = run_report ('owners', 'foo', 'bar');
+is ($err, "some error\n", 'Error handling succeeds for report owners');
+is ($out, "new\nowners foo bar\n", ' and calls the right methods');
+
+# Test empty lists.
+$Wallet::Report::error = 0;
+$Wallet::Report::empty = 1;
+($out, $err) = run_report ('acls');
+is ($err, '', 'list acls runs with an empty list and no errors');
+is ($out, "new\nacls \n", ' and calls the right methods');
+($out, $err) = run_report ('objects');
+is ($err, '', 'list objects runs with an empty list with no errors');
+is ($out, "new\nobjects \n", ' and calls the right methods');
+($out, $err) = run_report ('owners', 'foo', 'bar');
+is ($err, '', 'report owners runs with an empty list and no errors');
+is ($out, "new\nowners foo bar\n", ' and calls the right methods');