Class: Rex::Proto::Http::Client::UnitTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rex/proto/http/client.rb.ut.rb

Constant Summary collapse

Klass =
Rex::Proto::Http::Client

Instance Method Summary collapse

Instance Method Details

#test_parseObject



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
70
71
72
73
74
75
76
77
# File 'lib/rex/proto/http/client.rb.ut.rb', line 12

def test_parse
	c = Klass.new('www.metasploit.com')

	# Set request factory parameters
	c.set_config(
		'vhost'      => 'www.metasploit.com',
		'agent'      => 'Metasploit Framework/3.3',
		'version'    => '1.1',
		'cookie'     => 'NoCookie=NotACookie'
	)

	# Set client parameters
	c.set_config(
		'read_max_data' => 1024 * 1024
	)

	#
	# Request the main web page
	#
	r = c.request_raw(
		'method' => 'GET',
		'uri'    => '/'
	)

	resp = c.send_recv(r)

	assert_equal(200, resp.code)
	assert_equal('OK', resp.message)
	assert_equal('1.1', resp.proto)

	#
	# Request a file that does not exist
	#
	r = c.request_raw(
		'method' => 'GET',
		'uri'    => '/NoFileHere.404'
	)

	resp = c.send_recv(r)

	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')
	c.set_config('vhost' => 'beta.microsoft.com')

	r = c.request_cgi(
		'method' => 'POST',
		'uri'    => '/',
		'vars_post'  => { 'var' => 'val' },
		'ctype' => 'application/x-www-form-urlencoded'
	)

	resp = c.send_recv(r)

	#assert_equal(200, resp.code)
	#assert_equal('OK', resp.message)
	assert_equal(301, resp.code)
	assert_equal('Moved Permanently', resp.message)
	assert_equal('1.1', resp.proto)
end

#test_sslObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rex/proto/http/client.rb.ut.rb', line 79

def test_ssl
	c = Klass.new('www.metasploit.com', 443, {}, true)
	c.set_config('vhost' => 'www.metasploit.com')
	r = c.request_raw(
		'method' => 'GET',
		'uri'    => '/'
	)
	resp = c.send_recv(r)

	assert_equal(200, resp.code)
	assert_equal('OK', resp.message)
	assert_equal('1.0', resp.proto)
	c.close
end