Skip to content

Commit

Permalink
test-tls-connect-given-socket: initial commit
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
Brandon Philips committed May 1, 2012
1 parent d3b3953 commit f949568
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/luvit/tls.lua
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions tests/test-tls-connect-given-socket.lua
@@ -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.