Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-tls-connect-given-socket: initial commit
WIP
- Loading branch information
Brandon Philips
committed
May 1, 2012
1 parent
d3b3953
commit f949568
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |