unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 8d0cc37d62bc2950933542b9d440d4ea823cbbc9 1043 bytes (raw)
$ git show 4.x-stable:test/unit/test_http_parser_xftrust.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
# -*- encoding: binary -*-
require './test/test_helper'

include Unicorn

class HttpParserXFTrustTest < Test::Unit::TestCase
  def setup
    assert HttpParser.trust_x_forwarded?
  end

  def test_xf_trust_false_xfp
    HttpParser.trust_x_forwarded = false
    parser = HttpParser.new
    parser.buf << "GET / HTTP/1.1\r\nHost: foo:\r\n" \
                  "X-Forwarded-Proto: https\r\n\r\n"
    env = parser.parse
    assert_kind_of Hash, env
    assert_equal 'foo', env['SERVER_NAME']
    assert_equal '80', env['SERVER_PORT']
    assert_equal 'http', env['rack.url_scheme']
  end

  def test_xf_trust_false_xfs
    HttpParser.trust_x_forwarded = false
    parser = HttpParser.new
    parser.buf << "GET / HTTP/1.1\r\nHost: foo:\r\n" \
                  "X-Forwarded-SSL: on\r\n\r\n"
    env = parser.parse
    assert_kind_of Hash, env
    assert_equal 'foo', env['SERVER_NAME']
    assert_equal '80', env['SERVER_PORT']
    assert_equal 'http', env['rack.url_scheme']
  end

  def teardown
    HttpParser.trust_x_forwarded = true
  end
end

git clone https://yhbt.net/unicorn.git