2005-06-03 07:13:15 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2005-06-09 06:18:27 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))
|
2005-06-03 07:13:15 +00:00
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
require 'Rex/Socket/TcpServer'
|
|
|
|
|
|
|
|
class Rex::Socket::TcpServer::UnitTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_tcp_server
|
|
|
|
serv_port = 65433
|
|
|
|
serv = Rex::Socket.create_tcp_server(
|
|
|
|
'LocalPort' => serv_port)
|
|
|
|
ccli = nil
|
|
|
|
|
|
|
|
begin
|
|
|
|
assert_kind_of(Rex::Socket::TcpServer, serv, "valid TcpServer")
|
|
|
|
assert_kind_of(Rex::IO::StreamServer, serv, "valid StreamServer")
|
|
|
|
|
|
|
|
# Connect to the server
|
|
|
|
assert_nothing_raised {
|
|
|
|
ccli = Rex::Socket.create_tcp(
|
|
|
|
'PeerHost' => '127.0.0.1',
|
|
|
|
'PeerPort' => serv_port)
|
|
|
|
}
|
|
|
|
assert_kind_of(Rex::Socket::Tcp, ccli, "valid client client Tcp")
|
|
|
|
|
|
|
|
# Accept the client connection
|
|
|
|
scli = serv.accept
|
|
|
|
assert_kind_of(Rex::Socket::Tcp, scli, "valid server client Tcp")
|
|
|
|
|
|
|
|
assert_equal(true, scli.put("Yo"), "scli: put Yo")
|
|
|
|
assert_equal("Yo", ccli.get("Yo"), "ccli: get Yo")
|
|
|
|
ensure
|
|
|
|
ccli.close if (ccli)
|
|
|
|
serv.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|