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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
Shindo.tests('Excon bad server interaction') do
with_server('bad') do
tests('header splitting') do
tests('prevents key splitting').raises(Excon::Errors::InvalidHeaderKey) do
connection = Excon.new('http://127.0.0.1:9292')
connection.request(
headers: { "Foo\r\nBar" => "baz" },
method: :get,
path: '/echo'
)
end
tests('prevents value splitting').raises(Excon::Errors::InvalidHeaderValue) do
connection = Excon.new('http://127.0.0.1:9292')
connection.request(
headers: { Foo: "bar\r\nBaz: qux" },
method: :get,
path: '/echo'
)
end
end
tests('bad server: causes EOFError') do
tests('with no content length and no chunking') do
tests('without a block') do
tests('response.body').returns('hello') do
connection = Excon.new('http://127.0.0.1:9292')
connection.request(:method => :get, :path => '/eof/no_content_length_and_no_chunking').body
end
end
tests('with a block') do
tests('body from chunks').returns('hello') do
connection = Excon.new('http://127.0.0.1:9292')
body = ""
response_block = lambda {|chunk, remaining, total| body << chunk }
connection.request(:method => :get, :path => '/eof/no_content_length_and_no_chunking', :response_block => response_block)
body
end
end
end
end
end
with_server('eof') do
tests('eof server: causes EOFError') do
tests('request').raises(Excon::Errors::SocketError) do
Excon.get('http://127.0.0.1:9292/eof')
end
end
end
end
|