Permalink
Browse files

Added tests for tls.start

  • Loading branch information...
1 parent bb1d0ec commit afcf5086ea29535e76b8d5b23ef26dc4779efc9a @Rush committed Jul 6, 2012
Showing with 57 additions and 0 deletions.
  1. +46 −0 test/simple/test-tls-start-client-server.js
  2. +11 −0 test/simple/test-tls-start-client.js
@@ -0,0 +1,46 @@
+var assert = require('assert');
+var net = require('net');
+var common = require('../common');
+var fs = require('fs');
+var tls = require('tls');
+
+function filenamePEM(n) {
+ return require('path').join(common.fixturesDir, 'keys', n + '.pem');
+}
+
+function loadPEM(n) {
+ return fs.readFileSync(filenamePEM(n));
+}
+
+var serverOptions = {
+ key: loadPEM('agent2-key'),
+ cert: loadPEM('agent2-cert')
+};
+
+
+var serverSecurelyConnected = false;
+var clientSecurelyConnected = false;
+
+net.createServer(function(socket) {
+ var encryptedStream = tls.start(socket, serverOptions, true, function() {
+ serverSecurelyConnected = true;
+ });
+}).listen(9999);
+
+
+
+var client = net.connect(9999, function() {
+ var encryptedStream = tls.start(client, function() {
+ clientSecurelyConnected = true;
+ if(serverSecurelyConnected) {
+ process.exit(0);
+ }
+ assert.fail("Client connected securely to the server but server does "
+ + "not know this", "Both client and server should be "
+ + "connected", "tls.start failed");
+ });
+});
+
+setTimeout(function() {
+ assert.fail("tls.start failed, client has not been able to upgrade connection");
+}, 100);
@@ -0,0 +1,11 @@
+var assert = require('assert');
+var net = require('net');
+var tls = require('tls');
+
+var client = net.connect(443, 'google.com', function() {
+ var encryptedStream = tls.start(client, function() {
+ assert.ok(encryptedStream.authorized, "When connected, connection should yield authorized");
+ client.end();
+ });
+
+});

0 comments on commit afcf508

Please sign in to comment.