2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-07-24 20:53:54 +00:00
|
|
|
|
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
require 'rex/proto/http'
|
|
|
|
|
|
|
|
class Rex::Proto::Http::Client::UnitTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
Klass = Rex::Proto::Http::Client
|
|
|
|
|
|
|
|
def test_parse
|
2009-06-26 23:18:53 +00:00
|
|
|
c = Klass.new('www.metasploit.com')
|
2005-09-15 23:37:38 +00:00
|
|
|
|
|
|
|
# Set request factory parameters
|
2006-12-19 07:11:55 +00:00
|
|
|
c.set_config(
|
2009-06-26 23:18:53 +00:00
|
|
|
'vhost' => 'www.metasploit.com',
|
|
|
|
'agent' => 'Metasploit Framework/3.3',
|
2006-12-19 07:11:55 +00:00
|
|
|
'version' => '1.1',
|
2005-09-15 23:37:38 +00:00
|
|
|
'cookie' => 'NoCookie=NotACookie'
|
|
|
|
)
|
|
|
|
|
|
|
|
# Set client parameters
|
2006-12-19 07:11:55 +00:00
|
|
|
c.set_config(
|
|
|
|
'read_max_data' => 1024 * 1024
|
2005-09-15 23:37:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Request the main web pagfe
|
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
r = c.request_raw(
|
2005-09-15 23:37:38 +00:00
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => '/'
|
|
|
|
)
|
2005-07-24 20:53:54 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
resp = c.send_recv(r)
|
2005-07-24 20:53:54 +00:00
|
|
|
|
|
|
|
assert_equal(200, resp.code)
|
|
|
|
assert_equal('OK', resp.message)
|
2005-09-15 23:37:38 +00:00
|
|
|
assert_equal('1.1', resp.proto)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Request a file that does not exist
|
|
|
|
#
|
2006-12-19 07:11:55 +00:00
|
|
|
r = c.request_raw(
|
2005-09-15 23:37:38 +00:00
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => '/NoFileHere.404'
|
|
|
|
)
|
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
resp = c.send_recv(r)
|
2005-09-15 23:37:38 +00:00
|
|
|
|
|
|
|
assert_equal(404, resp.code)
|
|
|
|
assert_equal('Not Found', resp.message)
|
|
|
|
assert_equal('1.1', resp.proto)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Send a POST request that results in a 302
|
|
|
|
#
|
|
|
|
c = Klass.new('beta.microsoft.com')
|
2006-12-19 07:11:55 +00:00
|
|
|
c.set_config('vhost' => 'beta.microsoft.com')
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
r = c.request_cgi(
|
2005-09-15 23:37:38 +00:00
|
|
|
'method' => 'POST',
|
2006-12-28 23:42:54 +00:00
|
|
|
'uri' => '/',
|
2006-12-19 07:11:55 +00:00
|
|
|
'vars_post' => { 'var' => 'val' },
|
|
|
|
'ctype' => 'application/x-www-form-urlencoded'
|
2005-09-15 23:37:38 +00:00
|
|
|
)
|
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
resp = c.send_recv(r)
|
2005-09-15 23:37:38 +00:00
|
|
|
|
2006-12-19 07:11:55 +00:00
|
|
|
assert_equal(200, resp.code)
|
|
|
|
assert_equal('OK', resp.message)
|
2005-09-15 23:37:38 +00:00
|
|
|
assert_equal('1.1', resp.proto)
|
2005-07-24 20:53:54 +00:00
|
|
|
end
|
|
|
|
|
2006-01-20 18:59:24 +00:00
|
|
|
def test_ssl
|
2006-12-19 07:11:55 +00:00
|
|
|
c = Klass.new('www.geotrust.com', 443, {}, true)
|
|
|
|
c.set_config('vhost' => 'www.geotrust.com')
|
|
|
|
r = c.request_raw(
|
2006-01-20 18:59:24 +00:00
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => '/'
|
|
|
|
)
|
2006-12-19 07:11:55 +00:00
|
|
|
resp = c.send_recv(r)
|
2006-01-20 18:59:24 +00:00
|
|
|
assert_equal(200, resp.code)
|
|
|
|
assert_equal('OK', resp.message)
|
|
|
|
assert_equal('1.1', resp.proto)
|
|
|
|
c.close
|
2006-01-27 05:33:08 +00:00
|
|
|
end
|
2006-01-20 18:59:24 +00:00
|
|
|
|
2009-06-26 23:18:53 +00:00
|
|
|
end
|