Skip to content

Commit

Permalink
fix proxy tests to respect ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Clement authored and NatalieWolfe committed Mar 6, 2018
1 parent 46e68a0 commit f53316a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 82 deletions.
4 changes: 2 additions & 2 deletions lib/collector/http-agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
73 changes: 40 additions & 33 deletions test/integration/collector-remote-method.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 5 additions & 47 deletions test/integration/proxy-api-connection.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
},
Expand All @@ -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
},
Expand Down

0 comments on commit f53316a

Please sign in to comment.