Permalink
Browse files

test-tls-connect-given-socket: initial commit

WIP
  • Loading branch information...
Brandon Philips
Brandon Philips committed May 1, 2012
1 parent d3b3953 commit f949568f568568d3a7eb8321b193e38c772e68d6
Showing with 53 additions and 2 deletions.
  1. +8 −2 lib/luvit/tls.lua
  2. +45 −0 tests/test-tls-connect-given-socket.lua
@@ -822,10 +822,16 @@ function connect(...)
callback = args[#args]
end

local socket = options.socket or Socket:new()
local socket
if options.socket then
socket = options.socket
else
socket = Socket:new()
socket:connect(options.port, options.host)
end

local sslcontext = createCredentials(options)

socket:connect(options.port, options.host)

local servername = options.servername or options.host
if not servername then
@@ -0,0 +1,45 @@
require('helper')
local fixture = require('./fixture-tls')
local net = require('net')
local tls = require('tls')

local options = {
cert = fixture.certPem,
key = fixture.certKey,
}

local server = tls.createServer(options, function(socket)
print('hi')
serverConnected = true
socket:write('Hello')
socket:destroy()
end)

server:listen(fixture.commonPort, function()
local socket
print('listening')
socket = net.createConnection(fixture.commonPort, '127.0.0.1', function(err)
if err then
assert(err)
end
print('connected')
local client
client = tls.connect({socket = socket, host = '127.0.0.1', port = fixture.commonPort}, function()
print('tls connected')
clientConnected = true
local data = ''
client:on('data', function(chunk)
data = data + chunk
end)
client:on('end', function()
assert.equal(data, 'Hello')
server:close()
end)
end)
end)
end)

process:on('exit', function()
assert(serverConnected)
assert(clientConnected)
end)

0 comments on commit f949568

Please sign in to comment.