-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from bugsnag/ip-option
Add option to prevent IP collection
- Loading branch information
Showing
8 changed files
with
178 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Prevent collection of user IPs | ||
*/ | ||
module.exports = { | ||
init: (client) => { | ||
if (client.config.collectUserIp) return | ||
client.config.beforeSend.push(report => { | ||
report.user = { id: '[NOT COLLECTED]', ...report.user } | ||
report.request = { clientIp: '[NOT COLLECTED]', ...report.request } | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// magical jasmine globals | ||
const { describe, it, expect } = global | ||
|
||
const plugin = require('../ip') | ||
|
||
const Client = require('../../../base/client') | ||
const schema = { ...require('../../../base/config').schema, ...require('../../config') } | ||
const VALID_NOTIFIER = { name: 't', version: '0', url: 'http://' } | ||
|
||
describe('plugin: ip', () => { | ||
it('does nothing when collectUserIp=true', () => { | ||
const client = new Client(VALID_NOTIFIER, schema) | ||
const payloads = [] | ||
client.configure({ apiKey: 'API_KEY_YEAH' }) | ||
client.use(plugin) | ||
|
||
client.transport({ sendReport: (logger, config, payload) => payloads.push(payload) }) | ||
client.notify(new Error('noooo'), { | ||
beforeSend: report => { report.request = { 'some': 'detail' } } | ||
}) | ||
|
||
expect(payloads.length).toEqual(1) | ||
expect(payloads[0].events[0].request).toEqual({ 'some': 'detail' }) | ||
}) | ||
|
||
it('doesn’t overwrite an existing user id', () => { | ||
const client = new Client(VALID_NOTIFIER, schema) | ||
const payloads = [] | ||
client.configure({ apiKey: 'API_KEY_YEAH', collectUserIp: false }) | ||
client.use(plugin) | ||
|
||
client.user = { id: 'foobar' } | ||
|
||
client.transport({ sendReport: (logger, config, payload) => payloads.push(payload) }) | ||
client.notify(new Error('noooo')) | ||
|
||
expect(payloads.length).toEqual(1) | ||
expect(payloads[0].events[0].user).toEqual({ id: 'foobar' }) | ||
expect(payloads[0].events[0].request).toEqual({ clientIp: '[NOT COLLECTED]' }) | ||
}) | ||
|
||
it('redacts user IP if none is provided', () => { | ||
const client = new Client(VALID_NOTIFIER, schema) | ||
const payloads = [] | ||
client.configure({ apiKey: 'API_KEY_YEAH', collectUserIp: false }) | ||
client.use(plugin) | ||
|
||
client.transport({ sendReport: (logger, config, payload) => payloads.push(payload) }) | ||
client.notify(new Error('noooo')) | ||
|
||
expect(payloads.length).toEqual(1) | ||
expect(payloads[0].events[0].user).toEqual({ id: '[NOT COLLECTED]' }) | ||
expect(payloads[0].events[0].request).toEqual({ clientIp: '[NOT COLLECTED]' }) | ||
}) | ||
}) |
Oops, something went wrong.