Sha256: 68416c038fecb3eaf50a4fb24ce869e6df7a15e6b981145c325ea307fff37571

Contents?: true

Size: 1.69 KB

Versions: 43

Compression:

Stored size: 1.69 KB

Contents

#!/usr/bin/env ruby

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

require 'test/unit'
require 'rex/exceptions'
require 'rex/socket/parameters'
require 'rex/socket/comm/local'

class Rex::Socket::Comm::Local::UnitTest < Test::Unit::TestCase

	def test_create_tcp
		test_port   = 64432
		test_server = TCPServer.new('127.0.0.1', test_port)

		# Create a stream connection to the stub listener
		stream = nil

		assert_nothing_raised {
			stream = Rex::Socket::Comm::Local.create(
				Rex::Socket::Parameters.from_hash(
					'PeerHost' => '127.0.0.1',
					'PeerPort' => test_port,
					'Proto'    => 'tcp'))
		}

		assert_kind_of(Rex::IO::Stream, stream, "valid Stream instance")
		assert_kind_of(Rex::Socket::Tcp, stream, "valid Tcp instance")
		stream.close

		# Now create a bare connection to the listener
		stream = nil

		assert_nothing_raised {
			stream = Rex::Socket::Comm::Local.create(
				Rex::Socket::Parameters.from_hash(
					'PeerHost' => '127.0.0.1',
					'PeerPort' => test_port,
					'Proto'    => 'tcp',
					'Bare'     => true))
		}

		assert_kind_of(Socket, stream, "valid Socket instance")

		assert_raise(Rex::ConnectionRefused, "connection refused failed") {
			Rex::Socket::Comm::Local.create(
				Rex::Socket::Parameters.from_hash(
					'PeerHost' => '127.0.0.1',
					'PeerPort' => 1,
					'Proto'    => 'tcp',
					'Bare'     => true))
		}

		stream.close

		test_server.close
	end

	def test_create_tcp_server
		# TODO
	end

	def test_create_udp
		# TODO
	end

	def test_create_invalid
		assert_raise(Rex::UnsupportedProtocol, "invalid protocol check failed") {
			Rex::Socket::Comm::Local.create(
				Rex::Socket::Parameters.from_hash(
					'Proto' => 'invalid'))
		}
	end

end

Version data entries

43 entries across 43 versions & 1 rubygems

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