New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tls: TLSSocket emits 'error' on handshake failure #9742
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) { | ||
common.skip('missing crypto'); | ||
return; | ||
} | ||
const tls = require('tls'); | ||
const net = require('net'); | ||
const assert = require('assert'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sort requires? |
||
|
||
const bonkers = Buffer.alloc(1024, 42); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a comment, "Construct a buffer that is not a valid TLS handshake.", or just change var name - |
||
|
||
let clientErrorEmited = false; | ||
|
||
const server = tls.createServer({}) | ||
.listen(0, function() { | ||
const c = net.connect({ port: this.address().port }, function() { | ||
c.write(bonkers); | ||
}); | ||
|
||
}).on('clientError', function(e) { | ||
clientErrorEmited = true; | ||
assert.ok(e instanceof Error, | ||
'Instance of Error should be passed to error handler'); | ||
assert.ok(e.message.match( | ||
/SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol/), | ||
'Expecting SSL unknown protocol'); | ||
}); | ||
|
||
setTimeout(function() { | ||
server.close(); | ||
|
||
assert.ok(clientErrorEmited, 'clientError should be emited'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "emitted" |
||
|
||
}, common.platformTimeout(200)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. description, etc. |
||
if (!common.hasCrypto) { | ||
common.skip('missing crypto'); | ||
return; | ||
} | ||
const tls = require('tls'); | ||
const net = require('net'); | ||
const assert = require('assert'); | ||
|
||
const bonkers = Buffer.alloc(1024, 42); | ||
|
||
const server = net.createServer(function(c) { | ||
setTimeout(function() { | ||
const s = new tls.TLSSocket(c, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this version of the test exists because the error handling code paths under test differ in behaviour depending on how the server is created, or just to be very thorough? |
||
isServer: true, | ||
server: server | ||
}); | ||
|
||
s.on('error', common.mustCall(function(e) { | ||
assert.ok(e instanceof Error, | ||
'Instance of Error should be passed to error handler'); | ||
assert.ok(e.message.match( | ||
/SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol/), | ||
'Expecting SSL unknown protocol'); | ||
})); | ||
|
||
s.on('close', function() { | ||
server.close(); | ||
s.destroy(); | ||
}); | ||
}, common.platformTimeout(200)); | ||
}).listen(0, function() { | ||
const c = net.connect({port: this.address().port}, function() { | ||
c.write(bonkers); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing test description: https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md#lines-4-5