spec/network/tcp_spec.rb in ronin-support-0.4.0 vs spec/network/tcp_spec.rb in ronin-support-0.4.1
- old
+ new
@@ -28,14 +28,14 @@
socket.close
end
it "should bind to a local host and port" do
- socket = subject.tcp_connect(host,port,nil,local_port)
+ socket = subject.tcp_connect(host,port,nil,local_port)
+ bound_port = socket.addr[1]
- local_address = socket.local_address
- local_address.ip_port.should == local_port
+ bound_port.should == local_port
socket.close
end
it "should yield the new TCPSocket" do
@@ -63,14 +63,14 @@
socket.close
end
it "should bind to a local host and port" do
- socket = subject.tcp_connect_and_send(data,host,port,nil,local_port)
+ socket = subject.tcp_connect_and_send(data,host,port,nil,local_port)
+ bound_port = socket.addr[1]
- local_address = socket.local_address
- local_address.ip_port.should == local_port
+ bound_port.should == local_port
socket.close
end
it "should yield the TCPSocket" do
@@ -100,17 +100,17 @@
socket.should be_kind_of(TCPSocket)
socket.should be_closed
end
it "should bind to a local host and port" do
- local_address = nil
+ bound_port = nil
subject.tcp_session(host,port,nil,local_port) do |socket|
- local_address = socket.local_address
+ bound_port = socket.addr[1]
end
- local_address.ip_port.should == local_port
+ bound_port.should == local_port
end
end
describe "#tcp_banner" do
let(:host) { 'smtp.gmail.com' }
@@ -140,12 +140,12 @@
banner.start_with?('220').should be_true
end
end
describe "#tcp_send" do
- let(:server) { TCPServer.new(server_host,nil) }
- let(:server_port) { server.local_address.ip_port }
+ let(:server) { TCPServer.new(server_host,0) }
+ let(:server_port) { server.addr[1] }
let(:data) { "hello\n" }
let(:local_port) { 1024 + rand(65535 - 1024) }
after(:all) { server.close }
@@ -162,14 +162,14 @@
end
it "should bind to a local host and port" do
subject.tcp_send(data,server_host,server_port,nil,local_port)
- client = server.accept
+ client = server.accept
+ client_port = client.peeraddr[1]
- client_address = client.remote_address
- client_address.ip_port.should == local_port
+ client_port.should == local_port
client.close
end
end
@@ -184,15 +184,16 @@
server.close
end
it "should bind to a specific port and host" do
- server = subject.tcp_server(server_port,server_host)
+ server = subject.tcp_server(server_port,server_host)
+ bound_host = server.addr[3]
+ bound_port = server.addr[1]
- local_address = server.local_address
- local_address.ip_address.should == server_ip
- local_address.ip_port.should == server_port
+ bound_host.should == server_ip
+ bound_port.should == server_port
server.close
end
it "should yield the new TCPServer" do
@@ -222,17 +223,19 @@
server.should be_kind_of(TCPServer)
server.should be_closed
end
it "should bind to a specific port and host" do
- local_address = nil
+ bound_host = nil
+ bound_port = nil
subject.tcp_server_session(server_port,server_host) do |yielded_server|
- local_address = yielded_server.local_address
+ bound_host = yielded_server.addr[3]
+ bound_port = yielded_server.addr[1]
end
- local_address.ip_address.should == server_ip
- local_address.ip_port.should == server_port
+ bound_host.should == server_ip
+ bound_port.should == server_port
end
end
describe "#tcp_single_server" do
let(:server_port) { 1024 + rand(65535 - 1024) }