Class: Rex::Socket::Comm::Local::UnitTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rex/socket/comm/local.rb.ut.rb

Instance Method Summary collapse

Instance Method Details

#test_create_invalidObject



68
69
70
71
72
73
74
# File 'lib/rex/socket/comm/local.rb.ut.rb', line 68

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

#test_create_tcpObject



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
# File 'lib/rex/socket/comm/local.rb.ut.rb', line 13

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

#test_create_tcp_serverObject



60
61
62
# File 'lib/rex/socket/comm/local.rb.ut.rb', line 60

def test_create_tcp_server
	# TODO
end

#test_create_udpObject



64
65
66
# File 'lib/rex/socket/comm/local.rb.ut.rb', line 64

def test_create_udp
	# TODO
end