Skip to content

Commit

Permalink
test(ssl): address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Svetlichny authored and NatalieWolfe committed Mar 6, 2018
1 parent 01174dd commit 2c8bd99
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 32 deletions.
24 changes: 21 additions & 3 deletions test/integration/collector-remote-method.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ tap.test('DataSender (callback style) talking to fake collector', function(t) {
tap.test('remote method to get redirect host', function(t) {
t.test('https with custom certificate', function(t) {
t.plan(3)
var method = createRemoteMethod()
var method = createRemoteMethod(true)

// create mock collector
startMockCollector(t, function() {
method.invoke([], function(error, returnValue) {
validateResponse(t, error, returnValue)
t.end()
})
})
})

t.test('https without custom certificate', function(t) {
t.plan(3)
var method = createRemoteMethod(false)

// create mock collector
startMockCollector(t, function() {
Expand All @@ -66,12 +79,17 @@ tap.test('remote method to get redirect host', function(t) {
t.equal(returnValue, 'some-collector-url', 'should get expected response')
}

function createRemoteMethod() {
function createRemoteMethod(useCertificate) {
var config = {
host: 'ssl.lvh.me',
port: 8765,
ssl: true,
certificates: read(join(__dirname, '../lib/ca-certificate.crt'), 'utf8')
}

if (useCertificate) {
config.certificates = [
read(join(__dirname, '../lib/ca-certificate.crt'), 'utf8')
]
}

var method = new RemoteMethod('preconnect', config)
Expand Down
111 changes: 82 additions & 29 deletions test/integration/proxy-api-connection.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,60 @@ var configurator = require('../../lib/config')
var Agent = require('../../lib/agent')
var CollectorAPI = require('../../lib/collector/api')

tap.test("setting proxy_port should use the proxy agent", function(t) {
tap.test('support ssl to the proxy', function(t) {
var port = 0
var opts = {
key: read(join(__dirname, '../lib/test-key.key')),
cert: read(join(__dirname, '../lib/self-signed-test-certificate.crt')),
}
var server = proxySetup(https.createServer(opts))

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: 'https://ssl.lvh.me:' + port,
ssl: true,
utilization: {
detect_aws: false,
detect_pcf: false,
detect_gcp: false,
detect_docker: false
},
logging: {
level: 'trace'
},
certificates: [
read(join(__dirname, '..', 'lib', 'ca-certificate.crt'), 'utf8')
]
})
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('setting proxy_port should use the proxy agent', function(t) {
var opts = {
key: read(join(__dirname, '../lib/test-key.key')),
cert: read(join(__dirname, '../lib/self-signed-test-certificate.crt')),
Expand Down Expand Up @@ -46,16 +99,16 @@ tap.test("setting proxy_port should use the proxy agent", function(t) {
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")
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")
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()
Expand All @@ -64,7 +117,7 @@ tap.test("setting proxy_port should use the proxy agent", function(t) {
})
})

tap.test("proxy agent with SSL tunnel to collector", function(t) {
tap.test('proxy agent with SSL tunnel to collector', function(t) {
var server = proxySetup(https.createServer())
var port = 0

Expand Down Expand Up @@ -93,16 +146,16 @@ tap.test("proxy agent with SSL tunnel to collector", function(t) {


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")
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")
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()
Expand All @@ -111,15 +164,15 @@ tap.test("proxy agent with SSL tunnel to collector", function(t) {
})
})

tap.test("proxy authentication should set headers", function(t) {
tap.test('proxy authentication should set headers', function(t) {
t.plan(2)

var server = net.createServer()

server.on('connection', function(socket) {
socket.on('data', function(chunk) {
var data = chunk.toString().split('\r\n')
t.equal(data[0], 'CONNECT staging-collector.newrelic.com:80 HTTP/1.1')
t.equal(data[0], 'CONNECT staging-collector.newrelic.com:443 HTTP/1.1')
t.equal(data[1], 'Proxy-Authorization: Basic YTpi')
server.close()
})
Expand Down Expand Up @@ -157,7 +210,7 @@ tap.test("proxy authentication should set headers", function(t) {
})
})

test("no proxy set should not use proxy agent", function(t) {
tap.test('no proxy set should not use proxy agent', function(t) {
var config = configurator.initialize({
app_name: 'node.js Tests',
license_key: 'd67afc830dab717fd163bfcb0b8b88423e9a1a3b',
Expand All @@ -179,16 +232,16 @@ test("no proxy set should not use proxy agent", function(t) {


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")
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")
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')

t.end()
})
Expand Down

0 comments on commit 2c8bd99

Please sign in to comment.