2005-06-03 04:51:51 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2005-06-09 06:18:27 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
|
2005-06-03 04:51:51 +00:00
|
|
|
|
|
|
|
require 'test/unit'
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/exceptions'
|
|
|
|
require 'rex/socket/parameters'
|
|
|
|
require 'rex/socket/comm/local'
|
2005-06-03 04:51:51 +00:00
|
|
|
|
|
|
|
class Rex::Socket::Comm::Local::UnitTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_create_tcp
|
|
|
|
test_port = 65432
|
|
|
|
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")
|
2005-06-03 07:13:15 +00:00
|
|
|
stream.close
|
2005-06-03 04:51:51 +00:00
|
|
|
|
|
|
|
# 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")
|
|
|
|
|
2005-06-04 20:38:49 +00:00
|
|
|
assert_raise(Rex::ConnectionRefused, "connection refused failed") {
|
|
|
|
Rex::Socket::Comm::Local.create(
|
|
|
|
Rex::Socket::Parameters.from_hash(
|
|
|
|
'PeerHost' => '127.0.0.1',
|
|
|
|
'PeerPort' => 0,
|
|
|
|
'Proto' => 'tcp',
|
|
|
|
'Bare' => true))
|
|
|
|
}
|
|
|
|
|
2005-06-03 07:13:15 +00:00
|
|
|
stream.close
|
|
|
|
|
2005-06-03 04:51:51 +00:00
|
|
|
test_server.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_tcp_server
|
|
|
|
# TODO
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_udp
|
|
|
|
# TODO
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_invalid
|
2005-06-04 20:38:49 +00:00
|
|
|
assert_raise(Rex::UnsupportedProtocol, "invalid protocol check failed") {
|
2005-06-03 04:51:51 +00:00
|
|
|
Rex::Socket::Comm::Local.create(
|
|
|
|
Rex::Socket::Parameters.from_hash(
|
|
|
|
'Proto' => 'invalid'))
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|