1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 # note: our HTTP server should be standalone and capable of running
4 # generic PSGI/Plack apps.
8 use Time::HiRes qw(gettimeofday tv_interval);
9 use PublicInbox::Spawn qw(which spawn);
10 use PublicInbox::TestCommon;
11 require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status));
12 use Digest::SHA qw(sha1_hex);
17 use Socket qw(IPPROTO_TCP TCP_NODELAY SOL_SOCKET);
20 my ($tmpdir, $for_destroy) = tmpdir();
21 my $fifo = "$tmpdir/fifo";
22 ok(defined mkfifo($fifo, 0777), 'created FIFO');
23 my $err = "$tmpdir/stderr.log";
24 my $out = "$tmpdir/stdout.log";
25 my $psgi = "./t/httpd-corner.psgi";
26 my $sock = tcp_server() or die;
27 my @zmods = qw(PublicInbox::GzipFilter IO::Uncompress::Gunzip);
29 # make sure stdin is not a pipe for lsof test to check for leaking pipes
30 open(STDIN, '<', '/dev/null') or die 'no /dev/null: $!';
32 # Make sure we don't clobber socket options set by systemd or similar
33 # using socket activation:
34 my ($defer_accept_val, $accf_arg, $TCP_DEFER_ACCEPT);
36 $TCP_DEFER_ACCEPT = eval { Socket::TCP_DEFER_ACCEPT() } // 9;
37 setsockopt($sock, IPPROTO_TCP, $TCP_DEFER_ACCEPT, 5) or die;
38 my $x = getsockopt($sock, IPPROTO_TCP, $TCP_DEFER_ACCEPT);
39 defined $x or die "getsockopt: $!";
40 $defer_accept_val = unpack('i', $x);
41 if ($defer_accept_val <= 0) {
42 die "unexpected TCP_DEFER_ACCEPT value: $defer_accept_val";
44 } elsif ($^O eq 'freebsd' && system('kldstat -m accf_data >/dev/null') == 0) {
45 require PublicInbox::Daemon;
46 my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
47 $accf_arg = pack('a16a240', 'dataready', '');
48 setsockopt($sock, SOL_SOCKET, $var, $accf_arg) or die "setsockopt: $!";
52 my $s = IO::Socket::UNIX->new(
54 Type => Socket::SOCK_STREAM(),
61 my $upath = "$tmpdir/s";
62 my $unix = unix_server($upath);
63 ok($unix, 'UNIX socket created');
65 my $spawn_httpd = sub {
67 my $cmd = [ '-httpd', @args, "--stdout=$out", "--stderr=$err", $psgi ];
68 $td = start_script($cmd, undef, { 3 => $sock, 4 => $unix });
72 if ('test worker death') {
73 my $conn = conn_for($sock, 'killed worker');
74 $conn->write("GET /pid HTTP/1.1\r\nHost:example.com\r\n\r\n");
76 while (defined(my $line = $conn->getline)) {
77 next unless $line eq "\r\n";
78 chomp($pid = $conn->getline);
81 like($pid, qr/\A[0-9]+\z/, '/pid response');
82 is(kill('KILL', $pid), 1, 'killed worker');
83 is($conn->getline, undef, 'worker died and EOF-ed client');
85 $conn = conn_for($sock, 'respawned worker');
86 $conn->write("GET /pid HTTP/1.0\r\n\r\n");
87 ok($conn->read(my $buf, 8192), 'read response');
88 my ($head, $body) = split(/\r\n\r\n/, $buf);
90 like($body, qr/\A[0-9]+\z/, '/pid response');
91 isnt($body, $pid, 'respawned worker');
95 my $conn = conn_for($sock, 'streaming callback');
96 $conn->write("GET /callback HTTP/1.0\r\n\r\n");
97 ok($conn->read(my $buf, 8192), 'read response');
98 my ($head, $body) = split(/\r\n\r\n/, $buf);
99 is($body, "hello world\n", 'callback body matches expected');
103 my $conn = conn_for($sock, 'getline-die');
104 $conn->write("GET /getline-die HTTP/1.1\r\nHost: example.com\r\n\r\n");
105 ok($conn->read(my $buf, 8192), 'read some response');
106 like($buf, qr!HTTP/1\.1 200\b[^\r]*\r\n!, 'got some sort of header');
107 is($conn->read(my $nil, 8192), 0, 'read EOF');
109 my $after = capture($err);
110 is(scalar(grep(/GETLINE FAIL/, @$after)), 1, 'failure logged');
111 is(scalar(grep(/CLOSE FAIL/, @$after)), 1, 'body->close not called');
115 my $conn = conn_for($sock, 'close-die');
116 $conn->write("GET /close-die HTTP/1.1\r\nHost: example.com\r\n\r\n");
117 ok($conn->read(my $buf, 8192), 'read some response');
118 like($buf, qr!HTTP/1\.1 200\b[^\r]*\r\n!, 'got some sort of header');
119 is($conn->read(my $nil, 8192), 0, 'read EOF');
121 my $after = capture($err);
122 is(scalar(grep(/GETLINE FAIL/, @$after)), 0, 'getline not failed');
123 is(scalar(grep(/CLOSE FAIL/, @$after)), 1, 'body->close not called');
128 my $r = $conn->read(my $buf, 8192);
129 # ECONNRESET and $r==0 are both observed on FreeBSD 11.2
131 ok($!{ECONNRESET}, 'ECONNRESET on read (BSD sometimes)');
133 like($buf, qr!\AHTTP/1\.\d 400 !, 'got 400 response');
135 is($r, 0, 'got EOF (BSD sometimes)');
137 close($conn); # ensure we don't get SIGPIPE later
141 local $SIG{PIPE} = 'IGNORE';
142 my $conn = conn_for($sock, 'excessive header');
143 $conn->write("GET /callback HTTP/1.0\r\n");
144 foreach my $i (1..500000) {
145 last unless $conn->write("X-xxxxxJunk-$i: omg\r\n");
147 ok(!$conn->write("\r\n"), 'broken request');
152 my $conn = conn_for($sock, 'excessive body Content-Length');
153 my $n = (10 * 1024 * 1024) + 1;
154 $conn->write("PUT /sha1 HTTP/1.0\r\nContent-Length: $n\r\n\r\n");
155 my $r = $conn->read(my $buf, 8192);
156 ok($r > 0, 'read response');
157 my ($head, $body) = split(/\r\n\r\n/, $buf);
158 like($head, qr/\b413\b/, 'got 413 response');
162 my $conn = conn_for($sock, 'excessive body chunked');
163 my $n = (10 * 1024 * 1024) + 1;
164 $conn->write("PUT /sha1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n");
165 $conn->write("\r\n".sprintf("%x\r\n", $n));
166 my $r = $conn->read(my $buf, 8192);
167 ok($r > 0, 'read response');
168 my ($head, $body) = split(/\r\n\r\n/, $buf);
169 like($head, qr/\b413\b/, 'got 413 response');
173 my $conn = conn_for($sock, '1.1 Transfer-Encoding bogus');
174 $conn->write("PUT /sha1 HTTP/1.1\r\nTransfer-Encoding: bogus\r\n\r\n");
175 $conn->read(my $buf, 4096);
176 like($buf, qr!\AHTTP/1\.[0-9] 400 !, 'got 400 response on bogus TE');
179 my $conn = conn_for($sock, '1.1 Content-Length bogus');
180 $conn->write("PUT /sha1 HTTP/1.1\r\nContent-Length: 3.3\r\n\r\n");
181 $conn->read(my $buf, 4096);
182 like($buf, qr!\AHTTP/1\.[0-9] 400 !, 'got 400 response on bad length');
186 my $req = "PUT /sha1 HTTP/1.1\r\nContent-Length: 3\r\n" .
187 "Content-Length: 3\r\n\r\n";
188 # this is stricter than it needs to be. Due to the way
189 # Plack::HTTPParser, PSGI specs, and how hash tables work in common
190 # languages; it's not possible to tell the difference between folded
191 # and intentionally bad commas (e.g. "Content-Length: 3, 3")
193 require Plack::HTTPParser; # XS or pure Perl
194 require Data::Dumper;
195 Plack::HTTPParser::parse_http_request($req, my $env = {});
196 diag Data::Dumper::Dumper($env); # "Content-Length: 3, 3"
198 my $conn = conn_for($sock, '1.1 Content-Length dupe');
200 $conn->read(my $buf, 4096);
201 like($buf, qr!\AHTTP/1\.[0-9] 400 !, 'got 400 response on dupe length');
205 my $conn = conn_for($sock, 'chunk with pipeline');
207 my $payload = 'b'x$n;
208 $conn->write("PUT /sha1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n");
209 $conn->write("\r\n".sprintf("%x\r\n", $n));
210 $conn->write($payload . "\r\n0\r\n\r\nGET /empty HTTP/1.0\r\n\r\n");
211 $conn->read(my $buf, 4096);
213 $lim++ while ($conn->read($buf, 4096, length($buf)) && $lim < 9);
214 my $exp = sha1_hex($payload);
215 like($buf, qr!\r\n\r\n${exp}HTTP/1\.0 200 OK\r\n!s,
216 'chunk parser can handled pipelined requests');
219 # Unix domain sockets
221 my $u = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => $upath);
222 ok($u, 'unix socket connected');
223 $u->write("GET /host-port HTTP/1.0\r\n\r\n");
224 $u->read(my $buf, 4096);
225 like($buf, qr!\r\n\r\n127\.0\.0\.1:0\z!,
226 'set REMOTE_ADDR and REMOTE_PORT for Unix socket');
230 my ($dest, $msg) = @_;
231 my $conn = tcp_connect($dest);
232 ok($conn, "connected for $msg");
233 setsockopt($conn, IPPROTO_TCP, TCP_NODELAY, 1);
238 my $conn = conn_for($sock, 'host-port');
239 $conn->write("GET /host-port HTTP/1.0\r\n\r\n");
240 $conn->read(my $buf, 4096);
241 my ($head, $body) = split(/\r\n\r\n/, $buf);
242 my ($addr, $port) = split(/:/, $body);
243 is($addr, $conn->sockhost, 'host matches addr');
244 is($port, $conn->sockport, 'port matches');
247 # graceful termination
249 my $conn = conn_for($sock, 'graceful termination via slow header');
250 $conn->write("GET /slow-header HTTP/1.0\r\n" .
251 "X-Check-Fifo: $fifo\r\n\r\n");
252 open my $f, '>', $fifo or die "open $fifo: $!\n";
254 ok(print($f "hello\n"), 'wrote something to fifo');
255 is($td->kill, 1, 'started graceful shutdown');
256 ok(print($f "world\n"), 'wrote else to fifo');
257 close $f or die "close fifo: $!\n";
258 $conn->read(my $buf, 8192);
259 my ($head, $body) = split(/\r\n\r\n/, $buf, 2);
260 like($head, qr!\AHTTP/1\.[01] 200 OK!, 'got 200 for slow-header');
261 is($body, "hello\nworld\n", 'read expected body');
263 is($?, 0, 'no error');
264 $spawn_httpd->('-W0');
268 my $conn = conn_for($sock, 'graceful termination via slow-body');
269 $conn->write("GET /slow-body HTTP/1.0\r\n" .
270 "X-Check-Fifo: $fifo\r\n\r\n");
271 open my $f, '>', $fifo or die "open $fifo: $!\n";
274 $conn->sysread($buf, 8192);
275 like($buf, qr!\AHTTP/1\.[01] 200 OK!, 'got 200 for slow-body');
276 like($buf, qr!\r\n\r\n!, 'finished HTTP response header');
278 foreach my $c ('a'..'c') {
280 ok(print($f $c), 'wrote line to fifo');
281 $conn->sysread($buf, 8192);
282 is($buf, $c, 'got trickle for reading');
284 is($td->kill, 1, 'started graceful shutdown');
285 ok(print($f "world\n"), 'wrote else to fifo');
286 close $f or die "close fifo: $!\n";
287 $conn->sysread($buf, 8192);
288 is($buf, "world\n", 'read expected body');
289 is($conn->sysread($buf, 8192), 0, 'got EOF from server');
291 is($?, 0, 'no error');
292 $spawn_httpd->('-W0');
295 sub delay { select(undef, undef, undef, shift || rand(0.02)) }
297 my $str = 'abcdefghijklmnopqrstuvwxyz';
298 my $len = length $str;
299 is($len, 26, 'got the alphabet');
300 my $check_self = sub {
302 vec(my $rbits, fileno($conn), 1) = 1;
303 select($rbits, undef, undef, 30) or Carp::confess('timed out');
304 $conn->read(my $buf, 4096);
305 my ($head, $body) = split(/\r\n\r\n/, $buf, 2);
306 like($head, qr/\r\nContent-Length: 40\r\n/s, 'got expected length');
307 is($body, sha1_hex($str), 'read expected body');
311 which('curl') or skip('curl(1) missing', 4);
312 my $base = 'http://' . $sock->sockhost . ':' . $sock->sockport;
313 my $url = "$base/sha1";
315 pipe($r, $w) or die "pipe: $!";
316 my $cmd = [qw(curl --tcp-nodelay --no-buffer -T- -HExpect: -sS), $url];
317 open my $cout, '+>', undef or die;
318 open my $cerr, '>', undef or die;
319 my $rdr = { 0 => $r, 1 => $cout, 2 => $cerr };
320 my $pid = spawn($cmd, undef, $rdr);
321 close $r or die "close read pipe: $!";
322 foreach my $c ('a'..'z') {
323 print $w $c or die "failed to write to curl: $!";
326 close $w or die "close write pipe: $!";
328 is($?, 0, 'curl exited successfully');
329 is(-s $cerr, 0, 'no errors from curl');
330 seek($cout, 0, SEEK_SET);
331 is(<$cout>, sha1_hex($str), 'read expected body');
333 open my $fh, '-|', qw(curl -sS), "$base/async-big" or die $!;
337 my $r = sysread($fh, my $buf, 4096) or last;
339 $buf =~ /\A\0+\z/ or $non_zero++;
341 close $fh or die "curl errored out \$?=$?";
342 is($n, 30 * 1024 * 1024, 'got expected output from curl');
343 is($non_zero, 0, 'read all zeros');
345 require_mods(@zmods, 1);
346 open $fh, '-|', qw(curl -sS), "$base/psgi-return-gzip" or die;
348 my $buf = do { local $/; <$fh> };
349 close $fh or die "curl errored out \$?=$?";
350 IO::Uncompress::Gunzip::gunzip(\$buf => \(my $out));
351 is($out, "hello world\n");
355 my $conn = conn_for($sock, 'psgi_return ENOENT');
356 print $conn "GET /psgi-return-enoent HTTP/1.1\r\n\r\n" or die;
358 sysread($conn, $buf, 16384, length($buf)) until $buf =~ /\r\n\r\n/;
359 like($buf, qr!HTTP/1\.[01] 500\b!, 'got 500 error on ENOENT');
363 my $conn = conn_for($sock, '1.1 pipeline together');
364 $conn->write("PUT /sha1 HTTP/1.1\r\nUser-agent: hello\r\n\r\n" .
365 "PUT /sha1 HTTP/1.1\r\n\r\n");
368 until (scalar(@r) >= 2) {
369 my $r = $conn->sysread(my $tmp, 4096);
370 die $! unless defined $r;
371 die "EOF <$buf>" unless $r;
373 @r = ($buf =~ /\r\n\r\n([a-f0-9]{40})/g);
375 is(2, scalar @r, 'got 2 responses');
377 foreach my $hex (@r) {
378 is($hex, sha1_hex(''), "read expected body $i");
384 my $conn = conn_for($sock, 'no TCP_CORK on empty body');
385 $conn->write("GET /empty HTTP/1.1\r\nHost:example.com\r\n\r\n");
387 my $t0 = [ gettimeofday ];
388 until ($buf =~ /\r\n\r\n/s) {
389 $conn->sysread($buf, 4096, length($buf));
391 my $elapsed = tv_interval($t0, [ gettimeofday ]);
392 ok($elapsed < 0.190, 'no 200ms TCP cork delay on empty body');
396 my $conn = conn_for($sock, 'graceful termination during slow request');
397 $conn->write("PUT /sha1 HTTP/1.0\r\nContent-Length: $len\r\n\r\n");
399 # XXX ugh, want a reliable and non-intrusive way to detect
400 # that the server has started buffering our partial request so we
401 # can reliably test graceful termination. Maybe making this and
402 # similar tests dependent on Linux strace is a possibility?
405 is($td->kill, 1, 'start graceful shutdown');
407 foreach my $c ('a'..'z') {
408 $n += $conn->write($c);
410 ok(kill(0, $td->{pid}), 'graceful shutdown did not kill httpd');
411 is($n, $len, 'wrote alphabet');
412 $check_self->($conn);
414 is($?, 0, 'no error');
415 $spawn_httpd->('-W0');
418 # various DoS attacks against the chunk parser:
420 local $SIG{PIPE} = 'IGNORE';
421 my $conn = conn_for($sock, '1.1 chunk header excessive');
422 $conn->write("PUT /sha1 HTTP/1.1\r\nTransfer-Encoding:chunked\r\n\r\n");
425 while ($w = $conn->write('ffffffff')) {
428 ok($!, 'got error set in $!');
429 is($w, undef, 'write error happened');
430 ok($n > 0, 'was able to write');
432 $conn = conn_for($sock, '1.1 chunk trailer excessive');
433 $conn->write("PUT /sha1 HTTP/1.1\r\nTransfer-Encoding:chunked\r\n\r\n");
434 is($conn->syswrite("1\r\na"), 4, 'wrote first header + chunk');
437 while ($w = $conn->write("\r")) {
440 ok($!, 'got error set in $!');
441 ok($n > 0, 'wrote part of chunk end (\r)');
446 my $conn = conn_for($sock, '1.1 chunked close trickle');
447 $conn->write("PUT /sha1 HTTP/1.1\r\nConnection:close\r\n");
448 $conn->write("Transfer-encoding: chunked\r\n\r\n");
449 foreach my $x ('a'..'z') {
473 $check_self->($conn);
477 my $conn = conn_for($sock, '1.1 chunked close');
478 $conn->write("PUT /sha1 HTTP/1.1\r\nConnection:close\r\n");
479 my $xlen = sprintf('%x', $len);
480 $conn->write("Transfer-Encoding: chunked\r\n\r\n$xlen\r\n" .
481 "$str\r\n0\r\n\r\n");
482 $check_self->($conn);
486 my $conn = conn_for($sock, 'chunked body + pipeline');
487 $conn->write("PUT /sha1 HTTP/1.1\r\n" .
488 "Transfer-Encoding: chunked\r\n");
490 $conn->write("\r\n1\r\n");
494 $conn->write("\r\n0\r\n\r\nPUT /sha1 HTTP/1.1\r\n");
498 until ($buf =~ /\r\n\r\n[a-f0-9]{40}\z/) {
499 $conn->sysread(my $tmp, 4096);
502 my ($head, $body) = split(/\r\n\r\n/, $buf, 2);
503 like($head, qr/\r\nContent-Length: 40\r\n/s, 'got expected length');
504 is($body, sha1_hex('a'), 'read expected body');
506 $conn->write("Connection: close\r\n");
507 $conn->write("Content-Length: $len\r\n\r\n$str");
508 $check_self->($conn);
512 my $conn = conn_for($sock, 'trickle header, one-shot body + pipeline');
513 $conn->write("PUT /sha1 HTTP/1.0\r\n" .
514 "Connection: keep-alive\r\n");
516 $conn->write("Content-Length: $len\r\n\r\n${str}PUT");
518 until ($buf =~ /\r\n\r\n[a-f0-9]{40}\z/) {
519 $conn->sysread(my $tmp, 4096);
522 my ($head, $body) = split(/\r\n\r\n/, $buf, 2);
523 like($head, qr/\r\nContent-Length: 40\r\n/s, 'got expected length');
524 is($body, sha1_hex($str), 'read expected body');
526 $conn->write(" /sha1 HTTP/1.0\r\nContent-Length: $len\r\n\r\n$str");
527 $check_self->($conn);
531 my $conn = conn_for($sock, 'trickle body');
532 $conn->write("PUT /sha1 HTTP/1.0\r\n");
533 $conn->write("Content-Length: $len\r\n\r\n");
534 my $beg = substr($str, 0, 10);
535 my $end = substr($str, 10);
536 is($beg . $end, $str, 'substr setup correct');
541 $check_self->($conn);
545 my $conn = conn_for($sock, 'one-shot write');
546 $conn->write("PUT /sha1 HTTP/1.0\r\n" .
547 "Content-Length: $len\r\n\r\n$str");
548 $check_self->($conn);
552 my $conn = conn_for($sock, 'trickle header, one-shot body');
553 $conn->write("PUT /sha1 HTTP/1.0\r\n");
555 $conn->write("Content-Length: $len\r\n\r\n$str");
556 $check_self->($conn);
560 my $conn = conn_for($sock, '1.1 Connection: close');
561 $conn->write("PUT /sha1 HTTP/1.1\r\nConnection:close\r\n");
563 $conn->write("Content-Length: $len\r\n\r\n$str");
564 $check_self->($conn);
568 my $conn = conn_for($sock, '1.1 pipeline start');
569 $conn->write("PUT /sha1 HTTP/1.1\r\n\r\nPUT");
571 until ($buf =~ /\r\n\r\n[a-f0-9]{40}\z/) {
572 $conn->sysread(my $tmp, 4096);
575 my ($head, $body) = split(/\r\n\r\n/, $buf, 2);
576 like($head, qr/\r\nContent-Length: 40\r\n/s, 'got expected length');
577 is($body, sha1_hex(''), 'read expected body');
580 $conn->write(" /sha1 HTTP/1.1\r\n\r\n");
582 until ($buf =~ /\r\n\r\n[a-f0-9]{40}\z/) {
583 $conn->sysread(my $tmp, 4096);
586 ($head, $body) = split(/\r\n\r\n/, $buf, 2);
587 like($head, qr/\r\nContent-Length: 40\r\n/s, 'got expected length');
588 is($body, sha1_hex(''), 'read expected body #2');
592 skip 'TCP_DEFER_ACCEPT is Linux-only', 1 if $^O ne 'linux';
593 my $var = $TCP_DEFER_ACCEPT;
594 defined(my $x = getsockopt($sock, IPPROTO_TCP, $var)) or die;
595 is(unpack('i', $x), $defer_accept_val,
596 'TCP_DEFER_ACCEPT unchanged if previously set');
599 skip 'SO_ACCEPTFILTER is FreeBSD-only', 1 if $^O ne 'freebsd';
600 skip 'accf_data not loaded: kldload accf_data' if !defined $accf_arg;
601 my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
602 defined(my $x = getsockopt($sock, SOL_SOCKET, $var)) or die;
603 is($x, $accf_arg, 'SO_ACCEPTFILTER unchanged if previously set');
607 skip 'only testing lsof(8) output on Linux', 1 if $^O ne 'linux';
608 skip 'no lsof in PATH', 1 unless which('lsof');
609 my @lsof = `lsof -p $td->{pid}`;
610 is_deeply([grep(/\bdeleted\b/, @lsof)], [], 'no lingering deleted inputs');
612 # filter out pipes inherited from the parent
613 my @this = `lsof -p $$`;
615 my $extract_inodes = sub {
617 my @f = split(' ', $_);
619 $bad = $_ if $inode !~ /\A[0-9]+\z/;
621 } grep (/\bpipe\b/, @_);
623 my %child = $extract_inodes->(@lsof);
624 my %parent = $extract_inodes->(@this);
625 skip("inode not in expected format: $bad", 1) if defined($bad);
626 delete @child{(keys %parent)};
627 is_deeply([], [keys %child], 'no extra pipes with -W0');
630 # ensure compatibility with other PSGI servers
632 require_mods(@zmods, qw(Plack::Test HTTP::Request::Common), 3);
633 use_ok 'HTTP::Request::Common';
634 use_ok 'Plack::Test';
636 open my $olderr, '>&', \*STDERR or die "dup stderr: $!";
637 open my $tmperr, '+>', undef or die;
638 open STDERR, '>&', $tmperr or die;
639 STDERR->autoflush(1);
640 my $app = require $psgi;
641 test_psgi($app, sub {
643 my $req = GET('http://example.com/psgi-return-gzip');
644 my $res = $cb->($req);
645 my $buf = $res->content;
646 IO::Uncompress::Gunzip::gunzip(\$buf => \(my $out));
647 is($out, "hello world\n", 'got expected output');
649 $req = GET('http://example.com/psgi-return-enoent');
651 is($res->code, 500, 'got error on ENOENT');
652 seek($tmperr, 0, SEEK_SET) or die;
653 my $errbuf = do { local $/; <$tmperr> };
654 like($errbuf, qr/this-better-not-exist/,
655 'error logged about missing command');
657 open STDERR, '>&', $olderr or die "restore stderr: $!";
664 open my $fh, '+<', $f or die "failed to open $f: $!\n";
667 truncate($fh, 0) or die "truncate failed on $f: $!\n";