Class: Rex::Proto::Http::Server::UnitTest

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

Constant Summary collapse

ListenPort =
8090
ListenHost =
'127.0.0.1'
SrvKlass =
Rex::Proto::Http::Server
CliKlass =
Rex::Proto::Http::Client

Instance Method Summary collapse

Instance Method Details

#test_resourceObject



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
# File 'lib/rex/proto/http/server.rb.ut.rb', line 33

def test_resource
	begin
		s   = start_srv
		c   = CliKlass.new(ListenHost, ListenPort)

		s.add_resource('/foo',
			'Proc' => Proc.new { |cli, req|
				resp = Rex::Proto::Http::Response::OK.new

				resp.body = "Chickens everywhere"

				cli.send_response(resp)
			})

		1.upto(10) {
			req = c.request_raw('uri' => '/foo')
			res = c.send_recv(req)
			assert_not_nil(res)
			assert_equal(200, res.code)
			assert_equal("Chickens everywhere", res.body)
		}

		s.remove_resource('/foo')

		req = c.request_raw('uri' => '/foo')
		res = c.send_recv(req)
		assert_not_nil(res)
		assert_equal(404, res.code)
	ensure
		stop_srv
	end
end

#test_serverObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rex/proto/http/server.rb.ut.rb', line 17

def test_server
	begin
		s   = start_srv
		c   = CliKlass.new(ListenHost, ListenPort)

		1.upto(10) {
			req = c.request_raw('uri' => '/')
			res = c.send_recv(req)
			assert_not_nil(res)
			assert_equal(404, res.code)
		}
	ensure
		stop_srv
	end
end