Sha256: ecfbb31468bbb12c7b85f34e6e6852982f9c07807805f23b9a51c549c81e81ef

Contents?: true

Size: 1.4 KB

Versions: 43

Compression:

Stored size: 1.4 KB

Contents

#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))

require 'test/unit'
require 'rex/proto/http'

class Rex::Proto::Http::Server::UnitTest < Test::Unit::TestCase

	ListenPort = 8090
	ListenHost = '127.0.0.1'

	SrvKlass = Rex::Proto::Http::Server
	CliKlass = Rex::Proto::Http::Client

	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

	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

protected

	def start_srv
		self.srv = SrvKlass.new(ListenPort, ListenHost)
		self.srv.start
		self.srv
	end

	def stop_srv
		self.srv.stop if (self.srv)
	end

attr_accessor :srv

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.63 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.54 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.53 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.52 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.51 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.50 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.49 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.48 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.47 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.46 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.44 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.43 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.42 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.41 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.40 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.39 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.38 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.37 lib/rex/proto/http/server.rb.ut.rb
librex-0.0.36 lib/rex/proto/http/server.rb.ut.rb