about summary refs log tree commit homepage
path: root/test/test_proxy_pass.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-04-03 22:08:15 +0000
committerEric Wong <e@80x24.org>2015-04-03 22:08:15 +0000
commitb537f61726c89dd4d0020041f521c66f2046f000 (patch)
treebf2ea70d8f3edd9110b08e8c0bcb7281624a8991 /test/test_proxy_pass.rb
parentdb0f20a4c889a132786af69a6aaacfadf689379d (diff)
downloadyahns-b537f61726c89dd4d0020041f521c66f2046f000.tar.gz
Even if a response is screwed, we need to ensure breakage is
predictable.
Diffstat (limited to 'test/test_proxy_pass.rb')
-rw-r--r--test/test_proxy_pass.rb55
1 files changed, 55 insertions, 0 deletions
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