Browse Source

Fix http and net tests failing due to race condition

Plus some minor cosmetic corrections
v0.7.4-release
Bert Belder 15 years ago
committed by Ryan Dahl
parent
commit
7059be19ec
  1. 28
      test/simple/test-http-1.0.js
  2. 18
      test/simple/test-http-chunked.js
  3. 94
      test/simple/test-http-client-race-2.js
  4. 34
      test/simple/test-http-client-race.js
  5. 38
      test/simple/test-http-client-upload.js
  6. 22
      test/simple/test-http-head-response-has-no-body.js
  7. 20
      test/simple/test-http-malformed-request.js
  8. 2
      test/simple/test-http-proxy.js
  9. 57
      test/simple/test-http-server.js
  10. 92
      test/simple/test-http-tls.js
  11. 42
      test/simple/test-http-wget.js
  12. 41
      test/simple/test-http.js
  13. 40
      test/simple/test-net-binary.js
  14. 23
      test/simple/test-net-keepalive.js
  15. 64
      test/simple/test-net-tls.js

28
test/simple/test-http-1.0.js

@ -16,23 +16,25 @@ var server = http.createServer(function (req, res) {
}) })
server.listen(common.PORT); server.listen(common.PORT);
var c = net.createConnection(common.PORT); server.addListener("listening", function() {
var c = net.createConnection(common.PORT);
c.setEncoding("utf8"); c.setEncoding("utf8");
c.addListener("connect", function () { c.addListener("connect", function () {
c.write( "GET / HTTP/1.0\r\n\r\n" ); c.write( "GET / HTTP/1.0\r\n\r\n" );
}); });
c.addListener("data", function (chunk) { c.addListener("data", function (chunk) {
console.log(chunk); console.log(chunk);
server_response += chunk; server_response += chunk;
}); });
c.addListener("end", function () { c.addListener("end", function () {
client_got_eof = true; client_got_eof = true;
c.end(); c.end();
server.close(); server.close();
});
}); });
process.addListener("exit", function () { process.addListener("exit", function () {

18
test/simple/test-http-chunked.js

@ -10,11 +10,13 @@ var server = http.createServer(function(req, res) {
}); });
server.listen(common.PORT); server.listen(common.PORT);
http.cat("http://127.0.0.1:"+common.PORT+"/", "utf8", function (err, data) { server.addListener("listening", function() {
if (err) throw err; http.cat("http://127.0.0.1:"+common.PORT+"/", "utf8", function (err, data) {
assert.equal('string', typeof data); if (err) throw err;
console.log('here is the response:'); assert.equal('string', typeof data);
assert.equal(UTF8_STRING, data); console.log('here is the response:');
console.log(data); assert.equal(UTF8_STRING, data);
server.close(); console.log(data);
}) server.close();
});
});

94
test/simple/test-http-client-race-2.js

@ -23,68 +23,70 @@ var server = http.createServer(function (req, res) {
}; };
res.writeHead(200, { "Content-Type": "text/plain" res.writeHead(200, { "Content-Type": "text/plain"
, "Content-Length": body.length , "Content-Length": body.length
}); });
res.end(body); res.end(body);
}); });
server.listen(common.PORT); server.listen(common.PORT);
var client = http.createClient(common.PORT);
var body1 = ""; var body1 = "";
var body2 = ""; var body2 = "";
var body3 = ""; var body3 = "";
// server.addListener("listening", function() {
// Client #1 is assigned Parser #1 var client = http.createClient(common.PORT);
//
var req1 = client.request("/1")
req1.end();
req1.addListener('response', function (res1) {
res1.setBodyEncoding("utf8");
res1.addListener('data', function (chunk) { //
body1 += chunk; // Client #1 is assigned Parser #1
}); //
var req1 = client.request("/1")
req1.end();
req1.addListener('response', function (res1) {
res1.setEncoding("utf8");
res1.addListener('end', function () { res1.addListener('data', function (chunk) {
// body1 += chunk;
// Delay execution a little to allow the "close" event to be processed });
// (required to trigger this bug!)
//
setTimeout(function () {
//
// The bug would introduce itself here: Client #2 would be allocated the
// parser that previously belonged to Client #1. But we're not finished
// with Client #1 yet!
//
var client2 = http.createClient(common.PORT);
res1.addListener('end', function () {
// //
// At this point, the bug would manifest itself and crash because the // Delay execution a little to allow the "close" event to be processed
// internal state of the parser was no longer valid for use by Client #1. // (required to trigger this bug!)
// //
var req2 = client.request("/2"); setTimeout(function () {
req2.end(); //
req2.addListener('response', function (res2) { // The bug would introduce itself here: Client #2 would be allocated the
res2.setBodyEncoding("utf8"); // parser that previously belonged to Client #1. But we're not finished
res2.addListener('data', function (chunk) { body2 += chunk; }); // with Client #1 yet!
res2.addListener('end', function () { //
var client2 = http.createClient(common.PORT);
//
// At this point, the bug would manifest itself and crash because the
// internal state of the parser was no longer valid for use by Client #1.
//
var req2 = client.request("/2");
req2.end();
req2.addListener('response', function (res2) {
res2.setEncoding("utf8");
res2.addListener('data', function (chunk) { body2 += chunk; });
res2.addListener('end', function () {
// //
// Just to be really sure we've covered all our bases, execute a // Just to be really sure we've covered all our bases, execute a
// request using client2. // request using client2.
// //
var req3 = client2.request("/3"); var req3 = client2.request("/3");
req3.end(); req3.end();
req3.addListener('response', function (res3) { req3.addListener('response', function (res3) {
res3.setBodyEncoding("utf8"); res3.setEncoding("utf8");
res3.addListener('data', function (chunk) { body3 += chunk }); res3.addListener('data', function (chunk) { body3 += chunk });
res3.addListener('end', function() { server.close(); }); res3.addListener('end', function() { server.close(); });
});
}); });
}); });
}); }, 500);
}, 500); });
}); });
}); });

34
test/simple/test-http-client-race.js

@ -15,27 +15,29 @@ var server = http.createServer(function (req, res) {
}); });
server.listen(common.PORT); server.listen(common.PORT);
var client = http.createClient(common.PORT);
var body1 = ""; var body1 = "";
var body2 = ""; var body2 = "";
var req1 = client.request("/1") server.addListener("listening", function() {
req1.end(); var client = http.createClient(common.PORT);
req1.addListener('response', function (res1) {
res1.setBodyEncoding("utf8");
res1.addListener('data', function (chunk) { var req1 = client.request("/1")
body1 += chunk; req1.end();
}); req1.addListener('response', function (res1) {
res1.setEncoding("utf8");
res1.addListener('data', function (chunk) {
body1 += chunk;
});
res1.addListener('end', function () { res1.addListener('end', function () {
var req2 = client.request("/2"); var req2 = client.request("/2");
req2.end(); req2.end();
req2.addListener('response', function (res2) { req2.addListener('response', function (res2) {
res2.setBodyEncoding("utf8"); res2.setEncoding("utf8");
res2.addListener('data', function (chunk) { body2 += chunk; }); res2.addListener('data', function (chunk) { body2 += chunk; });
res2.addListener('end', function () { server.close(); }); res2.addListener('end', function () { server.close(); });
});
}); });
}); });
}); });

38
test/simple/test-http-client-upload.js

@ -8,7 +8,7 @@ var client_res_complete = false;
var server = http.createServer(function(req, res) { var server = http.createServer(function(req, res) {
assert.equal("POST", req.method); assert.equal("POST", req.method);
req.setBodyEncoding("utf8"); req.setEncoding("utf8");
req.addListener('data', function (chunk) { req.addListener('data', function (chunk) {
console.log("server got: " + JSON.stringify(chunk)); console.log("server got: " + JSON.stringify(chunk));
@ -25,23 +25,25 @@ var server = http.createServer(function(req, res) {
}); });
server.listen(common.PORT); server.listen(common.PORT);
var client = http.createClient(common.PORT); server.addListener("listening", function() {
var req = client.request('POST', '/'); var client = http.createClient(common.PORT);
req.write('1\n'); var req = client.request('POST', '/');
req.write('2\n'); req.write('1\n');
req.write('3\n'); req.write('2\n');
req.end(); req.write('3\n');
req.end();
common.error("client finished sending request");
common.error("client finished sending request");
req.addListener('response', function(res) {
res.setEncoding("utf8"); req.addListener('response', function(res) {
res.addListener('data', function(chunk) { res.setEncoding("utf8");
console.log(chunk); res.addListener('data', function(chunk) {
}); console.log(chunk);
res.addListener('end', function() { });
client_res_complete = true; res.addListener('end', function() {
server.close(); client_res_complete = true;
server.close();
});
}); });
}); });

22
test/simple/test-http-head-response-has-no-body.js

@ -13,17 +13,19 @@ var server = http.createServer(function(req, res) {
}); });
server.listen(common.PORT); server.listen(common.PORT);
responseComplete = false; var responseComplete = false;
var req = http.createClient(common.PORT).request('HEAD', '/') server.addListener("listening", function() {
common.error('req'); var req = http.createClient(common.PORT).request('HEAD', '/')
req.end(); common.error('req');
req.addListener('response', function (res) { req.end();
common.error('response'); req.addListener('response', function (res) {
res.addListener('end', function() { common.error('response');
common.error('response end'); res.addListener('end', function() {
server.close(); common.error('response end');
responseComplete = true; server.close();
responseComplete = true;
});
}); });
}); });

20
test/simple/test-http-malformed-request.js

@ -10,24 +10,26 @@ url = require("url");
nrequests_completed = 0; nrequests_completed = 0;
nrequests_expected = 1; nrequests_expected = 1;
var s = http.createServer(function (req, res) { var server = http.createServer(function (req, res) {
console.log("req: " + JSON.stringify(url.parse(req.url))); console.log("req: " + JSON.stringify(url.parse(req.url)));
res.writeHead(200, {"Content-Type": "text/plain"}); res.writeHead(200, {"Content-Type": "text/plain"});
res.write("Hello World"); res.write("Hello World");
res.end(); res.end();
if (++nrequests_completed == nrequests_expected) s.close(); if (++nrequests_completed == nrequests_expected) server.close();
}); });
s.listen(common.PORT); server.listen(common.PORT);
var c = net.createConnection(common.PORT); server.addListener("listening", function() {
c.addListener("connect", function () { var c = net.createConnection(common.PORT);
c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n"); c.addListener("connect", function () {
c.end(); c.write("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
}); c.end();
});
// TODO add more! // TODO add more!
});
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(nrequests_expected, nrequests_completed); assert.equal(nrequests_expected, nrequests_completed);

2
test/simple/test-http-proxy.js

@ -43,7 +43,7 @@ function startReq () {
req.addListener('response', function (res) { req.addListener('response', function (res) {
common.debug("got res"); common.debug("got res");
assert.equal(200, res.statusCode); assert.equal(200, res.statusCode);
res.setBodyEncoding("utf8"); res.setEncoding("utf8");
res.addListener('data', function (chunk) { body += chunk; }); res.addListener('data', function (chunk) { body += chunk; });
res.addListener('end', function () { res.addListener('end', function () {
proxy.close(); proxy.close();

57
test/simple/test-http-server.js

@ -10,7 +10,7 @@ var requests_sent = 0;
var server_response = ""; var server_response = "";
var client_got_eof = false; var client_got_eof = false;
http.createServer(function (req, res) { var server = http.createServer(function (req, res) {
res.id = request_number; res.id = request_number;
req.id = request_number++; req.id = request_number++;
@ -45,41 +45,44 @@ http.createServer(function (req, res) {
res.end(); res.end();
}, 1); }, 1);
}).listen(common.PORT); });
server.listen(common.PORT);
var c = net.createConnection(common.PORT); server.addListener("listening", function() {
var c = net.createConnection(common.PORT);
c.setEncoding("utf8"); c.setEncoding("utf8");
c.addListener("connect", function () { c.addListener("connect", function () {
c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" ); c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" );
requests_sent += 1; requests_sent += 1;
}); });
c.addListener("data", function (chunk) { c.addListener("data", function (chunk) {
server_response += chunk; server_response += chunk;
if (requests_sent == 1) { if (requests_sent == 1) {
c.write("POST /quit HTTP/1.1\r\n\r\n"); c.write("POST /quit HTTP/1.1\r\n\r\n");
requests_sent += 1; requests_sent += 1;
} }
if (requests_sent == 2) { if (requests_sent == 2) {
c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n" c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n"
+"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n"); +"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
c.end(); c.end();
assert.equal(c.readyState, "readOnly"); assert.equal(c.readyState, "readOnly");
requests_sent += 2; requests_sent += 2;
} }
}); });
c.addListener("end", function () { c.addListener("end", function () {
client_got_eof = true; client_got_eof = true;
}); });
c.addListener("close", function () { c.addListener("close", function () {
assert.equal(c.readyState, "closed"); assert.equal(c.readyState, "closed");
});
}); });
process.addListener("exit", function () { process.addListener("exit", function () {

92
test/simple/test-http-tls.js

@ -37,11 +37,11 @@ var https_server = http.createServer(function (req, res) {
var peerDN = JSON.stringify(req.connection.getPeerCertificate()); var peerDN = JSON.stringify(req.connection.getPeerCertificate());
assert.equal(verified, true); assert.equal(verified, true);
assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones'
+ '/O=node.js/OU=Test TLS Certificate/CN=localhost",' + '/O=node.js/OU=Test TLS Certificate/CN=localhost",'
+ '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js'
+ '/OU=Test TLS Certificate/CN=localhost","valid_from":' + '/OU=Test TLS Certificate/CN=localhost","valid_from":'
+ '"Nov 11 09:52:22 2009 GMT","valid_to":' + '"Nov 11 09:52:22 2009 GMT","valid_to":'
+ '"Nov 6 09:52:22 2029 GMT"}'); + '"Nov 6 09:52:22 2029 GMT"}');
if (req.id == 0) { if (req.id == 0) {
assert.equal("GET", req.method); assert.equal("GET", req.method);
@ -74,52 +74,54 @@ var https_server = http.createServer(function (req, res) {
https_server.setSecure(credentials); https_server.setSecure(credentials);
https_server.listen(common.PORT); https_server.listen(common.PORT);
var c = net.createConnection(common.PORT); https_server.addListener("listening", function() {
var c = net.createConnection(common.PORT);
c.setEncoding("utf8");
c.setEncoding("utf8");
c.addListener("connect", function () {
c.setSecure(credentials);
});
c.addListener("secure", function () {
var verified = c.verifyPeer();
var peerDN = JSON.stringify(c.getPeerCertificate());
assert.equal(verified, true);
assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones'
+ '/O=node.js/OU=Test TLS Certificate/CN=localhost",'
+ '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js'
+ '/OU=Test TLS Certificate/CN=localhost","valid_from":'
+ '"Nov 11 09:52:22 2009 GMT","valid_to":'
+ '"Nov 6 09:52:22 2029 GMT"}');
c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" );
requests_sent += 1;
});
c.addListener("connect", function () { c.addListener("data", function (chunk) {
c.setSecure(credentials); server_response += chunk;
});
c.addListener("secure", function () { if (requests_sent == 1) {
var verified = c.verifyPeer(); c.write("POST /quit HTTP/1.1\r\n\r\n");
var peerDN = JSON.stringify(c.getPeerCertificate()); requests_sent += 1;
assert.equal(verified, true); }
assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones'
+ '/O=node.js/OU=Test TLS Certificate/CN=localhost",'
+ '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js'
+ '/OU=Test TLS Certificate/CN=localhost","valid_from":'
+ '"Nov 11 09:52:22 2009 GMT","valid_to":'
+ '"Nov 6 09:52:22 2029 GMT"}');
c.write( "GET /hello?hello=world&foo=b==ar HTTP/1.1\r\n\r\n" );
requests_sent += 1;
});
c.addListener("data", function (chunk) { if (requests_sent == 2) {
server_response += chunk; c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n"
+"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n");
c.end();
assert.equal(c.readyState, "readOnly");
requests_sent += 2;
}
if (requests_sent == 1) { });
c.write("POST /quit HTTP/1.1\r\n\r\n");
requests_sent += 1;
}
if (requests_sent == 2) { c.addListener("end", function () {
c.write("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n" client_got_eof = true;
+"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n"); });
c.end();
assert.equal(c.readyState, "readOnly");
requests_sent += 2;
}
});
c.addListener("end", function () {
client_got_eof = true;
});
c.addListener("close", function () { c.addListener("close", function () {
assert.equal(c.readyState, "closed"); assert.equal(c.readyState, "closed");
});
}); });
process.addListener("exit", function () { process.addListener("exit", function () {

42
test/simple/test-http-wget.js

@ -27,33 +27,35 @@ var server = http.createServer(function (req, res) {
res.write("hello "); res.write("hello ");
res.write("world\n"); res.write("world\n");
res.end(); res.end();
}) });
server.listen(common.PORT); server.listen(common.PORT);
var c = net.createConnection(common.PORT); server.addListener("listening", function() {
var c = net.createConnection(common.PORT);
c.setEncoding("utf8"); c.setEncoding("utf8");
c.addListener("connect", function () { c.addListener("connect", function () {
c.write("GET / HTTP/1.0\r\n" + c.write("GET / HTTP/1.0\r\n" +
"Connection: Keep-Alive\r\n\r\n"); "Connection: Keep-Alive\r\n\r\n");
}); });
c.addListener("data", function (chunk) { c.addListener("data", function (chunk) {
console.log(chunk); console.log(chunk);
server_response += chunk; server_response += chunk;
}); });
c.addListener("end", function () { c.addListener("end", function () {
client_got_eof = true; client_got_eof = true;
console.log('got end'); console.log('got end');
c.end(); c.end();
}); });
c.addListener("close", function () { c.addListener("close", function () {
connection_was_closed = true; connection_was_closed = true;
console.log('got close'); console.log('got close');
server.close(); server.close();
});
}); });
process.addListener("exit", function () { process.addListener("exit", function () {

41
test/simple/test-http.js

@ -12,7 +12,7 @@ var responses_recvd = 0;
var body0 = ""; var body0 = "";
var body1 = ""; var body1 = "";
http.createServer(function (req, res) { var server = http.createServer(function (req, res) {
if (responses_sent == 0) { if (responses_sent == 0) {
assert.equal("GET", req.method); assert.equal("GET", req.method);
assert.equal("/hello", url.parse(req.url).pathname); assert.equal("/hello", url.parse(req.url).pathname);
@ -39,30 +39,33 @@ http.createServer(function (req, res) {
}); });
//assert.equal("127.0.0.1", res.connection.remoteAddress); //assert.equal("127.0.0.1", res.connection.remoteAddress);
}).listen(common.PORT);
var client = http.createClient(common.PORT);
var req = client.request("/hello", {"Accept": "*/*", "Foo": "bar"});
req.end();
req.addListener('response', function (res) {
assert.equal(200, res.statusCode);
responses_recvd += 1;
res.setEncoding("utf8");
res.addListener('data', function (chunk) { body0 += chunk; });
common.debug("Got /hello response");
}); });
server.listen(common.PORT);
setTimeout(function () { server.addListener("listening", function() {
req = client.request("POST", "/world"); var client = http.createClient(common.PORT);
var req = client.request("/hello", {"Accept": "*/*", "Foo": "bar"});
req.end(); req.end();
req.addListener('response',function (res) { req.addListener('response', function (res) {
assert.equal(200, res.statusCode); assert.equal(200, res.statusCode);
responses_recvd += 1; responses_recvd += 1;
res.setBodyEncoding("utf8"); res.setEncoding("utf8");
res.addListener('data', function (chunk) { body1 += chunk; }); res.addListener('data', function (chunk) { body0 += chunk; });
common.debug("Got /world response"); common.debug("Got /hello response");
}); });
}, 1);
setTimeout(function () {
req = client.request("POST", "/world");
req.end();
req.addListener('response',function (res) {
assert.equal(200, res.statusCode);
responses_recvd += 1;
res.setEncoding("utf8");
res.addListener('data', function (chunk) { body1 += chunk; });
common.debug("Got /world response");
});
}, 1);
});
process.addListener("exit", function () { process.addListener("exit", function () {
common.debug("responses_recvd: " + responses_recvd); common.debug("responses_recvd: " + responses_recvd);

40
test/simple/test-net-binary.js

@ -32,29 +32,31 @@ var echoServer = tcp.createServer(function (connection) {
echoServer.listen(common.PORT); echoServer.listen(common.PORT);
var recv = ""; var recv = "";
var j = 0;
var c = tcp.createConnection(common.PORT); echoServer.addListener("listening", function() {
var j = 0;
var c = tcp.createConnection(common.PORT);
c.setEncoding("binary"); c.setEncoding("binary");
c.addListener("data", function (chunk) { c.addListener("data", function (chunk) {
if (j < 256) { if (j < 256) {
common.error("write " + j); common.error("write " + j);
c.write(String.fromCharCode(j), "binary"); c.write(String.fromCharCode(j), "binary");
j++; j++;
} else { } else {
c.end(); c.end();
} }
recv += chunk; recv += chunk;
}); });
c.addListener("connect", function () { c.addListener("connect", function () {
c.write(binaryString, "binary"); c.write(binaryString, "binary");
}); });
c.addListener("close", function () { c.addListener("close", function () {
p(recv); p(recv);
echoServer.close(); echoServer.close();
});
}); });
process.addListener("exit", function () { process.addListener("exit", function () {

23
test/simple/test-net-keepalive.js

@ -15,15 +15,16 @@ var echoServer = net.createServer(function (connection) {
}); });
echoServer.listen(common.PORT); echoServer.listen(common.PORT);
var clientConnection = net.createConnection(common.PORT); echoServer.addListener("listening", function() {
clientConnection.setTimeout(0); var clientConnection = net.createConnection(common.PORT);
clientConnection.setTimeout(0);
setTimeout( function() {
// make sure both connections are still open
assert.equal(serverConnection.readyState,"open");
assert.equal(clientConnection.readyState,"open");
serverConnection.end();
clientConnection.end();
echoServer.close();
}, 1200);
setTimeout( function() {
// make sure both connections are still open
assert.equal(serverConnection.readyState,"open");
assert.equal(clientConnection.readyState,"open");
serverConnection.end();
clientConnection.end();
echoServer.close();
}, 1200);
});

64
test/simple/test-net-tls.js

@ -37,11 +37,11 @@ var secureServer = net.createServer(function (connection) {
var peerDN = JSON.stringify(connection.getPeerCertificate()); var peerDN = JSON.stringify(connection.getPeerCertificate());
assert.equal(verified, true); assert.equal(verified, true);
assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones'
+ '/O=node.js/OU=Test TLS Certificate/CN=localhost",' + '/O=node.js/OU=Test TLS Certificate/CN=localhost",'
+ '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js'
+ '/OU=Test TLS Certificate/CN=localhost","valid_from":' + '/OU=Test TLS Certificate/CN=localhost","valid_from":'
+ '"Nov 11 09:52:22 2009 GMT","valid_to":' + '"Nov 11 09:52:22 2009 GMT","valid_to":'
+ '"Nov 6 09:52:22 2029 GMT"}'); + '"Nov 6 09:52:22 2029 GMT"}');
}); });
@ -58,40 +58,40 @@ var secureServer = net.createServer(function (connection) {
}); });
secureServer.listen(common.PORT); secureServer.listen(common.PORT);
var secureClient = net.createConnection(common.PORT); secureServer.addListener("listening", function() {
var secureClient = net.createConnection(common.PORT);
secureClient.setEncoding("UTF8"); secureClient.setEncoding("UTF8");
secureClient.addListener("connect", function () { secureClient.addListener("connect", function () {
secureClient.setSecure(credentials); secureClient.setSecure(credentials);
}); });
secureClient.addListener("secure", function () { secureClient.addListener("secure", function () {
gotSecureClient = true; gotSecureClient = true;
var verified = secureClient.verifyPeer(); var verified = secureClient.verifyPeer();
var peerDN = JSON.stringify(secureClient.getPeerCertificate()); var peerDN = JSON.stringify(secureClient.getPeerCertificate());
assert.equal(verified, true); assert.equal(verified, true);
assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones' assert.equal(peerDN, '{"subject":"/C=UK/ST=Acknack Ltd/L=Rhys Jones'
+ '/O=node.js/OU=Test TLS Certificate/CN=localhost",' + '/O=node.js/OU=Test TLS Certificate/CN=localhost",'
+ '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js' + '"issuer":"/C=UK/ST=Acknack Ltd/L=Rhys Jones/O=node.js'
+ '/OU=Test TLS Certificate/CN=localhost","valid_from":' + '/OU=Test TLS Certificate/CN=localhost","valid_from":'
+ '"Nov 11 09:52:22 2009 GMT","valid_to":' + '"Nov 11 09:52:22 2009 GMT","valid_to":'
+ '"Nov 6 09:52:22 2029 GMT"}'); + '"Nov 6 09:52:22 2029 GMT"}');
secureClient.write(testData); secureClient.write(testData);
secureClient.end(); secureClient.end();
}); });
secureClient.addListener("data", function (chunk) { secureClient.addListener("data", function (chunk) {
clientData += chunk; clientData += chunk;
}); });
secureClient.addListener("end", function () { secureClient.addListener("end", function () {
assert.equal(clientData, testData); assert.equal(clientData, testData);
});
}); });
process.addListener("exit", function () { process.addListener("exit", function () {
assert.ok(gotSecureServer, "Did not get secure event for server"); assert.ok(gotSecureServer, "Did not get secure event for server");
assert.ok(gotSecureClient, "Did not get secure event for clientr"); assert.ok(gotSecureClient, "Did not get secure event for clientr");
}); });

Loading…
Cancel
Save