Skip to content

Commit

Permalink
test: set rejectUnauthorized in tls/https tests
Browse files Browse the repository at this point in the history
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
bnoordhuis committed Sep 14, 2012
1 parent 35607f3 commit 3806cf0
Show file tree
Hide file tree
Showing 31 changed files with 183 additions and 164 deletions.
6 changes: 2 additions & 4 deletions test/fixtures/GH-892-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -35,7 +32,8 @@ var gotResponse = false;

var options = {
method: 'POST',
port: PORT
port: PORT,
rejectUnauthorized: false
};

var req = https.request(options, function(res) {
Expand Down
8 changes: 4 additions & 4 deletions test/pummel/test-https-large-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions test/pummel/test-tls-throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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('.');
Expand Down
80 changes: 55 additions & 25 deletions test/simple/test-http-host-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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();
});
}

Expand All @@ -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();
});
}
4 changes: 1 addition & 3 deletions test/simple/test-http-url.parse-https.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand Down
12 changes: 5 additions & 7 deletions test/simple/test-https-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions test/simple/test-https-drain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
Expand Down
11 changes: 4 additions & 7 deletions test/simple/test-https-eof-for-eom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down Expand Up @@ -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.');

Expand Down
10 changes: 5 additions & 5 deletions test/simple/test-https-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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() {
Expand Down
8 changes: 3 additions & 5 deletions test/simple/test-https-pfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
});
Expand Down
Loading

0 comments on commit 3806cf0

Please sign in to comment.