summaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2010-02-20 20:30:37 -0800
committerRuss Allbery <rra@stanford.edu>2010-02-20 20:30:37 -0800
commit4f863ccc9531130be3f4aecea341a0e8a66c6f8c (patch)
tree392e4953a3c2c6b77e2aeb8473c2ee17aa35b3a5 /tests/server
parenta3ee976840e97d37022ec117bae09fef25ac4385 (diff)
wallet-backend gets the third store argument from stdin if missing
If there is no third argument to store, read it from standard input instead. This is the preferred way of running wallet-backend, using stdin=last support from remctl 2.14 and later. Receiving the third argument as a regular argument continues to be supported for backward compatibility.
Diffstat (limited to 'tests/server')
-rwxr-xr-xtests/server/backend-t26
1 files changed, 23 insertions, 3 deletions
diff --git a/tests/server/backend-t b/tests/server/backend-t
index 2fc6a53..b58d02c 100755
--- a/tests/server/backend-t
+++ b/tests/server/backend-t
@@ -9,7 +9,7 @@
# 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,6 +163,7 @@ package main;
$INC{'Wallet/Server.pm'} = 'FAKE';
my $OUTPUT;
our $SYSLOG = \$OUTPUT;
+my $INPUT = '';
eval { do "$ENV{SOURCE}/../server/wallet-backend" };
# Run the wallet backend. This fun hack takes advantage of the fact that the
@@ -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') {
@@ -413,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');
@@ -468,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.