Sha256: 117b9fd30cebf77300eb74605c8344fb7a4e55a6fa903f3d477e628dd12b1654

Contents?: true

Size: 1.87 KB

Versions: 40

Compression:

Stored size: 1.87 KB

Contents

#!/usr/bin/env ruby

$:.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
		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

	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

end

Version data entries

40 entries across 40 versions & 1 rubygems

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