]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/httpd-corner.t
t/httpd-corner: ensure chunk payload read doesn't overreach
[public-inbox.git] / t / httpd-corner.t
index aa0698d3cd2b830f0bfc73ec350f74fffc721ca8..c1dc77dba9a3a5b89fa8420e9c66af962fa19e82 100644 (file)
@@ -1,13 +1,13 @@
-# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # note: our HTTP server should be standalone and capable of running
-# generic Rack apps.
+# generic PSGI/Plack apps.
 use strict;
 use warnings;
 use Test::More;
 use Time::HiRes qw(gettimeofday tv_interval);
 
-foreach my $mod (qw(Plack::Util Plack::Builder Danga::Socket
+foreach my $mod (qw(Plack::Util Plack::Builder
                        HTTP::Date HTTP::Status IPC::Run)) {
        eval "require $mod";
        plan skip_all => "$mod missing for httpd-corner.t" if $@;
@@ -15,12 +15,11 @@ foreach my $mod (qw(Plack::Util Plack::Builder Danga::Socket
 
 use Digest::SHA qw(sha1_hex);
 use File::Temp qw/tempdir/;
-use Cwd qw/getcwd/;
 use IO::Socket;
 use IO::Socket::UNIX;
 use Fcntl qw(:seek);
-use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
-use POSIX qw(mkfifo :sys_wait_h);
+use Socket qw(IPPROTO_TCP TCP_NODELAY);
+use POSIX qw(mkfifo);
 require './t/common.perl';
 my $tmpdir = tempdir('httpd-corner-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $fifo = "$tmpdir/fifo";
@@ -28,7 +27,7 @@ ok(defined mkfifo($fifo, 0777), 'created FIFO');
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
 my $httpd = 'blib/script/public-inbox-httpd';
-my $psgi = getcwd()."/t/httpd-corner.psgi";
+my $psgi = "./t/httpd-corner.psgi";
 my %opts = (
        LocalAddr => '127.0.0.1',
        ReuseAddr => 1,
@@ -124,6 +123,21 @@ my $spawn_httpd = sub {
        like($head, qr/\b413\b/, 'got 413 response');
 }
 
+{
+       my $conn = conn_for($sock, 'chunk with pipeline');
+       my $n = 10;
+       my $payload = 'b'x$n;
+       $conn->write("PUT /sha1 HTTP/1.1\r\nTransfer-Encoding: chunked\r\n");
+       $conn->write("\r\n".sprintf("%x\r\n", $n));
+       $conn->write($payload . "\r\n0\r\n\r\nGET /empty HTTP/1.0\r\n\r\n");
+       $conn->read(my $buf, 4096);
+       my $lim = 0;
+       $lim++ while ($conn->read($buf, 4096, bytes::length($buf)) && $lim < 9);
+       my $exp = sha1_hex($payload);
+       like($buf, qr!\r\n\r\n${exp}HTTP/1\.0 200 OK\r\n!s,
+               'chunk parser can handled pipelined requests');
+}
+
 # Unix domain sockets
 {
        my $u = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => $upath);