filter exception messages with control characters
[unicorn.git] / test / unit / test_http_parser_xftrust.rb
blobdb8cfa9f565257d178129ca28c8bfb4dfb1a05f1
1 # -*- encoding: binary -*-
2 require 'test/test_helper'
4 include Unicorn
6 class HttpParserXFTrustTest < Test::Unit::TestCase
7   def setup
8     assert HttpParser.trust_x_forwarded?
9   end
11   def test_xf_trust_false_xfp
12     HttpParser.trust_x_forwarded = false
13     parser = HttpParser.new
14     parser.buf << "GET / HTTP/1.1\r\nHost: foo:\r\n" \
15                   "X-Forwarded-Proto: https\r\n\r\n"
16     env = parser.parse
17     assert_kind_of Hash, env
18     assert_equal 'foo', env['SERVER_NAME']
19     assert_equal '80', env['SERVER_PORT']
20     assert_equal 'http', env['rack.url_scheme']
21   end
23   def test_xf_trust_false_xfs
24     HttpParser.trust_x_forwarded = false
25     parser = HttpParser.new
26     parser.buf << "GET / HTTP/1.1\r\nHost: foo:\r\n" \
27                   "X-Forwarded-SSL: on\r\n\r\n"
28     env = parser.parse
29     assert_kind_of Hash, env
30     assert_equal 'foo', env['SERVER_NAME']
31     assert_equal '80', env['SERVER_PORT']
32     assert_equal 'http', env['rack.url_scheme']
33   end
35   def teardown
36     HttpParser.trust_x_forwarded = true
37   end
38 end