rollbar 2.26.4 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +3 -0
- package/.cursor/rules/guidelines.mdc +154 -0
- package/.github/workflows/ci.yml +4 -6
- package/CLAUDE.local.md +297 -0
- package/CLAUDE.md +201 -0
- package/CLAUDE.testrunner.md +470 -0
- package/Gruntfile.js +59 -16
- package/Makefile +3 -3
- package/SECURITY.md +5 -0
- package/babel.config.json +9 -0
- package/codex.md +148 -0
- package/dist/plugins/jquery.min.js +1 -1
- package/dist/rollbar.js +19332 -6596
- package/dist/rollbar.js.map +1 -1
- package/dist/rollbar.min.js +2 -1
- package/dist/rollbar.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.min.js.map +1 -1
- package/dist/rollbar.named-amd.js +19332 -6596
- package/dist/rollbar.named-amd.js.map +1 -1
- package/dist/rollbar.named-amd.min.js +2 -1
- package/dist/rollbar.named-amd.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.named-amd.min.js.map +1 -1
- package/dist/rollbar.noconflict.umd.js +19319 -6581
- package/dist/rollbar.noconflict.umd.js.map +1 -1
- package/dist/rollbar.noconflict.umd.min.js +2 -1
- package/dist/rollbar.noconflict.umd.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.noconflict.umd.min.js.map +1 -1
- package/dist/rollbar.snippet.js +1 -1
- package/dist/rollbar.umd.js +19333 -6597
- package/dist/rollbar.umd.js.map +1 -1
- package/dist/rollbar.umd.min.js +2 -1
- package/dist/rollbar.umd.min.js.LICENSE.txt +1 -0
- package/dist/rollbar.umd.min.js.map +1 -1
- package/eslint.config.mjs +33 -0
- package/karma.conf.js +5 -14
- package/package.json +19 -20
- package/src/api.js +57 -4
- package/src/apiUtility.js +2 -3
- package/src/browser/core.js +37 -9
- package/src/browser/replay/defaults.js +70 -0
- package/src/browser/replay/recorder.js +194 -0
- package/src/browser/replay/replayMap.js +195 -0
- package/src/browser/rollbar.js +11 -7
- package/src/browser/telemetry.js +3 -3
- package/src/browser/transport/fetch.js +17 -4
- package/src/browser/transport/xhr.js +17 -1
- package/src/browser/transport.js +11 -8
- package/src/defaults.js +1 -1
- package/src/queue.js +65 -4
- package/src/react-native/rollbar.js +1 -1
- package/src/rollbar.js +52 -10
- package/src/server/rollbar.js +3 -2
- package/src/telemetry.js +76 -11
- package/src/tracing/context.js +24 -0
- package/src/tracing/contextManager.js +37 -0
- package/src/tracing/defaults.js +7 -0
- package/src/tracing/exporter.js +188 -0
- package/src/tracing/hrtime.js +98 -0
- package/src/tracing/id.js +24 -0
- package/src/tracing/session.js +55 -0
- package/src/tracing/span.js +92 -0
- package/src/tracing/spanProcessor.js +15 -0
- package/src/tracing/tracer.js +46 -0
- package/src/tracing/tracing.js +89 -0
- package/src/utility.js +34 -0
- package/test/api.test.js +57 -12
- package/test/apiUtility.test.js +5 -6
- package/test/browser.core.test.js +1 -10
- package/test/browser.domUtility.test.js +1 -1
- package/test/browser.predicates.test.js +1 -1
- package/test/browser.replay.recorder.test.js +430 -0
- package/test/browser.rollbar.test.js +58 -12
- package/test/browser.telemetry.test.js +1 -1
- package/test/browser.transforms.test.js +20 -13
- package/test/browser.transport.test.js +5 -4
- package/test/browser.url.test.js +1 -1
- package/test/fixtures/replay/index.js +20 -0
- package/test/fixtures/replay/payloads.fixtures.js +229 -0
- package/test/fixtures/replay/rrwebEvents.fixtures.js +251 -0
- package/test/fixtures/replay/rrwebSyntheticEvents.fixtures.js +328 -0
- package/test/notifier.test.js +1 -1
- package/test/predicates.test.js +1 -1
- package/test/queue.test.js +1 -1
- package/test/rateLimiter.test.js +1 -1
- package/test/react-native.rollbar.test.js +1 -1
- package/test/react-native.transforms.test.js +2 -2
- package/test/react-native.transport.test.js +3 -3
- package/test/replay/index.js +2 -0
- package/test/replay/integration/api.spans.test.js +136 -0
- package/test/replay/integration/e2e.test.js +228 -0
- package/test/replay/integration/index.js +9 -0
- package/test/replay/integration/queue.replayMap.test.js +332 -0
- package/test/replay/integration/replayMap.test.js +163 -0
- package/test/replay/integration/sessionRecording.test.js +390 -0
- package/test/replay/unit/api.postSpans.test.js +150 -0
- package/test/replay/unit/index.js +7 -0
- package/test/replay/unit/queue.replayMap.test.js +225 -0
- package/test/replay/unit/replayMap.test.js +348 -0
- package/test/replay/util/index.js +5 -0
- package/test/replay/util/mockRecordFn.js +80 -0
- package/test/server.lambda.mocha.test.mjs +172 -0
- package/test/server.locals.constructor.mocha.test.mjs +80 -0
- package/test/server.locals.error-handling.mocha.test.mjs +387 -0
- package/test/server.locals.merge.mocha.test.mjs +267 -0
- package/test/server.locals.test-utils.mjs +114 -0
- package/test/server.parser.mocha.test.mjs +87 -0
- package/test/server.predicates.mocha.test.mjs +63 -0
- package/test/server.rollbar.constructor.mocha.test.mjs +199 -0
- package/test/server.rollbar.handlers.mocha.test.mjs +253 -0
- package/test/server.rollbar.logging.mocha.test.mjs +326 -0
- package/test/server.rollbar.misc.mocha.test.mjs +44 -0
- package/test/server.rollbar.test-utils.mjs +57 -0
- package/test/server.telemetry.mocha.test.mjs +377 -0
- package/test/server.transforms.data.mocha.test.mjs +163 -0
- package/test/server.transforms.error.mocha.test.mjs +199 -0
- package/test/server.transforms.request.mocha.test.mjs +208 -0
- package/test/server.transforms.scrub.mocha.test.mjs +140 -0
- package/test/server.transforms.sourcemaps.mocha.test.mjs +122 -0
- package/test/server.transforms.test-utils.mjs +62 -0
- package/test/server.transport.mocha.test.mjs +269 -0
- package/test/telemetry.test.js +132 -1
- package/test/tracing/contextManager.test.js +28 -0
- package/test/tracing/exporter.toPayload.test.js +400 -0
- package/test/tracing/id.test.js +24 -0
- package/test/tracing/span.test.js +183 -0
- package/test/tracing/spanProcessor.test.js +73 -0
- package/test/tracing/tracing.test.js +105 -0
- package/test/transforms.test.js +2 -2
- package/test/truncation.test.js +2 -2
- package/test/utility.test.js +44 -6
- package/webpack.config.js +6 -44
- package/.eslintignore +0 -7
- package/test/server.lambda.test.js +0 -194
- package/test/server.locals.test.js +0 -1068
- package/test/server.parser.test.js +0 -78
- package/test/server.predicates.test.js +0 -91
- package/test/server.rollbar.test.js +0 -728
- package/test/server.telemetry.test.js +0 -443
- package/test/server.transforms.test.js +0 -1193
- package/test/server.transport.test.js +0 -269
|
@@ -1,1193 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var assert = require('assert');
|
|
4
|
-
var util = require('util');
|
|
5
|
-
var vows = require('vows');
|
|
6
|
-
var sinon = require('sinon');
|
|
7
|
-
var t = require('../src/server/transforms');
|
|
8
|
-
|
|
9
|
-
process.env.NODE_ENV = process.env.NODE_ENV || 'test-node-env';
|
|
10
|
-
var rollbar = require('../src/server/rollbar');
|
|
11
|
-
var _ = require('../src/utility');
|
|
12
|
-
|
|
13
|
-
function CustomError(message, nested) {
|
|
14
|
-
rollbar.Error.call(this, message, nested);
|
|
15
|
-
}
|
|
16
|
-
util.inherits(CustomError, rollbar.Error);
|
|
17
|
-
|
|
18
|
-
async function wait(ms) {
|
|
19
|
-
return new Promise((resolve) => {
|
|
20
|
-
setTimeout(resolve, ms);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function throwInScriptFile(rollbar, filepath, callback) {
|
|
25
|
-
setTimeout(function () {
|
|
26
|
-
var error = require(filepath);
|
|
27
|
-
error();
|
|
28
|
-
}, 10);
|
|
29
|
-
await wait(500);
|
|
30
|
-
callback(rollbar);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var nodeVersion = (function () {
|
|
34
|
-
var version = process.versions.node.split('.');
|
|
35
|
-
|
|
36
|
-
return [parseInt(version[0]), parseInt(version[1]), parseInt(version[2])];
|
|
37
|
-
})();
|
|
38
|
-
|
|
39
|
-
var isMinNodeVersion = function (major, minor) {
|
|
40
|
-
return (
|
|
41
|
-
nodeVersion[0] > major ||
|
|
42
|
-
(nodeVersion[0] === major && nodeVersion[1] >= minor)
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
vows
|
|
47
|
-
.describe('transforms')
|
|
48
|
-
.addBatch({
|
|
49
|
-
baseData: {
|
|
50
|
-
options: {
|
|
51
|
-
defaults: {
|
|
52
|
-
topic: function () {
|
|
53
|
-
return rollbar.defaultOptions;
|
|
54
|
-
},
|
|
55
|
-
item: {
|
|
56
|
-
empty: {
|
|
57
|
-
topic: function (options) {
|
|
58
|
-
var item = {};
|
|
59
|
-
t.baseData(item, options, this.callback);
|
|
60
|
-
},
|
|
61
|
-
'should have a timestamp': function (err, item) {
|
|
62
|
-
assert.ifError(err);
|
|
63
|
-
assert.notEqual(item.data, undefined);
|
|
64
|
-
assert.notEqual(item.data.timestamp, undefined);
|
|
65
|
-
},
|
|
66
|
-
'should have an error level': function (err, item) {
|
|
67
|
-
assert.ifError(err);
|
|
68
|
-
assert.notEqual(item.data, undefined);
|
|
69
|
-
assert.equal(item.data.level, 'error');
|
|
70
|
-
},
|
|
71
|
-
'should have some defaults': function (err, item) {
|
|
72
|
-
assert.ifError(err);
|
|
73
|
-
var data = item.data;
|
|
74
|
-
assert.equal(data.environment, process.env.NODE_ENV);
|
|
75
|
-
assert.equal(data.framework, 'node-js');
|
|
76
|
-
assert.equal(data.language, 'javascript');
|
|
77
|
-
assert.ok(data.server);
|
|
78
|
-
assert.ok(data.server.host);
|
|
79
|
-
assert.ok(data.server.pid);
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
'with values': {
|
|
83
|
-
topic: function (options) {
|
|
84
|
-
var item = {
|
|
85
|
-
level: 'critical',
|
|
86
|
-
framework: 'star-wars',
|
|
87
|
-
uuid: '12345',
|
|
88
|
-
environment: 'production',
|
|
89
|
-
custom: {
|
|
90
|
-
one: 'a1',
|
|
91
|
-
stuff: 'b2',
|
|
92
|
-
language: 'english',
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
t.baseData(item, options, this.callback);
|
|
96
|
-
},
|
|
97
|
-
'should have a critical level': function (err, item) {
|
|
98
|
-
assert.ifError(err);
|
|
99
|
-
assert.equal(item.data.level, 'critical');
|
|
100
|
-
},
|
|
101
|
-
'should have the defaults overriden by the item': function (
|
|
102
|
-
err,
|
|
103
|
-
item,
|
|
104
|
-
) {
|
|
105
|
-
assert.ifError(err);
|
|
106
|
-
assert.equal(item.data.environment, 'production');
|
|
107
|
-
assert.equal(item.data.framework, 'star-wars');
|
|
108
|
-
assert.equal(item.data.language, 'javascript');
|
|
109
|
-
assert.equal(item.data.uuid, '12345');
|
|
110
|
-
},
|
|
111
|
-
'should have data from custom': function (err, item) {
|
|
112
|
-
assert.equal(item.data.one, 'a1');
|
|
113
|
-
assert.equal(item.data.stuff, 'b2');
|
|
114
|
-
assert.notEqual(item.data.language, 'english');
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
'with values': {
|
|
120
|
-
topic: function () {
|
|
121
|
-
return _.merge(rollbar.defaultOptions, {
|
|
122
|
-
payload: {
|
|
123
|
-
environment: 'payload-prod',
|
|
124
|
-
},
|
|
125
|
-
framework: 'opt-node',
|
|
126
|
-
host: 'opt-host',
|
|
127
|
-
branch: 'opt-master',
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
item: {
|
|
131
|
-
empty: {
|
|
132
|
-
topic: function (options) {
|
|
133
|
-
var item = {};
|
|
134
|
-
t.baseData(item, options, this.callback);
|
|
135
|
-
},
|
|
136
|
-
'should have a timestamp': function (err, item) {
|
|
137
|
-
assert.ifError(err);
|
|
138
|
-
assert.notEqual(item.data, undefined);
|
|
139
|
-
assert.notEqual(item.data.timestamp, undefined);
|
|
140
|
-
},
|
|
141
|
-
'should have an error level': function (err, item) {
|
|
142
|
-
assert.ifError(err);
|
|
143
|
-
assert.notEqual(item.data, undefined);
|
|
144
|
-
assert.equal(item.data.level, 'error');
|
|
145
|
-
},
|
|
146
|
-
'should have data from options and defaults': function (
|
|
147
|
-
err,
|
|
148
|
-
item,
|
|
149
|
-
) {
|
|
150
|
-
assert.ifError(err);
|
|
151
|
-
var data = item.data;
|
|
152
|
-
assert.equal(data.environment, 'payload-prod');
|
|
153
|
-
assert.equal(data.framework, 'opt-node');
|
|
154
|
-
assert.equal(data.language, 'javascript');
|
|
155
|
-
assert.ok(data.server);
|
|
156
|
-
assert.equal(data.server.host, 'opt-host');
|
|
157
|
-
assert.equal(data.server.branch, 'opt-master');
|
|
158
|
-
assert.ok(data.server.pid);
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
'with values': {
|
|
162
|
-
topic: function (options) {
|
|
163
|
-
var item = {
|
|
164
|
-
level: 'critical',
|
|
165
|
-
environment: 'production',
|
|
166
|
-
framework: 'star-wars',
|
|
167
|
-
uuid: '12345',
|
|
168
|
-
custom: {
|
|
169
|
-
one: 'a1',
|
|
170
|
-
stuff: 'b2',
|
|
171
|
-
language: 'english',
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
t.baseData(item, options, this.callback);
|
|
175
|
-
},
|
|
176
|
-
'should have a critical level': function (err, item) {
|
|
177
|
-
assert.ifError(err);
|
|
178
|
-
assert.equal(item.data.level, 'critical');
|
|
179
|
-
},
|
|
180
|
-
'should have the defaults overriden by the item': function (
|
|
181
|
-
err,
|
|
182
|
-
item,
|
|
183
|
-
) {
|
|
184
|
-
assert.ifError(err);
|
|
185
|
-
assert.equal(item.data.environment, 'production');
|
|
186
|
-
assert.equal(item.data.framework, 'star-wars');
|
|
187
|
-
assert.equal(item.data.language, 'javascript');
|
|
188
|
-
assert.equal(item.data.uuid, '12345');
|
|
189
|
-
},
|
|
190
|
-
'should have data from custom': function (err, item) {
|
|
191
|
-
assert.equal(item.data.one, 'a1');
|
|
192
|
-
assert.equal(item.data.stuff, 'b2');
|
|
193
|
-
assert.notEqual(item.data.language, 'english');
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
})
|
|
201
|
-
.addBatch({
|
|
202
|
-
addBody: {
|
|
203
|
-
options: {
|
|
204
|
-
anything: {
|
|
205
|
-
topic: function () {
|
|
206
|
-
return { whatever: 'stuff' };
|
|
207
|
-
},
|
|
208
|
-
item: {
|
|
209
|
-
'with stackInfo': {
|
|
210
|
-
topic: function (options) {
|
|
211
|
-
var item = { stackInfo: [{ message: 'hey' }] };
|
|
212
|
-
t.addBody(item, options, this.callback);
|
|
213
|
-
},
|
|
214
|
-
'should not error': function (err, item) {
|
|
215
|
-
assert.ifError(err);
|
|
216
|
-
},
|
|
217
|
-
'should set the trace_chain': function (err, item) {
|
|
218
|
-
assert.ok(item.data.body.trace_chain);
|
|
219
|
-
},
|
|
220
|
-
'should not set a message': function (err, item) {
|
|
221
|
-
assert.ok(!item.data.body.message);
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
'with no stackInfo': {
|
|
225
|
-
topic: function (options) {
|
|
226
|
-
var item = { message: 'hello' };
|
|
227
|
-
t.addBody(item, options, this.callback);
|
|
228
|
-
},
|
|
229
|
-
'should not error': function (err, item) {
|
|
230
|
-
assert.ifError(err);
|
|
231
|
-
},
|
|
232
|
-
'should not set the trace_chain': function (err, item) {
|
|
233
|
-
assert.ok(!item.data.body.trace_chain);
|
|
234
|
-
},
|
|
235
|
-
'should set a message': function (err, item) {
|
|
236
|
-
assert.ok(item.data.body.message);
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
},
|
|
242
|
-
},
|
|
243
|
-
})
|
|
244
|
-
.addBatch({
|
|
245
|
-
addMessageData: {
|
|
246
|
-
options: {
|
|
247
|
-
anything: {
|
|
248
|
-
topic: function () {
|
|
249
|
-
return { random: 'stuff' };
|
|
250
|
-
},
|
|
251
|
-
item: {
|
|
252
|
-
'no message': {
|
|
253
|
-
topic: function (options) {
|
|
254
|
-
var item = { err: 'stuff', not: 'a message' };
|
|
255
|
-
t.addMessageData(item, options, this.callback);
|
|
256
|
-
},
|
|
257
|
-
'should not error': function (err, item) {
|
|
258
|
-
assert.ifError(err);
|
|
259
|
-
},
|
|
260
|
-
'should add an empty body': function (err, item) {
|
|
261
|
-
assert.ok(item.data.body);
|
|
262
|
-
},
|
|
263
|
-
},
|
|
264
|
-
'with a message': {
|
|
265
|
-
topic: function (options) {
|
|
266
|
-
var item = { message: 'this is awesome' };
|
|
267
|
-
t.addMessageData(item, options, this.callback);
|
|
268
|
-
},
|
|
269
|
-
'should not error': function (err, item) {
|
|
270
|
-
assert.ifError(err);
|
|
271
|
-
},
|
|
272
|
-
'should add a body with the message': function (err, item) {
|
|
273
|
-
assert.equal(item.data.body.message.body, 'this is awesome');
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
})
|
|
281
|
-
.addBatch({
|
|
282
|
-
nodeSourceMaps: {
|
|
283
|
-
'with original source present': {
|
|
284
|
-
topic: function () {
|
|
285
|
-
var Rollbar = new rollbar({
|
|
286
|
-
accessToken: 'abc123',
|
|
287
|
-
captureUncaught: true,
|
|
288
|
-
nodeSourceMaps: true,
|
|
289
|
-
});
|
|
290
|
-
var queue = Rollbar.client.notifier.queue;
|
|
291
|
-
Rollbar.addItemStub = sinon.stub(queue, 'addItem');
|
|
292
|
-
|
|
293
|
-
throwInScriptFile(
|
|
294
|
-
Rollbar,
|
|
295
|
-
'../examples/node-typescript/dist/index',
|
|
296
|
-
this.callback,
|
|
297
|
-
);
|
|
298
|
-
},
|
|
299
|
-
'should map the stack with context': function (r) {
|
|
300
|
-
var addItem = r.addItemStub;
|
|
301
|
-
|
|
302
|
-
assert.isTrue(addItem.called);
|
|
303
|
-
if (addItem.called) {
|
|
304
|
-
var frame = addItem
|
|
305
|
-
.getCall(0)
|
|
306
|
-
.args[0].body.trace_chain[0].frames.pop();
|
|
307
|
-
assert.ok(frame.filename.includes('src/index.ts'));
|
|
308
|
-
assert.equal(frame.lineno, 10);
|
|
309
|
-
assert.equal(frame.colno, 22);
|
|
310
|
-
assert.equal(
|
|
311
|
-
frame.code,
|
|
312
|
-
" var error = <Error> new CustomError('foo');",
|
|
313
|
-
);
|
|
314
|
-
assert.equal(frame.context.pre[0], ' }');
|
|
315
|
-
assert.equal(frame.context.pre[1], ' }');
|
|
316
|
-
assert.equal(
|
|
317
|
-
frame.context.pre[2],
|
|
318
|
-
' // TypeScript code snippet will include `<Error>`',
|
|
319
|
-
);
|
|
320
|
-
assert.equal(frame.context.post[0], ' throw error;');
|
|
321
|
-
assert.equal(frame.context.post[1], '}');
|
|
322
|
-
|
|
323
|
-
var sourceMappingURLs =
|
|
324
|
-
addItem.getCall(0).args[0].notifier.diagnostic.node_source_maps
|
|
325
|
-
.source_mapping_urls;
|
|
326
|
-
var urls = Object.keys(sourceMappingURLs);
|
|
327
|
-
assert.ok(urls[0].includes('index.js'));
|
|
328
|
-
assert.ok(sourceMappingURLs[urls[0]].includes('index.js.map'));
|
|
329
|
-
assert.ok(urls[1].includes('server.transforms.test.js'));
|
|
330
|
-
assert.ok(sourceMappingURLs[urls[1]].includes('not found'));
|
|
331
|
-
|
|
332
|
-
// Node until v12 will have 'timers.js' here.
|
|
333
|
-
// Node 12 - 14 will have 'internal/timers.js' here.
|
|
334
|
-
// Starting in v16, this is 'node:internal/timers'.
|
|
335
|
-
// This assert works for all and is specific enough for this test case.
|
|
336
|
-
assert.ok(urls[2].includes('timers'));
|
|
337
|
-
assert.ok(sourceMappingURLs[urls[2]].includes('not found'));
|
|
338
|
-
}
|
|
339
|
-
addItem.reset();
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
})
|
|
344
|
-
.addBatch({
|
|
345
|
-
nodeSourceMaps: {
|
|
346
|
-
'using sourcesContent': {
|
|
347
|
-
topic: function () {
|
|
348
|
-
var Rollbar = new rollbar({
|
|
349
|
-
accessToken: 'abc123',
|
|
350
|
-
captureUncaught: true,
|
|
351
|
-
nodeSourceMaps: true,
|
|
352
|
-
});
|
|
353
|
-
var queue = Rollbar.client.notifier.queue;
|
|
354
|
-
Rollbar.addItemStub = sinon.stub(queue, 'addItem');
|
|
355
|
-
|
|
356
|
-
throwInScriptFile(
|
|
357
|
-
Rollbar,
|
|
358
|
-
'../examples/node-dist/index',
|
|
359
|
-
this.callback,
|
|
360
|
-
);
|
|
361
|
-
},
|
|
362
|
-
'should map the stack with context': function (r) {
|
|
363
|
-
var addItem = r.addItemStub;
|
|
364
|
-
|
|
365
|
-
assert.isTrue(addItem.called);
|
|
366
|
-
if (addItem.called) {
|
|
367
|
-
var frame = addItem
|
|
368
|
-
.getCall(0)
|
|
369
|
-
.args[0].body.trace_chain[0].frames.pop();
|
|
370
|
-
assert.ok(frame.filename.includes('src/index.ts'));
|
|
371
|
-
assert.equal(frame.lineno, 10);
|
|
372
|
-
assert.equal(frame.colno, 22);
|
|
373
|
-
assert.equal(
|
|
374
|
-
frame.code,
|
|
375
|
-
" var error = <Error> new CustomError('foo');",
|
|
376
|
-
);
|
|
377
|
-
assert.equal(frame.context.pre[0], ' }');
|
|
378
|
-
assert.equal(frame.context.pre[1], ' }');
|
|
379
|
-
assert.equal(
|
|
380
|
-
frame.context.pre[2],
|
|
381
|
-
' // TypeScript code snippet will include `<Error>`',
|
|
382
|
-
);
|
|
383
|
-
assert.equal(frame.context.post[0], ' throw error;');
|
|
384
|
-
assert.equal(frame.context.post[1], '}');
|
|
385
|
-
|
|
386
|
-
var sourceMappingURLs =
|
|
387
|
-
addItem.getCall(0).args[0].notifier.diagnostic.node_source_maps
|
|
388
|
-
.source_mapping_urls;
|
|
389
|
-
var urls = Object.keys(sourceMappingURLs);
|
|
390
|
-
assert.ok(urls.length === 1);
|
|
391
|
-
assert.ok(urls[0].includes('index.js'));
|
|
392
|
-
assert.ok(sourceMappingURLs[urls[0]].includes('index.js.map'));
|
|
393
|
-
}
|
|
394
|
-
addItem.reset();
|
|
395
|
-
},
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
})
|
|
399
|
-
.addBatch({
|
|
400
|
-
handleItemWithError: {
|
|
401
|
-
options: {
|
|
402
|
-
anything: {
|
|
403
|
-
topic: function () {
|
|
404
|
-
return {
|
|
405
|
-
some: 'stuff',
|
|
406
|
-
captureIp: true,
|
|
407
|
-
};
|
|
408
|
-
},
|
|
409
|
-
item: {
|
|
410
|
-
'no error': {
|
|
411
|
-
topic: function (options) {
|
|
412
|
-
var item = {
|
|
413
|
-
data: { body: { yo: 'hey' } },
|
|
414
|
-
message: 'hey',
|
|
415
|
-
};
|
|
416
|
-
t.handleItemWithError(item, options, this.callback);
|
|
417
|
-
},
|
|
418
|
-
'should not error': function (err, item) {
|
|
419
|
-
assert.ifError(err);
|
|
420
|
-
},
|
|
421
|
-
'should not change the item': function (err, item) {
|
|
422
|
-
assert.equal(item.data.body.yo, 'hey');
|
|
423
|
-
},
|
|
424
|
-
},
|
|
425
|
-
'with a simple error': {
|
|
426
|
-
topic: function (options) {
|
|
427
|
-
var item = {
|
|
428
|
-
data: { body: {} },
|
|
429
|
-
err: new Error('wookie'),
|
|
430
|
-
};
|
|
431
|
-
t.handleItemWithError(item, options, this.callback);
|
|
432
|
-
},
|
|
433
|
-
'should not error': function (err, item) {
|
|
434
|
-
assert.ifError(err);
|
|
435
|
-
},
|
|
436
|
-
'should add some data to the trace_chain': function (err, item) {
|
|
437
|
-
assert.ok(item.stackInfo);
|
|
438
|
-
},
|
|
439
|
-
},
|
|
440
|
-
'with a normal error': {
|
|
441
|
-
topic: function (options) {
|
|
442
|
-
var test = function () {
|
|
443
|
-
var x = thisVariableIsNotDefined;
|
|
444
|
-
};
|
|
445
|
-
var err;
|
|
446
|
-
try {
|
|
447
|
-
test();
|
|
448
|
-
} catch (e) {
|
|
449
|
-
err = e;
|
|
450
|
-
}
|
|
451
|
-
var item = {
|
|
452
|
-
data: { body: {} },
|
|
453
|
-
err: err,
|
|
454
|
-
};
|
|
455
|
-
t.handleItemWithError(item, options, this.callback);
|
|
456
|
-
},
|
|
457
|
-
'should not error': function (err, item) {
|
|
458
|
-
assert.ifError(err);
|
|
459
|
-
},
|
|
460
|
-
'should add some data to the trace_chain': function (err, item) {
|
|
461
|
-
assert.ok(item.stackInfo);
|
|
462
|
-
},
|
|
463
|
-
},
|
|
464
|
-
'with a nested error': {
|
|
465
|
-
topic: function (options) {
|
|
466
|
-
var test = function () {
|
|
467
|
-
var x = thisVariableIsNotDefined;
|
|
468
|
-
};
|
|
469
|
-
var err;
|
|
470
|
-
try {
|
|
471
|
-
test();
|
|
472
|
-
} catch (e) {
|
|
473
|
-
err = new CustomError('nested-message', e);
|
|
474
|
-
}
|
|
475
|
-
var item = {
|
|
476
|
-
data: { body: {} },
|
|
477
|
-
err: err,
|
|
478
|
-
};
|
|
479
|
-
t.handleItemWithError(item, options, this.callback);
|
|
480
|
-
},
|
|
481
|
-
'should not error': function (err, item) {
|
|
482
|
-
assert.ifError(err);
|
|
483
|
-
},
|
|
484
|
-
'should have the right data in the trace_chain': function (
|
|
485
|
-
err,
|
|
486
|
-
item,
|
|
487
|
-
) {
|
|
488
|
-
var trace_chain = item.stackInfo;
|
|
489
|
-
assert.lengthOf(trace_chain, 2);
|
|
490
|
-
assert.equal(trace_chain[0].exception.class, 'CustomError');
|
|
491
|
-
assert.equal(
|
|
492
|
-
trace_chain[0].exception.message,
|
|
493
|
-
'nested-message',
|
|
494
|
-
);
|
|
495
|
-
assert.equal(trace_chain[1].exception.class, 'ReferenceError');
|
|
496
|
-
},
|
|
497
|
-
},
|
|
498
|
-
'with a null nested error': {
|
|
499
|
-
topic: function (options) {
|
|
500
|
-
var err = new CustomError('With null nested error');
|
|
501
|
-
|
|
502
|
-
// Set nested to null for the test
|
|
503
|
-
err.nested = null;
|
|
504
|
-
|
|
505
|
-
var item = {
|
|
506
|
-
data: { body: {} },
|
|
507
|
-
err: err,
|
|
508
|
-
};
|
|
509
|
-
t.handleItemWithError(item, options, this.callback);
|
|
510
|
-
},
|
|
511
|
-
'should not error': function (err, item) {
|
|
512
|
-
assert.ifError(err);
|
|
513
|
-
},
|
|
514
|
-
'should have the right data in the trace_chain': function (
|
|
515
|
-
err,
|
|
516
|
-
item,
|
|
517
|
-
) {
|
|
518
|
-
var trace_chain = item.stackInfo;
|
|
519
|
-
assert.lengthOf(trace_chain, 1);
|
|
520
|
-
assert.equal(trace_chain[0].exception.class, 'CustomError');
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
|
-
'with error context': {
|
|
524
|
-
topic: function (options) {
|
|
525
|
-
var test = function () {
|
|
526
|
-
var x = thisVariableIsNotDefined;
|
|
527
|
-
};
|
|
528
|
-
var err;
|
|
529
|
-
try {
|
|
530
|
-
test();
|
|
531
|
-
} catch (e) {
|
|
532
|
-
err = new CustomError('nested-message', e);
|
|
533
|
-
e.rollbarContext = { err1: 'nested context' };
|
|
534
|
-
err.rollbarContext = { err2: 'error context' };
|
|
535
|
-
}
|
|
536
|
-
var item = {
|
|
537
|
-
data: { body: {} },
|
|
538
|
-
err: err,
|
|
539
|
-
};
|
|
540
|
-
options.addErrorContext = true;
|
|
541
|
-
t.handleItemWithError(item, options, this.callback);
|
|
542
|
-
},
|
|
543
|
-
'should not error': function (err, item) {
|
|
544
|
-
assert.ifError(err);
|
|
545
|
-
},
|
|
546
|
-
'should add the error context': function (err, item) {
|
|
547
|
-
var trace_chain = item.stackInfo;
|
|
548
|
-
assert.lengthOf(trace_chain, 2);
|
|
549
|
-
assert.equal(item.data.custom.err1, 'nested context');
|
|
550
|
-
assert.equal(item.data.custom.err2, 'error context');
|
|
551
|
-
},
|
|
552
|
-
},
|
|
553
|
-
'with an error cause': {
|
|
554
|
-
topic: function (options) {
|
|
555
|
-
var test = function () {
|
|
556
|
-
var x = thisVariableIsNotDefined;
|
|
557
|
-
};
|
|
558
|
-
var err;
|
|
559
|
-
try {
|
|
560
|
-
test();
|
|
561
|
-
} catch (e) {
|
|
562
|
-
err = new Error('cause message', { cause: e });
|
|
563
|
-
e.rollbarContext = { err1: 'cause context' };
|
|
564
|
-
err.rollbarContext = { err2: 'error context' };
|
|
565
|
-
}
|
|
566
|
-
var item = {
|
|
567
|
-
data: { body: {} },
|
|
568
|
-
err: err,
|
|
569
|
-
};
|
|
570
|
-
t.handleItemWithError(item, options, this.callback);
|
|
571
|
-
},
|
|
572
|
-
'should not error': function (err, item) {
|
|
573
|
-
assert.ifError(err);
|
|
574
|
-
},
|
|
575
|
-
'should have the right data in the trace_chain': function (
|
|
576
|
-
err,
|
|
577
|
-
item,
|
|
578
|
-
) {
|
|
579
|
-
// Error cause was introduced in Node 16.9.
|
|
580
|
-
if (!isMinNodeVersion(16, 9)) return;
|
|
581
|
-
|
|
582
|
-
var trace_chain = item.stackInfo;
|
|
583
|
-
assert.lengthOf(trace_chain, 2);
|
|
584
|
-
assert.equal(trace_chain[0].exception.class, 'Error');
|
|
585
|
-
assert.equal(trace_chain[0].exception.message, 'cause message');
|
|
586
|
-
assert.equal(trace_chain[1].exception.class, 'ReferenceError');
|
|
587
|
-
assert.equal(item.data.custom.err1, 'cause context');
|
|
588
|
-
assert.equal(item.data.custom.err2, 'error context');
|
|
589
|
-
},
|
|
590
|
-
},
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
},
|
|
594
|
-
},
|
|
595
|
-
})
|
|
596
|
-
.addBatch({
|
|
597
|
-
addRequestData: {
|
|
598
|
-
options: {
|
|
599
|
-
'without custom addRequestData method': {
|
|
600
|
-
'without scrub fields': {
|
|
601
|
-
topic: function () {
|
|
602
|
-
return {
|
|
603
|
-
nothing: 'here',
|
|
604
|
-
captureEmail: true,
|
|
605
|
-
captureUsername: true,
|
|
606
|
-
captureIp: true,
|
|
607
|
-
};
|
|
608
|
-
},
|
|
609
|
-
item: {
|
|
610
|
-
'without a request': {
|
|
611
|
-
topic: function (options) {
|
|
612
|
-
var item = {
|
|
613
|
-
data: { body: { message: 'hey' } },
|
|
614
|
-
};
|
|
615
|
-
t.addRequestData(item, options, this.callback);
|
|
616
|
-
},
|
|
617
|
-
'should not error': function (err, item) {
|
|
618
|
-
assert.ifError(err);
|
|
619
|
-
},
|
|
620
|
-
'should not change the item': function (err, item) {
|
|
621
|
-
assert.equal(item.request, undefined);
|
|
622
|
-
assert.equal(item.data.request, undefined);
|
|
623
|
-
},
|
|
624
|
-
},
|
|
625
|
-
'with an empty request object': {
|
|
626
|
-
topic: function (options) {
|
|
627
|
-
var item = {
|
|
628
|
-
request: {},
|
|
629
|
-
data: { body: { message: 'hey' } },
|
|
630
|
-
};
|
|
631
|
-
t.addRequestData(item, options, this.callback);
|
|
632
|
-
},
|
|
633
|
-
'should not error': function (err, item) {
|
|
634
|
-
assert.ifError(err);
|
|
635
|
-
},
|
|
636
|
-
'should not change request object': function (err, item) {
|
|
637
|
-
assert.equal(item.request.headers, undefined);
|
|
638
|
-
},
|
|
639
|
-
},
|
|
640
|
-
'with a request': {
|
|
641
|
-
topic: function (options) {
|
|
642
|
-
var item = {
|
|
643
|
-
request: {
|
|
644
|
-
headers: {
|
|
645
|
-
host: 'example.com',
|
|
646
|
-
'x-auth-token': '12345',
|
|
647
|
-
},
|
|
648
|
-
protocol: 'https',
|
|
649
|
-
url: '/some/endpoint',
|
|
650
|
-
ip: '192.192.192.1',
|
|
651
|
-
method: 'GET',
|
|
652
|
-
body: {
|
|
653
|
-
token: 'abc123',
|
|
654
|
-
something: 'else',
|
|
655
|
-
},
|
|
656
|
-
route: { path: '/api/:bork' },
|
|
657
|
-
user: {
|
|
658
|
-
id: 42,
|
|
659
|
-
email: 'fake@example.com',
|
|
660
|
-
},
|
|
661
|
-
},
|
|
662
|
-
stuff: 'hey',
|
|
663
|
-
data: { other: 'thing' },
|
|
664
|
-
};
|
|
665
|
-
t.addRequestData(item, options, this.callback);
|
|
666
|
-
},
|
|
667
|
-
'should not error': function (err, item) {
|
|
668
|
-
assert.ifError(err);
|
|
669
|
-
},
|
|
670
|
-
'should have a request object inside data': function (
|
|
671
|
-
err,
|
|
672
|
-
item,
|
|
673
|
-
) {
|
|
674
|
-
assert.ok(item.data.request);
|
|
675
|
-
},
|
|
676
|
-
'should set a person based on request user': function (
|
|
677
|
-
err,
|
|
678
|
-
item,
|
|
679
|
-
) {
|
|
680
|
-
assert.equal(item.data.person.id, 42);
|
|
681
|
-
assert.equal(item.data.person.email, 'fake@example.com');
|
|
682
|
-
},
|
|
683
|
-
'should set some fields based on request data': function (
|
|
684
|
-
err,
|
|
685
|
-
item,
|
|
686
|
-
) {
|
|
687
|
-
var r = item.data.request;
|
|
688
|
-
assert.equal(r.url, 'https://example.com/some/endpoint');
|
|
689
|
-
assert.equal(r.user_ip, '192.192.192.1');
|
|
690
|
-
assert.ok(r.GET);
|
|
691
|
-
|
|
692
|
-
assert.equal(item.data.context, '/api/:bork');
|
|
693
|
-
},
|
|
694
|
-
},
|
|
695
|
-
'with a request for a nested router with a baseURL': {
|
|
696
|
-
topic: function (options) {
|
|
697
|
-
var item = {
|
|
698
|
-
request: {
|
|
699
|
-
headers: {
|
|
700
|
-
host: 'example.com',
|
|
701
|
-
'x-auth-token': '12345',
|
|
702
|
-
},
|
|
703
|
-
protocol: 'https',
|
|
704
|
-
url: '/some/endpoint',
|
|
705
|
-
baseUrl: '/nested',
|
|
706
|
-
ip: '192.192.192.1',
|
|
707
|
-
method: 'GET',
|
|
708
|
-
body: {
|
|
709
|
-
token: 'abc123',
|
|
710
|
-
something: 'else',
|
|
711
|
-
},
|
|
712
|
-
route: { path: '/api/:bork' },
|
|
713
|
-
user: {
|
|
714
|
-
id: 42,
|
|
715
|
-
email: 'fake@example.com',
|
|
716
|
-
},
|
|
717
|
-
},
|
|
718
|
-
stuff: 'hey',
|
|
719
|
-
data: { other: 'thing' },
|
|
720
|
-
};
|
|
721
|
-
t.addRequestData(item, options, this.callback);
|
|
722
|
-
},
|
|
723
|
-
'should not error': function (err, item) {
|
|
724
|
-
assert.ifError(err);
|
|
725
|
-
},
|
|
726
|
-
'should have a request object inside data': function (
|
|
727
|
-
err,
|
|
728
|
-
item,
|
|
729
|
-
) {
|
|
730
|
-
assert.ok(item.data.request);
|
|
731
|
-
},
|
|
732
|
-
'should set some fields based on request data': function (
|
|
733
|
-
err,
|
|
734
|
-
item,
|
|
735
|
-
) {
|
|
736
|
-
var r = item.data.request;
|
|
737
|
-
assert.equal(
|
|
738
|
-
r.url,
|
|
739
|
-
'https://example.com/nested/some/endpoint',
|
|
740
|
-
);
|
|
741
|
-
assert.equal(item.data.context, '/nested/api/:bork');
|
|
742
|
-
},
|
|
743
|
-
},
|
|
744
|
-
'with a request like from hapi': {
|
|
745
|
-
topic: function (options) {
|
|
746
|
-
var item = {
|
|
747
|
-
request: {
|
|
748
|
-
headers: {
|
|
749
|
-
host: 'example.com',
|
|
750
|
-
'x-auth-token': '12345',
|
|
751
|
-
},
|
|
752
|
-
protocol: 'https',
|
|
753
|
-
url: {
|
|
754
|
-
protocol: null,
|
|
755
|
-
slashes: null,
|
|
756
|
-
auth: null,
|
|
757
|
-
host: null,
|
|
758
|
-
port: null,
|
|
759
|
-
hostname: null,
|
|
760
|
-
hash: null,
|
|
761
|
-
search: '',
|
|
762
|
-
query: {},
|
|
763
|
-
pathname: '/some/endpoint',
|
|
764
|
-
path: '/some/endpoint',
|
|
765
|
-
href: '/some/endpoint',
|
|
766
|
-
},
|
|
767
|
-
ip: '192.192.192.1',
|
|
768
|
-
method: 'POST',
|
|
769
|
-
payload: {
|
|
770
|
-
token: 'abc123',
|
|
771
|
-
something: 'else',
|
|
772
|
-
},
|
|
773
|
-
route: { path: '/api/:bork' },
|
|
774
|
-
user: {
|
|
775
|
-
id: 42,
|
|
776
|
-
email: 'fake@example.com',
|
|
777
|
-
},
|
|
778
|
-
},
|
|
779
|
-
stuff: 'hey',
|
|
780
|
-
data: { other: 'thing' },
|
|
781
|
-
};
|
|
782
|
-
t.addRequestData(item, options, this.callback);
|
|
783
|
-
},
|
|
784
|
-
'should not error': function (err, item) {
|
|
785
|
-
assert.ifError(err);
|
|
786
|
-
},
|
|
787
|
-
'should have a request object inside data': function (
|
|
788
|
-
err,
|
|
789
|
-
item,
|
|
790
|
-
) {
|
|
791
|
-
assert.ok(item.data.request);
|
|
792
|
-
},
|
|
793
|
-
'should set a person based on request user': function (
|
|
794
|
-
err,
|
|
795
|
-
item,
|
|
796
|
-
) {
|
|
797
|
-
assert.equal(item.data.person.id, 42);
|
|
798
|
-
assert.equal(item.data.person.email, 'fake@example.com');
|
|
799
|
-
},
|
|
800
|
-
'should set some fields based on request data': function (
|
|
801
|
-
err,
|
|
802
|
-
item,
|
|
803
|
-
) {
|
|
804
|
-
var r = item.data.request;
|
|
805
|
-
assert.equal(r.url, 'https://example.com/some/endpoint');
|
|
806
|
-
assert.equal(r.user_ip, '192.192.192.1');
|
|
807
|
-
assert.ok(!r.GET);
|
|
808
|
-
assert.ok(r.POST);
|
|
809
|
-
|
|
810
|
-
assert.equal(item.data.context, '/api/:bork');
|
|
811
|
-
},
|
|
812
|
-
},
|
|
813
|
-
'with a request with an array body': {
|
|
814
|
-
topic: function (options) {
|
|
815
|
-
var item = {
|
|
816
|
-
request: {
|
|
817
|
-
headers: {
|
|
818
|
-
host: 'example.com',
|
|
819
|
-
'x-auth-token': '12345',
|
|
820
|
-
},
|
|
821
|
-
protocol: 'https',
|
|
822
|
-
url: '/some/endpoint',
|
|
823
|
-
ip: '192.192.192.1',
|
|
824
|
-
method: 'POST',
|
|
825
|
-
body: [
|
|
826
|
-
{
|
|
827
|
-
token: 'abc123',
|
|
828
|
-
something: 'else',
|
|
829
|
-
},
|
|
830
|
-
'otherStuff',
|
|
831
|
-
],
|
|
832
|
-
user: {
|
|
833
|
-
id: 42,
|
|
834
|
-
email: 'fake@example.com',
|
|
835
|
-
},
|
|
836
|
-
},
|
|
837
|
-
stuff: 'hey',
|
|
838
|
-
data: { other: 'thing' },
|
|
839
|
-
};
|
|
840
|
-
t.addRequestData(item, options, this.callback);
|
|
841
|
-
},
|
|
842
|
-
'should not error': function (err, item) {
|
|
843
|
-
assert.ifError(err);
|
|
844
|
-
},
|
|
845
|
-
'should have a request object inside data': function (
|
|
846
|
-
err,
|
|
847
|
-
item,
|
|
848
|
-
) {
|
|
849
|
-
assert.ok(item.data.request);
|
|
850
|
-
},
|
|
851
|
-
'should set a person based on request user': function (
|
|
852
|
-
err,
|
|
853
|
-
item,
|
|
854
|
-
) {
|
|
855
|
-
assert.equal(item.data.person.id, 42);
|
|
856
|
-
assert.equal(item.data.person.email, 'fake@example.com');
|
|
857
|
-
},
|
|
858
|
-
'should set some fields based on request data': function (
|
|
859
|
-
err,
|
|
860
|
-
item,
|
|
861
|
-
) {
|
|
862
|
-
var r = item.data.request;
|
|
863
|
-
assert.equal(r.url, 'https://example.com/some/endpoint');
|
|
864
|
-
assert.equal(r.user_ip, '192.192.192.1');
|
|
865
|
-
assert.ok(r.POST);
|
|
866
|
-
assert.equal(r.POST['0'].something, 'else');
|
|
867
|
-
assert.equal(r.POST['1'], 'otherStuff');
|
|
868
|
-
},
|
|
869
|
-
},
|
|
870
|
-
},
|
|
871
|
-
},
|
|
872
|
-
'with scrub fields': {
|
|
873
|
-
topic: function () {
|
|
874
|
-
return {
|
|
875
|
-
scrubHeaders: ['x-auth-token'],
|
|
876
|
-
scrubFields: ['passwd', 'access_token', 'request.cookie'],
|
|
877
|
-
};
|
|
878
|
-
},
|
|
879
|
-
item: {
|
|
880
|
-
'with a request': {
|
|
881
|
-
topic: function (options) {
|
|
882
|
-
var item = {
|
|
883
|
-
request: {
|
|
884
|
-
headers: {
|
|
885
|
-
host: 'example.com',
|
|
886
|
-
'x-auth-token': '12345',
|
|
887
|
-
},
|
|
888
|
-
protocol: 'https',
|
|
889
|
-
url: '/some/endpoint',
|
|
890
|
-
ip: '192.192.192.192',
|
|
891
|
-
method: 'GET',
|
|
892
|
-
body: {
|
|
893
|
-
token: 'abc123',
|
|
894
|
-
something: 'else',
|
|
895
|
-
},
|
|
896
|
-
user: {
|
|
897
|
-
id: 42,
|
|
898
|
-
email: 'fake@example.com',
|
|
899
|
-
},
|
|
900
|
-
},
|
|
901
|
-
stuff: 'hey',
|
|
902
|
-
data: { other: 'thing' },
|
|
903
|
-
};
|
|
904
|
-
t.addRequestData(item, options, this.callback);
|
|
905
|
-
},
|
|
906
|
-
'should not error': function (err, item) {
|
|
907
|
-
assert.ifError(err);
|
|
908
|
-
},
|
|
909
|
-
'should have a request object inside data': function (
|
|
910
|
-
err,
|
|
911
|
-
item,
|
|
912
|
-
) {
|
|
913
|
-
assert.ok(item.data.request);
|
|
914
|
-
},
|
|
915
|
-
},
|
|
916
|
-
},
|
|
917
|
-
},
|
|
918
|
-
},
|
|
919
|
-
'with custom addRequestData': {
|
|
920
|
-
'with scrub fields': {
|
|
921
|
-
topic: function () {
|
|
922
|
-
var customFn = function (i, r) {
|
|
923
|
-
assert.equal(i.stuff, undefined);
|
|
924
|
-
assert.equal(i.other, 'thing');
|
|
925
|
-
i.myRequest = { body: r.body.token };
|
|
926
|
-
};
|
|
927
|
-
return {
|
|
928
|
-
captureIp: true,
|
|
929
|
-
addRequestData: customFn,
|
|
930
|
-
scrubFields: [
|
|
931
|
-
'passwd',
|
|
932
|
-
'access_token',
|
|
933
|
-
'token',
|
|
934
|
-
'request.cookie',
|
|
935
|
-
],
|
|
936
|
-
};
|
|
937
|
-
},
|
|
938
|
-
item: {
|
|
939
|
-
'with a request': {
|
|
940
|
-
topic: function (options) {
|
|
941
|
-
var item = {
|
|
942
|
-
request: {
|
|
943
|
-
headers: {
|
|
944
|
-
host: 'example.com',
|
|
945
|
-
'x-auth-token': '12345',
|
|
946
|
-
},
|
|
947
|
-
protocol: 'https',
|
|
948
|
-
url: '/some/endpoint',
|
|
949
|
-
ip: '192.192.192.192',
|
|
950
|
-
method: 'GET',
|
|
951
|
-
body: {
|
|
952
|
-
token: 'abc123',
|
|
953
|
-
something: 'else',
|
|
954
|
-
},
|
|
955
|
-
user: {
|
|
956
|
-
id: 42,
|
|
957
|
-
email: 'fake@example.com',
|
|
958
|
-
},
|
|
959
|
-
},
|
|
960
|
-
stuff: 'hey',
|
|
961
|
-
data: { other: 'thing' },
|
|
962
|
-
};
|
|
963
|
-
t.addRequestData(item, options, this.callback);
|
|
964
|
-
},
|
|
965
|
-
'should not error': function (err, item) {
|
|
966
|
-
assert.ifError(err);
|
|
967
|
-
},
|
|
968
|
-
'should do what the function does': function (err, item) {
|
|
969
|
-
assert.equal(item.data.request, undefined);
|
|
970
|
-
assert.equal(item.data.myRequest.body, 'abc123');
|
|
971
|
-
},
|
|
972
|
-
},
|
|
973
|
-
},
|
|
974
|
-
},
|
|
975
|
-
},
|
|
976
|
-
},
|
|
977
|
-
},
|
|
978
|
-
})
|
|
979
|
-
.addBatch({
|
|
980
|
-
scrubPayload: {
|
|
981
|
-
options: {
|
|
982
|
-
'without scrub fields': {
|
|
983
|
-
topic: function () {
|
|
984
|
-
return rollbar.defaultOptions;
|
|
985
|
-
},
|
|
986
|
-
item: {
|
|
987
|
-
topic: function (options) {
|
|
988
|
-
var item = {
|
|
989
|
-
data: {
|
|
990
|
-
body: {
|
|
991
|
-
message: 'hey',
|
|
992
|
-
password: '123',
|
|
993
|
-
secret: { stuff: 'here' },
|
|
994
|
-
},
|
|
995
|
-
},
|
|
996
|
-
};
|
|
997
|
-
t.scrubPayload(item, options, this.callback);
|
|
998
|
-
},
|
|
999
|
-
'should not error': function (err, item) {
|
|
1000
|
-
assert.ifError(err);
|
|
1001
|
-
},
|
|
1002
|
-
'should not scrub okay keys': function (err, item) {
|
|
1003
|
-
assert.equal(item.data.body.message, 'hey');
|
|
1004
|
-
},
|
|
1005
|
-
'should scrub key/value based on defaults': function (err, item) {
|
|
1006
|
-
assert.matches(item.data.body.password, /\*+/);
|
|
1007
|
-
assert.matches(item.data.body.secret, /\*+/);
|
|
1008
|
-
},
|
|
1009
|
-
},
|
|
1010
|
-
},
|
|
1011
|
-
'with scrub fields': {
|
|
1012
|
-
topic: function () {
|
|
1013
|
-
return {
|
|
1014
|
-
captureIp: true,
|
|
1015
|
-
scrubHeaders: ['x-auth-token'],
|
|
1016
|
-
scrubFields: [
|
|
1017
|
-
'passwd',
|
|
1018
|
-
'access_token',
|
|
1019
|
-
'request.cookie',
|
|
1020
|
-
'sauce',
|
|
1021
|
-
],
|
|
1022
|
-
scrubRequestBody: true,
|
|
1023
|
-
};
|
|
1024
|
-
},
|
|
1025
|
-
item: {
|
|
1026
|
-
'with a request': {
|
|
1027
|
-
topic: function (options) {
|
|
1028
|
-
var item = {
|
|
1029
|
-
request: {
|
|
1030
|
-
headers: {
|
|
1031
|
-
host: 'example.com',
|
|
1032
|
-
'x-auth-token': '12345',
|
|
1033
|
-
},
|
|
1034
|
-
protocol: 'https',
|
|
1035
|
-
url: '/some/endpoint',
|
|
1036
|
-
ip: '192.192.192.192',
|
|
1037
|
-
method: 'GET',
|
|
1038
|
-
body: {
|
|
1039
|
-
token: 'abc123',
|
|
1040
|
-
something: 'else',
|
|
1041
|
-
},
|
|
1042
|
-
user: {
|
|
1043
|
-
id: 42,
|
|
1044
|
-
email: 'fake@example.com',
|
|
1045
|
-
},
|
|
1046
|
-
},
|
|
1047
|
-
stuff: 'hey',
|
|
1048
|
-
data: {
|
|
1049
|
-
other: 'thing',
|
|
1050
|
-
sauce: 'secrets',
|
|
1051
|
-
someParams: 'foo=okay&passwd=iamhere',
|
|
1052
|
-
},
|
|
1053
|
-
};
|
|
1054
|
-
t.addRequestData(
|
|
1055
|
-
item,
|
|
1056
|
-
options,
|
|
1057
|
-
function (e, i) {
|
|
1058
|
-
if (e) {
|
|
1059
|
-
this.callback(e);
|
|
1060
|
-
return;
|
|
1061
|
-
}
|
|
1062
|
-
t.scrubPayload(i, options, this.callback);
|
|
1063
|
-
}.bind(this),
|
|
1064
|
-
);
|
|
1065
|
-
},
|
|
1066
|
-
'should not error': function (err, item) {
|
|
1067
|
-
assert.ifError(err);
|
|
1068
|
-
},
|
|
1069
|
-
'should have a request object inside data': function (err, item) {
|
|
1070
|
-
assert.ok(item.data.request);
|
|
1071
|
-
},
|
|
1072
|
-
'should scrub based on the options': function (err, item) {
|
|
1073
|
-
var r = item.data.request;
|
|
1074
|
-
assert.equal(r.GET.token, 'abc123');
|
|
1075
|
-
assert.match(r.headers['x-auth-token'], /\*+/);
|
|
1076
|
-
assert.equal(r.headers['host'], 'example.com');
|
|
1077
|
-
assert.match(item.data.sauce, /\*+/);
|
|
1078
|
-
assert.equal(item.data.other, 'thing');
|
|
1079
|
-
assert.match(item.data.someParams, /foo=okay&passwd=\*+/);
|
|
1080
|
-
},
|
|
1081
|
-
},
|
|
1082
|
-
'with a json request body': {
|
|
1083
|
-
topic: function (options) {
|
|
1084
|
-
var requestBody = JSON.stringify({
|
|
1085
|
-
token: 'abc123',
|
|
1086
|
-
something: 'else',
|
|
1087
|
-
passwd: '123456',
|
|
1088
|
-
});
|
|
1089
|
-
var item = {
|
|
1090
|
-
request: {
|
|
1091
|
-
headers: {
|
|
1092
|
-
host: 'example.com',
|
|
1093
|
-
'content-type': 'application/json',
|
|
1094
|
-
'x-auth-token': '12345',
|
|
1095
|
-
},
|
|
1096
|
-
protocol: 'https',
|
|
1097
|
-
url: '/some/endpoint',
|
|
1098
|
-
ip: '192.192.192.192',
|
|
1099
|
-
method: 'GET',
|
|
1100
|
-
body: requestBody,
|
|
1101
|
-
user: {
|
|
1102
|
-
id: 42,
|
|
1103
|
-
email: 'fake@example.com',
|
|
1104
|
-
},
|
|
1105
|
-
},
|
|
1106
|
-
stuff: 'hey',
|
|
1107
|
-
data: {
|
|
1108
|
-
other: 'thing',
|
|
1109
|
-
sauce: 'secrets',
|
|
1110
|
-
someParams: 'foo=okay&passwd=iamhere',
|
|
1111
|
-
},
|
|
1112
|
-
};
|
|
1113
|
-
t.addRequestData(
|
|
1114
|
-
item,
|
|
1115
|
-
options,
|
|
1116
|
-
function (e, i) {
|
|
1117
|
-
if (e) {
|
|
1118
|
-
this.callback(e);
|
|
1119
|
-
return;
|
|
1120
|
-
}
|
|
1121
|
-
t.scrubPayload(i, options, this.callback);
|
|
1122
|
-
}.bind(this),
|
|
1123
|
-
);
|
|
1124
|
-
},
|
|
1125
|
-
'should not error': function (err, item) {
|
|
1126
|
-
assert.ifError(err);
|
|
1127
|
-
},
|
|
1128
|
-
'should have a request object inside data': function (err, item) {
|
|
1129
|
-
assert.ok(item.data.request);
|
|
1130
|
-
},
|
|
1131
|
-
'should scrub based on the options': function (err, item) {
|
|
1132
|
-
var r = item.data.request;
|
|
1133
|
-
assert.match(r.headers['x-auth-token'], /\*+/);
|
|
1134
|
-
assert.equal(r.headers['host'], 'example.com');
|
|
1135
|
-
assert.match(item.data.sauce, /\*+/);
|
|
1136
|
-
assert.equal(item.data.other, 'thing');
|
|
1137
|
-
assert.match(item.data.someParams, /foo=okay&passwd=\*+/);
|
|
1138
|
-
|
|
1139
|
-
var requestBody = JSON.parse(item.data.request.body);
|
|
1140
|
-
assert.match(requestBody.passwd, /\*+/);
|
|
1141
|
-
},
|
|
1142
|
-
},
|
|
1143
|
-
'with a bad json request body': {
|
|
1144
|
-
topic: function (options) {
|
|
1145
|
-
var requestBody = 'not valid json';
|
|
1146
|
-
var item = {
|
|
1147
|
-
request: {
|
|
1148
|
-
headers: {
|
|
1149
|
-
'content-type': 'application/json',
|
|
1150
|
-
},
|
|
1151
|
-
protocol: 'https',
|
|
1152
|
-
url: '/some/endpoint',
|
|
1153
|
-
ip: '192.192.192.192',
|
|
1154
|
-
method: 'GET',
|
|
1155
|
-
body: requestBody,
|
|
1156
|
-
},
|
|
1157
|
-
};
|
|
1158
|
-
t.addRequestData(
|
|
1159
|
-
item,
|
|
1160
|
-
options,
|
|
1161
|
-
function (e, i) {
|
|
1162
|
-
if (e) {
|
|
1163
|
-
this.callback(e);
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
t.scrubPayload(i, options, this.callback);
|
|
1167
|
-
}.bind(this),
|
|
1168
|
-
);
|
|
1169
|
-
},
|
|
1170
|
-
'should not error': function (err, item) {
|
|
1171
|
-
assert.ifError(err);
|
|
1172
|
-
},
|
|
1173
|
-
'should have a request object inside data': function (err, item) {
|
|
1174
|
-
assert.ok(item.data.request);
|
|
1175
|
-
},
|
|
1176
|
-
'should delete the body and add a diagnostic error': function (
|
|
1177
|
-
err,
|
|
1178
|
-
item,
|
|
1179
|
-
) {
|
|
1180
|
-
var requestBody = JSON.parse(item.data.request.body);
|
|
1181
|
-
assert.equal(requestBody, null);
|
|
1182
|
-
assert.match(
|
|
1183
|
-
item.data.request.error,
|
|
1184
|
-
/request.body parse failed/,
|
|
1185
|
-
);
|
|
1186
|
-
},
|
|
1187
|
-
},
|
|
1188
|
-
},
|
|
1189
|
-
},
|
|
1190
|
-
},
|
|
1191
|
-
},
|
|
1192
|
-
})
|
|
1193
|
-
.export(module, { error: false });
|