yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 2/4] proxy_pass: test for truncated response behavior
  @ 2015-04-04  1:08  7% ` Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2015-04-04  1:08 UTC (permalink / raw)
  To: yahns-public

Even if a response is screwed, we need to ensure breakage is
predictable.
---
 test/test_proxy_pass.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

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 @@ def call(env)
             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 @@ def test_proxy_pass
         h10.close
       end
     end
+    check_truncated_upstream(host, port)
   ensure
     gplv3.close if gplv3
     quit_wait pid
@@ -298,4 +314,43 @@ def check_pipelining(host, port)
   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
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-04-04  1:08     [PATCH 0/4] proxy_pass updates Eric Wong
2015-04-04  1:08  7% ` [PATCH 2/4] proxy_pass: test for truncated response behavior Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).