From ac7503210f55272e0d841a754a991fa96d665a46 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 20 Feb 2016 21:36:48 +0000 Subject: test_ssl: check SERVER_PORT when parsed from Host: header We need to ensure SERVER_PORT is still parsed from the Host: header when it is given, there. --- test/test_ssl.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/test_ssl.rb b/test/test_ssl.rb index 5fc2b52..e89a89d 100644 --- a/test/test_ssl.rb +++ b/test/test_ssl.rb @@ -114,11 +114,25 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC assert_match %r{\AHTTP/1\.\d 200 OK\r\n}, head end + # use port in Host: header (implemented by unicorn_http parser) + exp = '666' + client.write("GET /SERVER_PORT HTTP/1.1\r\nHost: example.com:#{exp}\r\n\r\n") + re = /#{Regexp.escape(exp)}\z/ + buf.clear + Timeout.timeout(60) do + buf << client.readpartial(111) until buf =~ re + end + head, body = buf.split("\r\n\r\n", 2) + assert_equal exp, body + assert_match %r{\AHTTP/1\.\d 200 OK\r\n}, head + Net::HTTP.start(insecure.addr[3], insecure.addr[1]) do |h| res = h.get('/rack.url_scheme') assert_equal 'http', res.body res = h.get('/HTTPS') assert_equal 'nil', res.body + res = h.get('/SERVER_PORT') + assert_equal insecure.addr[1].to_s, res.body end # read static file -- cgit v1.2.3-24-ge0c7