summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-alert-handling.js
diff options
context:
space:
mode:
authorShigeki Ohtsu <ohtsu@iij.ad.jp>2015-05-08 13:35:47 +0900
committerFedor Indutny <fedor@indutny.com>2015-05-16 12:34:01 +0200
commit7c52e1c1f47ac9d2f15048c2606331e3e09c5f6c (patch)
tree0285c87ac4de9feed3351bbbc8142ea914e762cd /test/parallel/test-tls-alert-handling.js
parente008e8faba34d6e5bd760e68cdff1f3fe0e04514 (diff)
downloadandroid-node-v8-7c52e1c1f47ac9d2f15048c2606331e3e09c5f6c.tar.gz
android-node-v8-7c52e1c1f47ac9d2f15048c2606331e3e09c5f6c.tar.bz2
android-node-v8-7c52e1c1f47ac9d2f15048c2606331e3e09c5f6c.zip
tls_wrap: fix error cb when fatal TLS Alert recvd
SSL_read() returns 0 when fatal TLS Alert is received. Fix to invoke ssl error callback in this case. PR-URL: https://github.com/nodejs/io.js/pull/1661 Reviewed-By: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'test/parallel/test-tls-alert-handling.js')
-rw-r--r--test/parallel/test-tls-alert-handling.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/parallel/test-tls-alert-handling.js b/test/parallel/test-tls-alert-handling.js
new file mode 100644
index 0000000000..045e69b949
--- /dev/null
+++ b/test/parallel/test-tls-alert-handling.js
@@ -0,0 +1,90 @@
+var common = require('../common');
+var assert = require('assert');
+
+if (!common.opensslCli) {
+ console.error('Skipping because node compiled without OpenSSL CLI.');
+ process.exit(0);
+}
+
+if (!common.hasCrypto) {
+ console.log('1..0 # Skipped: missing crypto');
+ process.exit();
+}
+
+var tls = require('tls');
+var net = require('net');
+var fs = require('fs');
+
+var success = false;
+
+function filenamePEM(n) {
+ return require('path').join(common.fixturesDir, 'keys', n + '.pem');
+}
+
+function loadPEM(n) {
+ return fs.readFileSync(filenamePEM(n));
+}
+
+var opts = {
+ key: loadPEM('agent2-key'),
+ cert: loadPEM('agent2-cert')
+};
+
+var max_iter = 20;
+var iter = 0;
+
+var server = tls.createServer(opts, function(s) {
+ s.pipe(s);
+ s.on('error', function(e) {
+ // ignore error
+ });
+});
+
+server.listen(common.PORT, function() {
+ sendClient();
+});
+
+
+function sendClient() {
+ var client = tls.connect(common.PORT, {
+ rejectUnauthorized: false
+ });
+ client.on('data', function(chunk) {
+ if (iter++ === 2) sendBADTLSRecord();
+ if (iter < max_iter) {
+ client.write('a');
+ return;
+ }
+ client.end();
+ server.close();
+ success = true;
+ });
+ client.write('a');
+ client.on('error', function(e) {
+ // ignore error
+ });
+ client.on('close', function() {
+ server.close();
+ });
+}
+
+
+function sendBADTLSRecord() {
+ var BAD_RECORD = new Buffer([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]);
+ var socket = net.connect(common.PORT);
+ var client = tls.connect({
+ socket: socket,
+ rejectUnauthorized: false
+ }, function() {
+ socket.write(BAD_RECORD);
+ socket.end();
+ });
+ client.on('error', function(e) {
+ // ignore error
+ });
+}
+
+process.on('exit', function() {
+ assert(iter === max_iter);
+ assert(success);
+});