Sha256: f98acd3b9111bc87b45124b4b86b4c706774ec7e4431fe8d6210f87f8bab5170

Contents?: true

Size: 1.69 KB

Versions: 38

Compression:

Stored size: 1.69 KB

Contents

#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))

require 'test/unit'
require 'rex/socket/ssl_tcp_server'
require 'rex/socket/ssl_tcp'
require 'rex/text'

class Rex::Socket::SslTcpServer::UnitTest < Test::Unit::TestCase

	# XXX.  The client data is sent & decrypted just fine.  The server data is not.  the client thread just spins.  BAH.
	#
	# As of 2011-03-04, works fine on 1.8.6-p399, 1.8.7-p330, 1.9.1-p378
	#
	def test_tcp_server
		#return;

		serv_port = 65433
		c = nil

		threads = []

		# Server thread
		threads << Thread.new() {
			serv = Rex::Socket.create_tcp_server('LocalPort' => serv_port, 'SSL' => true)
			assert_kind_of(Rex::Socket::SslTcpServer, serv, "type => ssl")
			assert_kind_of(Rex::Socket::TcpServer, serv, "type => tcp")
			assert_kind_of(Rex::IO::StreamServer, serv, "type => stream")
			s = serv.accept
			assert_equal("client_data\n", s.get_once(), "s: get_once")
			assert_equal(3, s.write("Yo\n"), "s: put Yo")
			# Make sure methods are Strings for 1.9 compat (which returns
			# symbols)
			meths = s.methods.map {|m| m.to_s}
			assert(meths.include?("<<"), "Has <<")
			assert(meths.include?(">>"), "Has >>")
			assert(meths.include?("has_read_data?"), "Has has_read_data?")
			serv.close
		}

		# Client thread
		threads << Thread.new() {
			sleep(2)
			assert_nothing_raised {
				c = Rex::Socket::SslTcp.create(
				'PeerHost' => '127.0.0.1',
				'PeerPort' => serv_port
				)
			}
			assert_kind_of(Rex::Socket::Tcp, c, "TCP")
			assert_kind_of(Rex::Socket::SslTcp, c, "SSL")
			assert_equal(12, c.write("client_data\n"), "c: write")
			assert_equal("Yo\n", c.get_once(), "c: get_once")
			c.close if (c)
		}

		threads.each { |aThread|  aThread.join }
	end

end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
librex-0.0.35 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.34 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.33 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.32 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.31 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.30 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.29 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.28 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.27 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.26 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.25 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.23 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.21 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.19 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.17 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.13 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.12 lib/rex/socket/ssl_tcp_server.rb.ut.rb
librex-0.0.7 lib/rex/socket/ssl_tcp_server.rb.ut.rb