From f53316ab299574075bb5885631c7f6ce751c2656 Mon Sep 17 00:00:00 2001 From: Bryan Clement Date: Mon, 5 Mar 2018 11:39:56 -0800 Subject: [PATCH] fix proxy tests to respect ssl --- lib/collector/http-agents.js | 4 +- .../collector-remote-method.tap.js | 73 ++++++++++--------- test/integration/proxy-api-connection.tap.js | 52 ++----------- 3 files changed, 47 insertions(+), 82 deletions(-) diff --git a/lib/collector/http-agents.js b/lib/collector/http-agents.js index 82152096f3..22b0b8c7b1 100644 --- a/lib/collector/http-agents.js +++ b/lib/collector/http-agents.js @@ -35,7 +35,7 @@ function proxyOptions(config) { var parsed_url = parse(config.proxy) var proxy_url = { - protocol: parsed_url.protocol || 'http:', + protocol: parsed_url.protocol || 'https:', host: parsed_url.hostname, port: parsed_url.port || 80, auth: parsed_url.auth @@ -48,7 +48,7 @@ function proxyOptions(config) { // Unless a proxy config is provided, default to HTTP. proxy_url = { - protocol: 'http:', + protocol: 'https:', host: config.proxy_host || 'localhost', port: config.proxy_port || 80, auth: proxy_auth diff --git a/test/integration/collector-remote-method.tap.js b/test/integration/collector-remote-method.tap.js index 601dafefbf..635dfc01a5 100644 --- a/test/integration/collector-remote-method.tap.js +++ b/test/integration/collector-remote-method.tap.js @@ -6,50 +6,57 @@ var join = require('path').join var https = require('https') var url = require('url') var collector = require('../lib/fake-collector') +var semver = require('semver') var RemoteMethod = require('../../lib/collector/remote-method') -tap.test('DataSender (callback style) talking to fake collector', function(t) { - var config = { - host: 'ssl.lvh.me', - port: 8765, - run_id: 1337, - ssl: true, - license_key: 'whatever', - version: '0' - } - config.certificates = [ - read(join(__dirname, '../lib/ca-certificate.crt'), 'utf8') - ] - var method = new RemoteMethod('preconnect', config) - - collector({port: 8765}, function(error, server) { - if (error) { - t.fail(error) - return t.end() +// Specifying custom certs on 0.10 sends the process into a spin lock, +// so we skip it. +tap.test( + 'DataSender (callback style) talking to fake collector', + {skip: semver.satisfies(process.version, '0.10.x')}, + function(t) { + var config = { + host: 'ssl.lvh.me', + port: 8765, + run_id: 1337, + ssl: true, + license_key: 'whatever', + version: '0' } + config.certificates = [ + read(join(__dirname, '../lib/ca-certificate.crt'), 'utf8') + ] + var method = new RemoteMethod('preconnect', config) - t.tearDown(function() { - server.close() - }) - - method._post('[]', function(error, results, json) { + collector({port: 8765}, function(error, server) { if (error) { t.fail(error) return t.end() } - t.equal(results, 'collector-1.lvh.me:8089', 'parsed result should come through') - t.notOk(json.validations, 'fake collector should find no irregularities') - t.equal( - json.return_value, - 'collector-1.lvh.me:8089', - 'collector returns expected collector redirect' - ) + t.tearDown(function() { + server.close() + }) + + method._post('[]', function(error, results, json) { + if (error) { + t.fail(error) + return t.end() + } + + t.equal(results, 'collector-1.lvh.me:8089', 'parsed result should come through') + t.notOk(json.validations, 'fake collector should find no irregularities') + t.equal( + json.return_value, + 'collector-1.lvh.me:8089', + 'collector returns expected collector redirect' + ) - t.end() + t.end() + }) }) - }) -}) + } +) tap.test('remote method to get redirect host', function(t) { t.plan(2) diff --git a/test/integration/proxy-api-connection.tap.js b/test/integration/proxy-api-connection.tap.js index eadc497169..383aec74e2 100644 --- a/test/integration/proxy-api-connection.tap.js +++ b/test/integration/proxy-api-connection.tap.js @@ -32,6 +32,7 @@ tap.test('support ssl to the proxy', function(t) { utilization: { detect_aws: false, detect_pcf: false, + detect_azure: false, detect_gcp: false, detect_docker: false }, @@ -80,11 +81,13 @@ tap.test('setting proxy_port should use the proxy agent', function(t) { license_key: 'd67afc830dab717fd163bfcb0b8b88423e9a1a3b', host: 'staging-collector.newrelic.com', port: 443, + proxy_host: 'ssl.lvh.me', proxy_port: port, ssl: true, utilization: { detect_aws: false, detect_pcf: false, + detect_azure: false, detect_gcp: false, detect_docker: false }, @@ -117,53 +120,6 @@ tap.test('setting proxy_port should use the proxy agent', function(t) { }) }) -tap.test('proxy agent with SSL tunnel to collector', function(t) { - var server = proxySetup(https.createServer()) - var port = 0 - - server.listen(port, function() { - port = server.address().port - - var config = configurator.initialize({ - app_name: 'node.js Tests', - license_key: 'd67afc830dab717fd163bfcb0b8b88423e9a1a3b', - host: 'staging-collector.newrelic.com', - port: 443, - proxy: fmt('http://localhost:%d', port), - ssl: true, - utilization: { - detect_aws: false, - detect_pcf: false, - detect_gcp: false, - detect_docker: false - }, - logging: { - level: 'trace' - } - }) - var agent = new Agent(config) - var api = new CollectorAPI(agent) - - - api.connect(function(error, returned) { - t.notOk(error, 'connected without error') - t.ok(returned, 'got boot configuration') - t.ok(returned.agent_run_id, 'got run ID') - t.ok(agent.config.run_id, 'run ID set in configuration') - - api.shutdown(function(error, returned, json) { - t.notOk(error, 'should have shut down without issue') - t.equal(returned, null, 'collector explicitly returns null') - t.deepEqual(json, {return_value: null}, 'raw message looks right') - t.notOk(agent.config.run_id, 'run ID should have been cleared by shutdown') - - server.close() - t.end() - }) - }) - }) -}) - tap.test('proxy authentication should set headers', function(t) { t.plan(2) @@ -194,6 +150,7 @@ tap.test('proxy authentication should set headers', function(t) { utilization: { detect_aws: false, detect_pcf: false, + detect_azure: false, detect_gcp: false, detect_docker: false }, @@ -220,6 +177,7 @@ tap.test('no proxy set should not use proxy agent', function(t) { utilization: { detect_aws: false, detect_pcf: false, + detect_azure: false, detect_gcp: false, detect_docker: false },