1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-05 14:57:30 +01:00
metasploit-framework/lib/rex/socket.rb.ut.rb
Matt Miller 44e809d111 udp
git-svn-id: file:///home/svn/incoming/trunk@2554 4d416f70-5f16-0410-b530-b9f4589650da
2005-06-04 06:19:42 +00:00

58 lines
1.6 KiB
Ruby

#!/usr/bin/ruby
$:.unshift(File.join('..', File.dirname(__FILE__)))
require 'test/unit'
require 'Rex/Socket'
require 'Rex/Socket/Tcp'
class Rex::Socket::UnitTest < Test::Unit::TestCase
def test_create
serv = TCPServer.new('127.0.0.1', 65432)
sock = nil
assert_nothing_raised {
sock = Rex::Socket.create(
'PeerHost' => '127.0.0.1',
'PeerPort' => 65432,
'Proto' => 'tcp')
}
assert_kind_of(Rex::Socket::Tcp, sock, "socket factory creation")
sock = nil
assert_nothing_raised {
sock = Rex::Socket.create_tcp(
'PeerHost' => '127.0.0.1',
'PeerPort' => 65432)
}
assert_kind_of(Rex::Socket::Tcp, sock, "tcp socket factory creation")
serv.close
end
def test_to_sockaddr
assert_equal("\x00" * 16, Rex::Socket.to_sockaddr(nil, 0, 0), "null sockaddr")
assert_equal("\x02\x00\x00\x16" + "\x00" * 12, Rex::Socket.to_sockaddr(nil, 22), "default addr, port 22 sockaddr")
assert_equal("\x02\x00\x00\x16\x01\x02\x03\x04" + "\x00" * 8, Rex::Socket.to_sockaddr("1.2.3.4", 22), "1.2.3.4 addr, port 22 sockaddr")
end
def test_from_sockaddr
af, host, port = Rex::Socket.from_sockaddr("\x00" * 16)
assert_equal(0, af, "zero af")
assert_equal('0.0.0.0', host, "zero host")
assert_equal(0, port, "zero port")
af, host, port = Rex::Socket.from_sockaddr("\x02\x00\x00\x16" + "\x00" * 12)
assert_equal(2, af, "af = 2")
assert_equal('0.0.0.0', host, "zero host")
assert_equal(22, port, "port = 22")
af, host, port = Rex::Socket.from_sockaddr("\x02\x00\x00\x16\x01\x02\x03\x04" + "\x00" * 8)
assert_equal(2, af, "af = 2")
assert_equal('1.2.3.4', host, "zero host")
assert_equal(22, port, "port = 22")
end
end