Skip to content

Commit

Permalink
agent no longer forwards headers from connect response when in p16
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Clement committed Nov 29, 2018
1 parent 9049908 commit 67def4b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/collector/api.js
Expand Up @@ -211,8 +211,10 @@ CollectorAPI.prototype._connect = function _connect(env, callback) {
config.agent_run_id
)

// Store request headers for future collector requests if they're present
collector._reqHeadersMap = config.request_headers_map
if (agent.config.feature_flag.protocol_17) {
// Store request headers for future collector requests if they're present
collector._reqHeadersMap = config.request_headers_map
}

// pass configuration data from the API so automatic reconnect works
agent.reconfigure(config)
Expand Down
57 changes: 57 additions & 0 deletions test/unit/collector/api.test.js
Expand Up @@ -104,6 +104,63 @@ describe('CollectorAPI', function() {
})
})

describe('when getting request headers', function() {
var reqHeaderMap = {
'X-NR-TEST-HEADER': 'TEST VALUE'
}
var valid = {
capture_params: true,
agent_run_id: RUN_ID,
request_headers_map: reqHeaderMap
}

var response = {return_value: valid}
var oldProtocolVersion
beforeEach(function() {
oldProtocolVersion = agent.config.feature_flag.protocol_17
})

afterEach(function() {
agent.config.feature_flag.protocol_17 = oldProtocolVersion
})

it('should not copy them under p16', function(done) {
agent.config.port = 8080
agent.config.feature_flag.protocol_17 = false
var redirection = nock(URL + ':8080')
.post(helper.generateCollectorPath('preconnect'))
.reply(200, {return_value: {redirect_host: HOST, security_policies: {}}})
var connection = nock(URL)
.post(helper.generateCollectorPath('connect'))
.reply(200, response)

api._login(function test(error, config, json) {
expect(api._reqHeadersMap).to.be.null
redirection.done()
connection.done()
done()
})
})

it('should copy them under p17', function(done) {
agent.config.port = 8080
agent.config.feature_flag.protocol_17 = true
var redirection = nock(URL + ':8080')
.post(helper.generateCollectorPath('preconnect'))
.reply(200, {return_value: {redirect_host: HOST, security_policies: {}}})
var connection = nock(URL)
.post(helper.generateCollectorPath('connect'))
.reply(200, response)

api._login(function test(error, config, json) {
expect(api._reqHeadersMap).to.deep.equal(reqHeaderMap)
redirection.done()
connection.done()
done()
})
})
})

describe('on the happy path', function() {
var bad
var ssc
Expand Down

0 comments on commit 67def4b

Please sign in to comment.