about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <BOFH@YHBT.net>2023-06-05 10:12:34 +0000
committerEric Wong <bofh@yhbt.net>2023-06-05 10:38:39 +0000
commit7c5fb3b9eccc6ee7698f6107f83edc83df3b0b63 (patch)
treea7c95eb9ab5d0e5e85dee8361c1226b01aaea1eb /t
parentfbdf627a138ffcaa589a7bb29559a3c6f9297a24 (diff)
downloadunicorn-7c5fb3b9eccc6ee7698f6107f83edc83df3b0b63.tar.gz
Another socat dependency down...
Diffstat (limited to 't')
-rw-r--r--t/integration.t33
-rw-r--r--t/lib.perl9
-rwxr-xr-xt/t0002-parser-error.sh94
3 files changed, 41 insertions, 95 deletions
diff --git a/t/integration.t b/t/integration.t
index ee22e7e..503b7eb 100644
--- a/t/integration.t
+++ b/t/integration.t
@@ -85,6 +85,39 @@ SKIP: {
         is($res->{content}, 'Goodbye', 'write-on-close body read');
 }
 
+if ('bad requests') {
+        $c = start_req($srv, 'GET /env_dump HTTP/1/1');
+        ($status, $hdr) = slurp_hdr($c);
+        like($status, qr!\AHTTP/1\.[01] 400 \b!, 'got 400 on bad request');
+
+        $c = tcp_connect($srv);
+        print $c 'GET /' or die $!;
+        my $buf = join('', (0..9), 'ab');
+        for (0..1023) { print $c $buf or die $! }
+        print $c " HTTP/1.0\r\n\r\n" or die $!;
+        ($status, $hdr) = slurp_hdr($c);
+        like($status, qr!\AHTTP/1\.[01] 414 \b!,
+                '414 on REQUEST_PATH > (12 * 1024)');
+
+        $c = tcp_connect($srv);
+        print $c 'GET /hello-world?a' or die $!;
+        $buf = join('', (0..9));
+        for (0..1023) { print $c $buf or die $! }
+        print $c " HTTP/1.0\r\n\r\n" or die $!;
+        ($status, $hdr) = slurp_hdr($c);
+        like($status, qr!\AHTTP/1\.[01] 414 \b!,
+                '414 on QUERY_STRING > (10 * 1024)');
+
+        $c = tcp_connect($srv);
+        print $c 'GET /hello-world#a' or die $!;
+        $buf = join('', (0..9), 'a'..'f');
+        for (0..63) { print $c $buf or die $! }
+        print $c " HTTP/1.0\r\n\r\n" or die $!;
+        ($status, $hdr) = slurp_hdr($c);
+        like($status, qr!\AHTTP/1\.[01] 414 \b!, '414 on FRAGMENT > (1024)');
+}
+
+
 # ... more stuff here
 undef $ar;
 my @log = slurp("$tmpdir/err.log");
diff --git a/t/lib.perl b/t/lib.perl
index 12deaf8..7d712b5 100644
--- a/t/lib.perl
+++ b/t/lib.perl
@@ -10,7 +10,7 @@ use POSIX qw(dup2 _exit setpgid :signal_h SEEK_SET F_SETFD);
 use File::Temp 0.19 (); # 0.19 for ->newdir
 our ($tmpdir, $errfh);
 our @EXPORT = qw(unicorn slurp tcp_server tcp_connect unicorn $tmpdir $errfh
-        SEEK_SET tcp_host_port);
+        SEEK_SET tcp_host_port start_req);
 
 my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
 $tmpdir = File::Temp->newdir("unicorn-$base-XXXX", TMPDIR => 1);
@@ -59,6 +59,13 @@ sub tcp_connect {
         $s;
 }
 
+sub start_req {
+        my ($srv, @req) = @_;
+        my $c = tcp_connect($srv);
+        print $c @req, "\r\n\r\n" or die "print: $!";
+        $c;
+}
+
 sub slurp {
         open my $fh, '<', $_[0] or die "open($_[0]): $!";
         local $/;
diff --git a/t/t0002-parser-error.sh b/t/t0002-parser-error.sh
deleted file mode 100755
index 9dc1cd2..0000000
--- a/t/t0002-parser-error.sh
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/bin/sh
-. ./test-lib.sh
-t_plan 11 "parser error test"
-
-t_begin "setup and startup" && {
-        unicorn_setup
-        unicorn -D env.ru -c $unicorn_config
-        unicorn_wait_start
-}
-
-t_begin "send a bad request" && {
-        (
-                printf 'GET / HTTP/1/1\r\nHost: example.com\r\n\r\n'
-                cat $fifo > $tmp &
-                wait
-                echo ok > $ok
-        ) | socat - TCP:$listen > $fifo
-        test xok = x$(cat $ok)
-}
-
-dbgcat tmp
-
-t_begin "response should be a 400" && {
-        grep -F 'HTTP/1.1 400 Bad Request' $tmp
-}
-
-t_begin "send a huge Request URI (REQUEST_PATH > (12 * 1024))" && {
-        rm -f $tmp
-        cat $fifo > $tmp &
-        (
-                set -e
-                trap 'echo ok > $ok' EXIT
-                printf 'GET /'
-                for i in $(awk </dev/null 'BEGIN{for(i=0;i<1024;i++) print i}')
-                do
-                        printf '0123456789ab'
-                done
-                printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
-        ) | socat - TCP:$listen > $fifo || :
-        test xok = x$(cat $ok)
-        wait
-}
-
-t_begin "response should be a 414 (REQUEST_PATH)" && {
-        grep -F 'HTTP/1.1 414 ' $tmp
-}
-
-t_begin "send a huge Request URI (QUERY_STRING > (10 * 1024))" && {
-        rm -f $tmp
-        cat $fifo > $tmp &
-        (
-                set -e
-                trap 'echo ok > $ok' EXIT
-                printf 'GET /hello-world?a'
-                for i in $(awk </dev/null 'BEGIN{for(i=0;i<1024;i++) print i}')
-                do
-                        printf '0123456789'
-                done
-                printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
-        ) | socat - TCP:$listen > $fifo || :
-        test xok = x$(cat $ok)
-        wait
-}
-
-t_begin "response should be a 414 (QUERY_STRING)" && {
-        grep -F 'HTTP/1.1 414 ' $tmp
-}
-
-t_begin "send a huge Request URI (FRAGMENT > 1024)" && {
-        rm -f $tmp
-        cat $fifo > $tmp &
-        (
-                set -e
-                trap 'echo ok > $ok' EXIT
-                printf 'GET /hello-world#a'
-                for i in $(awk </dev/null 'BEGIN{for(i=0;i<64;i++) print i}')
-                do
-                        printf '0123456789abcdef'
-                done
-                printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
-        ) | socat - TCP:$listen > $fifo || :
-        test xok = x$(cat $ok)
-        wait
-}
-
-t_begin "response should be a 414 (FRAGMENT)" && {
-        grep -F 'HTTP/1.1 414 ' $tmp
-}
-
-t_begin "server stderr should be clean" && check_stderr
-
-t_begin "term signal sent" && kill $unicorn_pid
-
-t_done