From b537f61726c89dd4d0020041f521c66f2046f000 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 3 Apr 2015 22:08:15 +0000 Subject: proxy_pass: test for truncated response behavior Even if a response is screwed, we need to ensure breakage is predictable. --- test/test_proxy_pass.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'test/test_proxy_pass.rb') diff --git a/test/test_proxy_pass.rb b/test/test_proxy_pass.rb index 53542ac..cebd004 100644 --- a/test/test_proxy_pass.rb +++ b/test/test_proxy_pass.rb @@ -7,6 +7,11 @@ class TestProxyPass < Testcase ENV["N"].to_i > 1 and parallelize_me! include ServerHelper OMFG = 'a' * (1024 * 1024 * 32) + TRUNCATE_BODY = "HTTP/1.1 200 OK\r\n" \ + "Content-Length: 7\r\n" \ + "Content-Type: text/PAIN\r\n\r\nshort".freeze + TRUNCATE_HEAD = "HTTP/1.1 200 OK\r\n" \ + "Content-Length: 666\r\n".freeze class ProxiedApp def call(env) @@ -30,6 +35,16 @@ class TestProxyPass < Testcase sleep delay end io.close + when '/truncate-body' + io = env['rack.hijack'].call + io.write(TRUNCATE_BODY) + io.close + when '/truncate-head' + io = env['rack.hijack'].call + io.write(TRUNCATE_HEAD) + io.close + when '/immediate-EOF' + env['rack.hijack'].call.close when %r{\A/chunky-slow-(\d+(?:\.\d+)?)\z} delay = $1.to_f chunky = Object.new @@ -248,6 +263,7 @@ class TestProxyPass < Testcase h10.close end end + check_truncated_upstream(host, port) ensure gplv3.close if gplv3 quit_wait pid @@ -298,4 +314,43 @@ class TestProxyPass < Testcase ensure pl.close end + + def check_truncated_upstream(host, port) + # we want to make sure we show the truncated response without extra headers + s = TCPSocket.new(host, port) + check_err + res = Timeout.timeout(60) do + s.write "GET /truncate-body HTTP/1.1\r\nHost: example.com\r\n\r\n" + s.read + end + s.close + + exp = "HTTP/1.1 200 OK\r\n" \ + "Content-Length: 7\r\n" \ + "Content-Type: text/PAIN\r\n" \ + "Connection: keep-alive\r\n" \ + "\r\nshort" + assert_equal exp, res + errs = File.readlines(@err.path).grep(/\bERROR\b/) + assert_equal 1, errs.size + assert_match(/premature upstream EOF/, errs[0]) + @err.truncate(0) + + # truncated headers or no response at all... + # Send a 502 error + %w(immediate-EOF truncate-head).each do |path| + s = TCPSocket.new(host, port) + check_err + res = Timeout.timeout(60) do + s.write "GET /#{path} HTTP/1.1\r\nHost: example.com\r\n\r\n" + s.read(1024) + end + assert_match %r{\AHTTP/1.1 502\s+}, res + s.close + errs = File.readlines(@err.path).grep(/\bERROR\b/) + assert_equal 1, errs.size + assert_match(/premature upstream EOF/, errs[0]) + @err.truncate(0) + end + end end -- cgit v1.2.3-24-ge0c7