Permalink
Browse files

test: set rejectUnauthorized in tls/https tests

Update the tls and https tests to explicitly set rejectUnauthorized instead of
relying on the NODE_TLS_REJECT_UNAUTHORIZED environment variable getting set.
  • Loading branch information...
1 parent 35607f3 commit 3806cf0d640da3024d50208452d2dd9e3cb015d2 @bnoordhuis committed Aug 30, 2012
Showing with 183 additions and 164 deletions.
  1. +2 −4 test/fixtures/GH-892-request.js
  2. +4 −4 test/pummel/test-https-large-response.js
  3. +4 −4 test/pummel/test-tls-throttle.js
  4. +55 −25 test/simple/test-http-host-headers.js
  5. +1 −3 test/simple/test-http-url.parse-https.request.js
  6. +5 −7 test/simple/test-https-agent.js
  7. +2 −4 test/simple/test-https-drain.js
  8. +4 −7 test/simple/test-https-eof-for-eom.js
  9. +5 −5 test/simple/test-https-localaddress.js
  10. +3 −5 test/simple/test-https-pfx.js
  11. +8 −8 test/simple/test-https-socket-options.js
  12. +2 −4 test/simple/test-https-timeout.js
  13. +2 −4 test/simple/test-regress-GH-1531.js
  14. +10 −5 test/simple/test-tls-client-resume.js
  15. +2 −4 test/simple/test-tls-client-verify.js
  16. +8 −5 test/simple/test-tls-connect-given-socket.js
  17. +2 −1 test/simple/test-tls-connect-pipe.js
  18. +8 −5 test/simple/test-tls-connect-simple.js
  19. +5 −4 test/simple/test-tls-getcipher.js
  20. +4 −4 test/simple/test-tls-honorcipherorder.js
  21. +6 −6 test/simple/test-tls-npn-server-client.js
  22. +2 −7 test/simple/test-tls-over-http-tunnel.js
  23. +4 −5 test/simple/test-tls-passphrase.js
  24. +4 −4 test/simple/test-tls-pause-close.js
  25. +4 −4 test/simple/test-tls-pause.js
  26. +4 −4 test/simple/test-tls-peer-certificate-multi-keys.js
  27. +4 −4 test/simple/test-tls-peer-certificate.js
  28. +5 −4 test/simple/test-tls-remote.js
  29. +4 −4 test/simple/test-tls-request-timeout.js
  30. +4 −4 test/simple/test-tls-set-encoding.js
  31. +6 −6 test/simple/test-tls-sni-server-client.js
@@ -21,9 +21,6 @@
// Called by test/pummel/test-regress-GH-892.js
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var https = require('https');
var fs = require('fs');
var assert = require('assert');
@@ -35,7 +32,8 @@ var gotResponse = false;
var options = {
method: 'POST',
- port: PORT
+ port: PORT,
+ rejectUnauthorized: false
};
var req = https.request(options, function(res) {
@@ -19,9 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var assert = require('assert');
@@ -53,7 +50,10 @@ var count = 0;
var gotResEnd = false;
server.listen(common.PORT, function() {
- https.get({ port: common.PORT }, function(res) {
+ https.get({
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, function(res) {
console.log('response!');
res.on('data', function(d) {
@@ -22,9 +22,6 @@
// Server sends a large string. Client counts bytes and pauses every few
// seconds. Makes sure that pause and resume work properly.
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var assert = require('assert');
var tls = require('tls');
@@ -56,7 +53,10 @@ var server = tls.Server(options, function(socket) {
var recvCount = 0;
server.listen(common.PORT, function() {
- var client = tls.connect(common.PORT);
+ var client = tls.connect({
+ port: common.PORT,
+ rejectUnauthorized: false
+ });
client.on('data', function(d) {
process.stdout.write('.');
@@ -19,9 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var http = require('http'),
https = require('https'),
fs = require('fs'),
@@ -74,35 +71,50 @@ function testHttp() {
if (er) throw er;
- http.get({ method: 'GET',
+ http.get({
+ method: 'GET',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower);
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower);
- http.request({ method: 'GET',
+ http.request({
+ method: 'GET',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
- http.request({ method: 'POST',
+ http.request({
+ method: 'POST',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
- http.request({ method: 'PUT',
+ http.request({
+ method: 'PUT',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
- http.request({ method: 'DELETE',
+ http.request({
+ method: 'DELETE',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
});
}
@@ -124,40 +136,58 @@ function testHttps() {
httpsServer.listen(common.PORT, function(er) {
if (er) throw er;
- https.get({ method: 'GET',
+ https.get({
+ method: 'GET',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower);
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower);
- https.request({ method: 'GET',
+ https.request({
+ method: 'GET',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
- https.request({ method: 'POST',
+ https.request({
+ method: 'POST',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
- https.request({ method: 'PUT',
+ https.request({
+ method: 'PUT',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
- https.request({ method: 'DELETE',
+ https.request({
+ method: 'DELETE',
path: '/' + (counter++),
host: 'localhost',
//agent: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
- https.get({ method: 'GET',
+ https.get({
+ method: 'GET',
path: '/setHostFalse' + (counter++),
host: 'localhost',
setHost: false,
- port: common.PORT }, cb).on('error', thrower).end();
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, cb).on('error', thrower).end();
});
}
@@ -19,9 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var assert = require('assert');
var https = require('https');
@@ -36,6 +33,7 @@ var httpsOptions = {
};
var testURL = url.parse('https://localhost:' + common.PORT);
+testURL.rejectUnauthorized = false;
function check(request) {
// assert that I'm https
@@ -19,17 +19,11 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-
-
if (!process.versions.openssl) {
console.error('Skipping because node compiled without OpenSSL.');
process.exit(0);
}
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var assert = require('assert');
var https = require('https');
@@ -55,7 +49,11 @@ server.listen(common.PORT, function() {
for (var i = 0; i < N; i++) {
setTimeout(function() {
for (var j = 0; j < M; j++) {
- https.get({ port: common.PORT, path: '/' }, function(res) {
+ https.get({
+ path: '/',
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, function(res) {
console.log(res.statusCode);
if (++responses == N * M) server.close();
}).on('error', function(e) {
@@ -24,9 +24,6 @@ if (!process.versions.openssl) {
process.exit(0);
}
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var assert = require('assert');
var https = require('https');
@@ -50,8 +47,9 @@ var server = https.createServer(options, function(req, res) {
server.listen(common.PORT, function() {
var resumed = false;
var req = https.request({
+ method: 'POST',
port: common.PORT,
- method: 'POST'
+ rejectUnauthorized: false
}, function(res) {
var timer;
res.pause();
@@ -19,9 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-
-
// I hate HTTP. One way of terminating an HTTP response is to not send
// a content-length header, not send a transfer-encoding: chunked header,
// and simply terminate the TCP connection. That is identity
@@ -34,9 +31,6 @@ if (!process.versions.openssl) {
process.exit(0);
}
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var assert = require('assert');
var tls = require('tls');
@@ -77,7 +71,10 @@ var bodyBuffer = '';
server.listen(common.PORT, function() {
console.log('1) Making Request');
- var req = https.get({ port: common.PORT }, function(res) {
+ var req = https.get({
+ port: common.PORT,
+ rejectUnauthorized: false
+ }, function(res) {
server.close();
console.log('3) Client got response headers.');
@@ -19,9 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var https = require('https'),
fs = require('fs'),
@@ -48,11 +45,14 @@ var server = https.createServer(options, function (req, res) {
});
server.listen(common.PORT, "127.0.0.1", function() {
- var options = { host: 'localhost',
+ var options = {
+ host: 'localhost',
port: common.PORT,
path: '/',
method: 'GET',
- localAddress: '127.0.0.2' };
+ localAddress: '127.0.0.2',
+ rejectUnauthorized: false
+ };
var req = https.request(options, function(res) {
res.on('end', function() {
@@ -19,9 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-// disable strict server certificate validation by the client
-process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
-
var common = require('../common');
var assert = require('assert');
var https = require('https');
@@ -35,12 +32,13 @@ var options = {
path: '/',
pfx: pfx,
passphrase: 'sample',
- requestCert: true
+ requestCert: true,
+ rejectUnauthorized: false
};
var server = https.createServer(options, function(req, res) {
assert.equal(req.socket.authorized, false); // not a client cert
- assert.equal(req.socket.authorizationError, 'UNABLE_TO_GET_ISSUER_CERT');
+ assert.equal(req.socket.authorizationError, 'DEPTH_ZERO_SELF_SIGNED_CERT');
res.writeHead(200);
res.end('OK');
});
Oops, something went wrong.

0 comments on commit 3806cf0

Please sign in to comment.