Skip to content

Commit

Permalink
Add unit test for Net::HTTP::Proxy'ing through mouseHole
Browse files Browse the repository at this point in the history
  • Loading branch information
lwu committed Feb 5, 2007
1 parent 5c33a67 commit 2d08553
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions test/test_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@
options.logger.level = Logger::INFO
options.database ||= {:adapter => 'sqlite3', :database => 'mh_test.db'}

$address = ['127.0.0.1', 9998]
$server = Mongrel::HttpServer.new(*$address)
$proxy_address = ['127.0.0.1', 9998]
$server = Mongrel::HttpServer.new(*$proxy_address)
MouseHole::CENTRAL = MouseHole::Central.new($server, options)

class TestProxy < Test::Unit::TestCase
def setup
@client = Net::HTTP.new(*$address)
$server.run

doorway = Mongrel::Camping::CampingHandler.new(MouseHole)
$server.register("/doorway", doorway)
$server.register('http:', MouseHole::ProxyHandler.new(MouseHole::CENTRAL))
$server.register('/', Mongrel::Camping::CampingHandler.new(MouseHole))
sleep(1)

@client = Net::HTTP.new(*$proxy_address)
@proxy_class = Net::HTTP::Proxy(*$proxy_address)
end

def teardown
end

def test_doorway
doorway = Mongrel::Camping::CampingHandler.new(MouseHole)
$server.register("/doorway", doorway)
sleep(1)

res = @client.request_get('/doorway')
assert res != nil, "Didn't get a response"
assert res.body =~ /MouseHole/, "Couldn't find doorway"
end

def test_proxy
$server.register('http:', MouseHole::ProxyHandler.new(MouseHole::CENTRAL))
$server.register('/', Mongrel::Camping::CampingHandler.new(MouseHole))
sleep(1)

def lagado_test(klass)
res = klass.get_response(URI.parse('http://www.lagado.com/proxy-test'))
assert res != nil, "Didn't get a response"
Expand All @@ -53,7 +53,16 @@ def lagado_test(klass)
res = lagado_test(Net::HTTP)
assert res.body =~ /NOT to have come via a proxy/, "Non-proxy didn't work as expected"

res = lagado_test(Net::HTTP::Proxy(*$address))
res = lagado_test(Net::HTTP::Proxy(*$proxy_address))
assert res.body =~ /This request appears to have come via a proxy/, "Proxy didn't work"
end
end

def test_ssl
# mH https:proxying works with Camino/Firefox, but
# apparently not yet with Net::HTTP::Proxy

url = "https://javacc.dev.java.net/"
res = @proxy_class.get_response(URI.parse(url))
assert res != nil, "Didn't get a response"
end
end

0 comments on commit 2d08553

Please sign in to comment.