@contrast/route-coverage 1.35.0 → 1.35.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/LICENSE +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/install/express/express4.js +1 -1
- package/lib/install/express/express5.js +1 -1
- package/lib/install/express/index.js +1 -1
- package/lib/install/fastify.js +1 -1
- package/lib/install/graphql.js +1 -1
- package/lib/install/hapi.js +1 -1
- package/lib/install/http.js +1 -1
- package/lib/install/koa.js +1 -1
- package/lib/install/restify.js +1 -1
- package/lib/normalized-url-mapper.js +1 -1
- package/lib/utils/methods.js +1 -1
- package/lib/utils/route-info.js +1 -1
- package/package.json +11 -8
- package/lib/index.test.js +0 -136
- package/lib/install/express/express4.test.js +0 -418
- package/lib/install/express/express5.test.js +0 -813
- package/lib/install/fastify.test.js +0 -218
- package/lib/install/graphql.test.js +0 -175
- package/lib/install/hapi.test.js +0 -127
- package/lib/install/koa.test.js +0 -152
- package/lib/install/restify.test.js +0 -92
- package/lib/normalized-url-mapper.test.js +0 -50
package/LICENSE
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/install/fastify.js
CHANGED
package/lib/install/graphql.js
CHANGED
package/lib/install/hapi.js
CHANGED
package/lib/install/http.js
CHANGED
package/lib/install/koa.js
CHANGED
package/lib/install/restify.js
CHANGED
package/lib/utils/methods.js
CHANGED
package/lib/utils/route-info.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/route-coverage",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.2",
|
|
4
4
|
"description": "Handles route discovery and observation",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
7
7
|
"files": [
|
|
8
|
-
"lib/"
|
|
8
|
+
"lib/",
|
|
9
|
+
"!*.test.*",
|
|
10
|
+
"!tsconfig.*",
|
|
11
|
+
"!*.map"
|
|
9
12
|
],
|
|
10
13
|
"main": "lib/index.js",
|
|
11
14
|
"types": "lib/index.d.ts",
|
|
@@ -17,13 +20,13 @@
|
|
|
17
20
|
"test": "../scripts/test.sh"
|
|
18
21
|
},
|
|
19
22
|
"dependencies": {
|
|
20
|
-
"@contrast/common": "1.29.
|
|
21
|
-
"@contrast/config": "1.40.
|
|
22
|
-
"@contrast/dep-hooks": "1.14.
|
|
23
|
+
"@contrast/common": "1.29.1",
|
|
24
|
+
"@contrast/config": "1.40.2",
|
|
25
|
+
"@contrast/dep-hooks": "1.14.2",
|
|
23
26
|
"@contrast/fn-inspect": "^4.3.0",
|
|
24
|
-
"@contrast/logger": "1.18.
|
|
25
|
-
"@contrast/patcher": "1.17.
|
|
26
|
-
"@contrast/scopes": "1.15.
|
|
27
|
+
"@contrast/logger": "1.18.2",
|
|
28
|
+
"@contrast/patcher": "1.17.2",
|
|
29
|
+
"@contrast/scopes": "1.15.2",
|
|
27
30
|
"semver": "^7.6.0",
|
|
28
31
|
"path-to-regexp": "^8.2.0"
|
|
29
32
|
}
|
package/lib/index.test.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const proxyquire = require('proxyquire');
|
|
6
|
-
const { Event } = require('@contrast/common');
|
|
7
|
-
const mocks = require('@contrast/test/mocks');
|
|
8
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
9
|
-
const { installsComponents } = require('@contrast/test/utils');
|
|
10
|
-
|
|
11
|
-
const MODULES = ['express', 'fastify', 'hapi', 'koa'];
|
|
12
|
-
|
|
13
|
-
describe('route coverage', function () {
|
|
14
|
-
let core, simulateRequestScope, routeCoverage, clock;
|
|
15
|
-
|
|
16
|
-
beforeEach(function () {
|
|
17
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
18
|
-
|
|
19
|
-
clock = sinon.useFakeTimers();
|
|
20
|
-
sinon.spy(core.messages, 'emit');
|
|
21
|
-
|
|
22
|
-
const moduleMock = (moduleName) => (deps) => {
|
|
23
|
-
deps.routeCoverage[moduleName] = mocks.installable();
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
routeCoverage = proxyquire('.', {
|
|
27
|
-
'./install/express': moduleMock('express'),
|
|
28
|
-
'./install/fastify': moduleMock('fastify'),
|
|
29
|
-
'./install/hapi': moduleMock('hapi'),
|
|
30
|
-
'./install/koa': moduleMock('koa'),
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('installs its components', function () {
|
|
35
|
-
routeCoverage(core).install();
|
|
36
|
-
installsComponents(core.routeCoverage, MODULES);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('does not install when not enabled', function () {
|
|
40
|
-
core.config.agent.route_coverage.enable = false;
|
|
41
|
-
routeCoverage(core);
|
|
42
|
-
expect(core).not.to.have.property('routeCoverage');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('.discoveryFinished()', function () {
|
|
46
|
-
beforeEach(function () {
|
|
47
|
-
routeCoverage(core).install();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('emits an event when discovery is finished', function () {
|
|
51
|
-
const eventA = { signature: 'url.get', url: 'url', method: 'get' };
|
|
52
|
-
const eventB = { signature: 'url.post', url: 'url', method: 'post' };
|
|
53
|
-
core.routeCoverage.discover(eventA);
|
|
54
|
-
core.routeCoverage.discover(eventA); // check that we dedupe discovery.
|
|
55
|
-
core.routeCoverage.discover(eventB);
|
|
56
|
-
core.routeCoverage.discoveryFinished();
|
|
57
|
-
|
|
58
|
-
expect(core.messages.emit).to.have.been.calledWith(
|
|
59
|
-
Event.ROUTE_COVERAGE_DISCOVERY_FINISHED,
|
|
60
|
-
[eventA, eventB],
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('queues new events after initial discovery is finished', function () {
|
|
65
|
-
const eventA = { signature: 'url.get', url: 'url', method: 'get' };
|
|
66
|
-
core.routeCoverage.discover(eventA);
|
|
67
|
-
core.routeCoverage.discoveryFinished();
|
|
68
|
-
expect(core.messages.emit).to.have.been.calledWith(
|
|
69
|
-
Event.ROUTE_COVERAGE_DISCOVERY_FINISHED,
|
|
70
|
-
[eventA],
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const eventB = { signature: 'url.post', url: 'url', method: 'post' };
|
|
74
|
-
core.routeCoverage.discover(eventA); // check that we dedupe routes discoverd on startup
|
|
75
|
-
core.routeCoverage.discover(eventB);
|
|
76
|
-
core.routeCoverage.discover(eventB); // check that we dedupe routes defined lazily
|
|
77
|
-
clock.tick(10000); //queuingFinished
|
|
78
|
-
|
|
79
|
-
expect(core.messages.emit).to.have.been.calledWith(
|
|
80
|
-
Event.ROUTE_COVERAGE_DISCOVERY_FINISHED,
|
|
81
|
-
[eventB],
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe('.observe()', function () {
|
|
87
|
-
beforeEach(function () {
|
|
88
|
-
routeCoverage(core).install();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('logs debug messages when a route is missing on observation', function () {
|
|
92
|
-
const info = { url: 'url', method: 'get' };
|
|
93
|
-
core.routeCoverage.observe(info);
|
|
94
|
-
expect(core.logger.debug).to.have.been.calledOnceWithExactly(
|
|
95
|
-
info,
|
|
96
|
-
'unable to observe undiscovered route',
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('emits an event on route observation', function () {
|
|
101
|
-
const event = {
|
|
102
|
-
signature: 'hello',
|
|
103
|
-
url: 'url',
|
|
104
|
-
method: 'get',
|
|
105
|
-
sourceInfo: undefined
|
|
106
|
-
};
|
|
107
|
-
core.routeCoverage.discover(event);
|
|
108
|
-
core.routeCoverage.observe(event);
|
|
109
|
-
|
|
110
|
-
expect(core.messages.emit).to.have.been.calledWith(
|
|
111
|
-
Event.ROUTE_COVERAGE_OBSERVATION,
|
|
112
|
-
event,
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('emits an event on route observation and appends sourceInfo when in request scope', function () {
|
|
117
|
-
const event = {
|
|
118
|
-
signature: 'hello',
|
|
119
|
-
url: 'url',
|
|
120
|
-
method: 'get',
|
|
121
|
-
};
|
|
122
|
-
core.routeCoverage.discover(event);
|
|
123
|
-
|
|
124
|
-
simulateRequestScope(() => {
|
|
125
|
-
core.routeCoverage.observe(event);
|
|
126
|
-
const { sourceInfo, route } = core.scopes.sources.getStore();
|
|
127
|
-
expect(sourceInfo).to.be.ok;
|
|
128
|
-
expect(route).to.eql({ method: 'get', signature: 'hello', url: 'url' });
|
|
129
|
-
expect(core.messages.emit).to.have.been.calledWith(
|
|
130
|
-
Event.ROUTE_COVERAGE_OBSERVATION,
|
|
131
|
-
sinon.match({ ...event, sourceInfo })
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|