Sha256: f6d774977d3315dfb3545c2b89de1a3ed9a2efbf24d8594e6a8c3bede059924f

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'test/unit'
require 'unicorn'
require 'unicorn/http11'
require 'unicorn/trailer_parser'

class TestTrailerParser < Test::Unit::TestCase

  def test_basic
    tp = Unicorn::TrailerParser.new('Content-MD5')
    env = {}
    assert ! tp.execute!(env, "Content-MD5: asdf")
    assert env.empty?
    assert tp.execute!(env, "Content-MD5: asdf\r\n")
    assert_equal 'asdf', env['HTTP_CONTENT_MD5']
    assert_equal 1, env.size
  end

  def test_invalid_trailer
    tp = Unicorn::TrailerParser.new('Content-MD5')
    env = {}
    assert_raises(Unicorn::HttpParserError) {
      tp.execute!(env, "Content-MD: asdf\r\n")
    }
    assert env.empty?
  end

  def test_multiple_trailer
    tp = Unicorn::TrailerParser.new('Foo,Bar')
    env = {}
    buf = "Bar: a\r\nFoo: b\r\n"
    assert tp.execute!(env, buf)
    assert_equal 'a', env['HTTP_BAR']
    assert_equal 'b', env['HTTP_FOO']
  end

  def test_too_big_key
    tp = Unicorn::TrailerParser.new('Foo,Bar')
    env = {}
    buf = "Bar#{'a' * 1024}: a\r\nFoo: b\r\n"
    assert_raises(Unicorn::HttpParserError) { tp.execute!(env, buf) }
    assert env.empty?
  end

  def test_too_big_value
    tp = Unicorn::TrailerParser.new('Foo,Bar')
    env = {}
    buf = "Bar: #{'a' * (1024 * 1024)}: a\r\nFoo: b\r\n"
    assert_raises(Unicorn::HttpParserError) { tp.execute!(env, buf) }
    assert env.empty?
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unicorn-0.9.0 test/unit/test_trailer_parser.rb
unicorn-0.9.1 test/unit/test_trailer_parser.rb