Skip to content

Commit

Permalink
wip test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jjiang-stripe committed Apr 17, 2021
1 parent 69d6167 commit 3a9dba4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
37 changes: 32 additions & 5 deletions tests/proxy_tests.rb
Expand Up @@ -88,7 +88,7 @@ def env_proxy_tests(env)
connection = nil

tests('connection.data[:proxy][:host]').returns('mysecureproxy') do
connection = Excon.new('https://secret.com', :ssl_proxy_headers => {'x-proxy-id': 'abc123' })
connection = Excon.new('https://secret.com')
connection.data[:proxy][:host]
end

Expand All @@ -100,10 +100,6 @@ def env_proxy_tests(env)
connection.data[:proxy][:scheme]
end

tests('connection.data[:proxy][:headers]').returns({ 'x-proxy-id': 'abc123' }) do
connection.data[:proxy][:headers]
end

tests('with disable_proxy set') do
connection = nil

Expand Down Expand Up @@ -277,6 +273,37 @@ def env_proxy_tests(env)
end
end

tests('https proxying: https://foo.com:8080') do
response = nil

tests('response.status').returns(200) do
connection = Excon.new('https://foo.com:8080', :proxy => 'http://127.0.0.1:9292', :ssl_proxy_headers => {'X-Proxy-Id': 'abc123'})
response = connection.request(:method => :get, :path => '/bar', :query => {:alpha => 'kappa'})

response.status
end

# must be absolute form for proxy requests
tests('sent Request URI').returns('http://foo.com:8080/bar?alpha=kappa') do
response.headers['Sent-Request-Uri']
end

tests('sent Sent-Host header').returns('foo.com:8080') do
response.headers['Sent-Host']
end

tests('sent Proxy-Connection header').returns('Keep-Alive') do
response.headers['Sent-Proxy-Connection']
end

tests('response.body (proxied content)').returns('proxied content') do
response.body
end

tests('sent ssl proxy header').returns('abc123') do
response.headers['X-Proxy-Id']
end
end
end

with_unicorn('proxy.ru', 'unix:///tmp/myproxy.sock') do
Expand Down
22 changes: 22 additions & 0 deletions tests/rackups/proxy.ru
Expand Up @@ -5,6 +5,28 @@ class App < Sinatra::Base
set :environment, :production
enable :dump_errors

# a bit of a hack to handle the proxy CONNECT request since
# Sinatra doesn't support it by default
configure do
class << Sinatra::Base
def connect(path, opts={}, &block)
route 'CONNECT', path, opts, &block
end
end
Sinatra::Delegator.delegate :options
end

connect('*') do
headers(
"Sent-Request-Uri" => request.env['REQUEST_URI'].to_s,
"Sent-Host" => request.env['HTTP_HOST'].to_s,
"Sent-Proxy-Connection" => request.env['HTTP_PROXY_CONNECTION'].to_s,
"X-Proxy-Id" => request.env['X_PROXY_ID'].to_s
)

halt 200, 'proxy connect successful'
end

get('*') do
headers(
"Sent-Request-Uri" => request.env['REQUEST_URI'].to_s,
Expand Down

0 comments on commit 3a9dba4

Please sign in to comment.