From 8cd6f4d94503a568501b6e24bb785a8e002720c9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 8 Nov 2009 01:57:14 -0800 Subject: rev_thread_spawn/revactor: fix TeeInput for short reads Explicitly requested short reads may cause too much data to be returned, which would be bad and potentially break the application. We need to ensure proper IO#readpartial-like semantics in both of these models. --- t/sha1-random-size.ru | 19 +++++++++++++++++++ t/t0102-rack-input-short.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 t/sha1-random-size.ru create mode 100644 t/t0102-rack-input-short.sh (limited to 't') diff --git a/t/sha1-random-size.ru b/t/sha1-random-size.ru new file mode 100644 index 0000000..f86d017 --- /dev/null +++ b/t/sha1-random-size.ru @@ -0,0 +1,19 @@ +# SHA1 checksum generator +require 'digest/sha1' +use Rack::ContentLength +cap = 16384 +app = lambda do |env| + /\A100-continue\z/i =~ env['HTTP_EXPECT'] and + return [ 100, {}, [] ] + digest = Digest::SHA1.new + input = env['rack.input'] + if buf = input.read(rand(cap)) + begin + raise "#{buf.size} > #{cap}" if buf.size > cap + digest.update(buf) + end while input.read(rand(cap), buf) + end + + [ 200, {'Content-Type' => 'text/plain'}, [ digest.hexdigest << "\n" ] ] +end +run app diff --git a/t/t0102-rack-input-short.sh b/t/t0102-rack-input-short.sh new file mode 100644 index 0000000..97c079d --- /dev/null +++ b/t/t0102-rack-input-short.sh @@ -0,0 +1,32 @@ +#!/bin/sh +. ./test-lib.sh +test -r random_blob || die "random_blob required, run with 'make $0'" + +t_plan 4 "rack.input short read tests" + +t_begin "setup and startup" && { + rtmpfiles curl_out curl_err + rainbows_setup $model + rainbows -D sha1-random-size.ru -c $unicorn_config + blob_sha1=$(rsha1 random_blob) + t_info "blob_sha1=$blob_sha1" + rainbows_wait_start +} + +t_begin "regular request" && { + curl -sSf -T random_blob http://$listen/ > $curl_out 2> $curl_err + test x$blob_sha1 = x$(cat $curl_out) + test ! -s $curl_err +} + +t_begin "chunked request" && { + curl -sSf -T- < random_blob http://$listen/ > $curl_out 2> $curl_err + test x$blob_sha1 = x$(cat $curl_out) + test ! -s $curl_err +} + +t_begin "shutdown" && { + kill $rainbows_pid +} + +t_done -- cgit v1.2.3-24-ge0c7