Skip to content

Commit

Permalink
feat: add tests for SNI
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoseph Maguire committed Feb 21, 2020
1 parent b77241c commit defa756
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions test/secure_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,34 @@ describe('MqttSecureClient', function () {
done()
})
})

it.only('should support SNI on the TLS connection', function (done) {
var hostname, client
server.removeAllListeners('secureConnection') // clear eventHandler
server.once('secureConnection', function (tlsSocket) { // one time eventHandler
assert(tlsSocket.servername) // validate SNI set
server.on('secureConnection', Server.setupConnection) // reset eventHandler

var that = this
var connection = new Connection(tlsSocket, function () {
that.emit('client', connection)
})
})

client = mqtt.connect({
protocol: 'mqtts',
port: port,
ca: [fs.readFileSync(CERT)],
rejectUnauthorized: true,
})

client.on('error', function (err) {
done(err)
})

server.once('connect', function () {
done()
})
})
})
})
2 changes: 1 addition & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var MqttServer
var FastMqttServer
var MqttSecureServer

function setupConnection (duplex) {
var setupConnection = module.exports.setupConnection = function setupConnection (duplex) {
var that = this
var connection = new Connection(duplex, function () {
that.emit('client', connection)
Expand Down

0 comments on commit defa756

Please sign in to comment.