@contrast/instrumentation 1.11.0 → 1.13.0

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.
Files changed (2) hide show
  1. package/lib/index.test.js +44 -0
  2. package/package.json +2 -2
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const sinon = require('sinon');
4
+ const { expect } = require('chai');
5
+ const proxyquire = require('proxyquire');
6
+ const mocks = require('@contrast/test/mocks');
7
+
8
+ describe('instrumentation', function () {
9
+ let core, instrumentation, mongodb, mongodbHook;
10
+
11
+ beforeEach(function () {
12
+ core = mocks.core();
13
+ core.logger = mocks.logger();
14
+ core.depHooks = mocks.depHooks();
15
+ core.protect = mocks.protect();
16
+ core.patcher = require('@contrast/patcher')(core);
17
+ core.scopes = require('@contrast/scopes')(core);
18
+ mongodbHook = sinon.stub();
19
+ mongodb = () => ({
20
+ 'mongodb': mongodbHook
21
+ });
22
+ instrumentation = proxyquire('.', {
23
+ './mongodb': mongodb
24
+ });
25
+ core.instrumentation = instrumentation(core);
26
+ });
27
+
28
+
29
+ it('instruments existent hook', function () {
30
+ core.instrumentation.instrument({
31
+ moduleName: 'mongodb'
32
+ });
33
+ expect(mongodbHook).to.have.been.calledWith({ moduleName: 'mongodb' });
34
+ });
35
+
36
+ it('does not instrument non-existent hook', function () {
37
+ core.instrumentation.instrument({
38
+ moduleName: 'foo'
39
+ });
40
+ expect(mongodbHook).not.to.have.been.calledWith({ moduleName: 'foo' });
41
+ expect(core.logger.error).to.have.been.calledWith('Unable to instrument non-existent hook: %s', 'foo');
42
+ });
43
+
44
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/instrumentation",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "description": "Shared hooks and patches between Protect and Assess components",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,6 +17,6 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.22.0"
20
+ "@contrast/common": "1.24.0"
21
21
  }
22
22
  }