Skip to content
This repository was archived by the owner on Jun 2, 2022. It is now read-only.

Commit 66575cf

Browse files
committed
feat: use the new flag to allow ignore unknown CAs when sending beacons
1 parent 117b27d commit 66575cf

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lib/transmitter.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ function transmitEvents(url, projectId, agentId) {
2424
loadedSources: currentState.packages,
2525
};
2626

27-
postPromise = needle('post', url, body, {json: true})
27+
const options = {
28+
json: true,
29+
rejectUnauthorized: !config['allowUnknownCA'],
30+
};
31+
32+
postPromise = needle('post', url, body, options)
2833
.then((response) => {
2934
if (response && response.statusCode !== 200) {
3035
debug('Unexpected response for events transmission: ' +

test/transmitter.test.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
const test = require('tap').test;
22
const proxyquire = require('proxyquire');
33
const nock = require('nock');
4+
const needle = require('needle');
45

56
const sinon = require('sinon');
67
const spy = sinon.spy();
78
const debugMock = (loggerType) => (msg) => {spy(msg);};
89
const state = require('../lib/state');
10+
const config = require('../lib/config');
11+
config.initConfig({projectId: 'some-project-id'});
912
const transmitter = proxyquire('../lib/transmitter', {'debug': debugMock});
1013

1114
test('Transmitter transmits 0 events for no events', async function (t) {
1215
nock('http://host')
13-
.post('/method')
14-
.reply(200, {});
16+
.post('/method')
17+
.reply(200, {});
18+
nock('http://host')
19+
.post('/method')
20+
.reply(200, {});
1521

1622
spy.resetHistory();
23+
const needleSpy = sinon.spy(needle, 'request');
1724

1825
await transmitter.transmitEvents('http://host/method', 'some-project-id', 'some-agent-id');
19-
t.ok(nock.isDone(), 'empty transmission sent');
26+
t.equal(needleSpy.args[0][0], 'post', 'beacons are being posted');
27+
t.equal(needleSpy.args[0][1], 'http://host/method', 'url is correct');
28+
t.ok('agentId' in needleSpy.args[0][2], 'agent ID is transmitted');
29+
t.equal(needleSpy.args[0][2]['agentId'], 'some-agent-id', 'agent ID is correct');
30+
t.ok('projectId' in needleSpy.args[0][2], 'project ID is transmitted');
31+
t.equal(needleSpy.args[0][2]['projectId'], 'some-project-id', 'project ID is correct');
32+
t.deepEqual(needleSpy.args[0][3], {json: true, rejectUnauthorized: true}, 'request options are correct');
33+
34+
config['allowUnknownCA'] = true;
35+
await transmitter.transmitEvents('http://host/method', 'some-project-id', 'some-agent-id');
36+
t.deepEqual(needleSpy.args[1][3], {json: true, rejectUnauthorized: false}, 'request options are correct');
37+
38+
t.ok(nock.isDone(), 'two transmissions sent');
39+
2040
nock.cleanAll();
2141
});
2242

0 commit comments

Comments
 (0)