@contrast/route-coverage 1.11.1 → 1.11.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/lib/index.js +1 -0
- package/lib/install/express.js +45 -65
- package/lib/install/fastify.js +1 -3
- package/lib/install/http.js +44 -0
- package/lib/install/koa.js +25 -37
- package/package.json +1 -1
package/lib/index.js
CHANGED
package/lib/install/express.js
CHANGED
|
@@ -117,84 +117,64 @@ module.exports = function init(core) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
core.routeCoverage.express = {
|
|
120
|
+
return core.routeCoverage.express = {
|
|
121
121
|
install() {
|
|
122
|
-
depHooks.resolve(
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
depHooks.resolve({ name: 'express' }, (express) => {
|
|
123
|
+
patcher.patch(express.Router, 'use', {
|
|
124
|
+
name: 'express.Router.use',
|
|
125
|
+
patchType,
|
|
126
|
+
post({ args, result }) {
|
|
127
|
+
const [prefix, router] = args;
|
|
128
|
+
if (typeof prefix === 'string' && prefix !== '/') {
|
|
129
|
+
updateRoutes(prefix, router, result);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
125
133
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
patcher.patch(express.application, 'use', {
|
|
135
|
+
name: 'express.application.use',
|
|
136
|
+
patchType,
|
|
137
|
+
post({ args }) {
|
|
138
|
+
const idx = args.length;
|
|
139
|
+
const router = args[idx - 1];
|
|
140
|
+
const routes = routers.get(router);
|
|
141
|
+
if (routes) {
|
|
142
|
+
routes.forEach((route) => {
|
|
143
|
+
discoverRoute(route);
|
|
144
|
+
});
|
|
134
145
|
}
|
|
135
|
-
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
136
148
|
|
|
137
|
-
|
|
138
|
-
|
|
149
|
+
METHODS.forEach((method) => {
|
|
150
|
+
patcher.patch(express.application, method, {
|
|
151
|
+
name: `express.application.${method}`,
|
|
139
152
|
patchType,
|
|
140
|
-
post({ args }) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
discoverRoute(route);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
153
|
+
post({ args, result }) {
|
|
154
|
+
const [url, fn] = args;
|
|
155
|
+
if (!url || !fn) return;
|
|
156
|
+
const route = createRoute(formatUrl(url), method);
|
|
157
|
+
instrumentRoute(result?._router, route);
|
|
158
|
+
discoverRoute(route);
|
|
149
159
|
}
|
|
150
160
|
});
|
|
151
161
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
name: `express.application.${method}`,
|
|
155
|
-
patchType,
|
|
156
|
-
post({ args, result }) {
|
|
157
|
-
const [url, fn] = args;
|
|
158
|
-
if (!url || !fn) return;
|
|
159
|
-
const route = createRoute(formatUrl(url), method);
|
|
160
|
-
instrumentRoute(result?._router, route);
|
|
161
|
-
discoverRoute(route);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
patcher.patch(express.Router, method, {
|
|
166
|
-
name: `express.Router.${method}`,
|
|
167
|
-
patchType,
|
|
168
|
-
post({ args, obj: router }) {
|
|
169
|
-
const [url, fn] = args;
|
|
170
|
-
if (!url || !fn) return;
|
|
171
|
-
const route = createRoute(formatUrl(url), method);
|
|
172
|
-
const routes = routers.get(router) || [];
|
|
173
|
-
|
|
174
|
-
instrumentRoute(router, route);
|
|
175
|
-
routes.push(route);
|
|
176
|
-
routers.set(router, routes);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
['http', 'https', 'spdy'].forEach((name) => {
|
|
184
|
-
depHooks.resolve({ name }, (module) => {
|
|
185
|
-
if (!module.Server?.prototype) return;
|
|
186
|
-
|
|
187
|
-
patcher.patch(module.Server.prototype, 'listen', {
|
|
188
|
-
name: `${name}.Server.prototype.listen`,
|
|
162
|
+
patcher.patch(express.Router, method, {
|
|
163
|
+
name: `express.Router.${method}`,
|
|
189
164
|
patchType,
|
|
190
|
-
post() {
|
|
191
|
-
|
|
165
|
+
post({ args, obj: router }) {
|
|
166
|
+
const [url, fn] = args;
|
|
167
|
+
if (!url || !fn) return;
|
|
168
|
+
const route = createRoute(formatUrl(url), method);
|
|
169
|
+
const routes = routers.get(router) || [];
|
|
170
|
+
|
|
171
|
+
instrumentRoute(router, route);
|
|
172
|
+
routes.push(route);
|
|
173
|
+
routers.set(router, routes);
|
|
192
174
|
}
|
|
193
175
|
});
|
|
194
176
|
});
|
|
195
177
|
});
|
|
196
178
|
}
|
|
197
179
|
};
|
|
198
|
-
|
|
199
|
-
return core.routeCoverage.express;
|
|
200
180
|
};
|
package/lib/install/fastify.js
CHANGED
|
@@ -82,7 +82,7 @@ module.exports = function init(core) {
|
|
|
82
82
|
routeCoverage.observe({ method, url });
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
core.routeCoverage.fastify = {
|
|
85
|
+
return core.routeCoverage.fastify = {
|
|
86
86
|
install() {
|
|
87
87
|
depHooks.resolve(
|
|
88
88
|
{ name: 'fastify', version: '>=3.0.0' },
|
|
@@ -105,6 +105,4 @@ module.exports = function init(core) {
|
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
|
-
|
|
109
|
-
return core.routeCoverage.fastify;
|
|
110
108
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
module.exports = function init(core) {
|
|
18
|
+
const { depHooks, patcher, routeCoverage } = core;
|
|
19
|
+
|
|
20
|
+
let handled;
|
|
21
|
+
|
|
22
|
+
return core.routeCoverage.http = {
|
|
23
|
+
install() {
|
|
24
|
+
['http', 'https', 'spdy'].forEach((name) => {
|
|
25
|
+
depHooks.resolve({ name }, (_export) => {
|
|
26
|
+
if (!_export?.Server?.prototype) return;
|
|
27
|
+
|
|
28
|
+
patcher.patch(_export.Server.prototype, 'listen', {
|
|
29
|
+
name: `${name}.Server.prototype.listen`,
|
|
30
|
+
patchType: 'route-coverage',
|
|
31
|
+
post(data) {
|
|
32
|
+
data.result?.on('listening', () => {
|
|
33
|
+
if (!handled) {
|
|
34
|
+
handled = true;
|
|
35
|
+
routeCoverage.discoveryFinished();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
package/lib/install/koa.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const { createSignature, patchType } = require('./../utils/route-info');
|
|
18
17
|
const { toLowerCase } = require('@contrast/common');
|
|
18
|
+
const { createSignature, patchType } = require('./../utils/route-info');
|
|
19
19
|
|
|
20
20
|
module.exports = function init(core) {
|
|
21
21
|
const { patcher, depHooks, routeCoverage } = core;
|
|
@@ -37,46 +37,34 @@ module.exports = function init(core) {
|
|
|
37
37
|
await next();
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const [path, methods] = args;
|
|
46
|
-
if (!path || !methods || Array.isArray(path)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
40
|
+
return core.routeCoverage.koa = {
|
|
41
|
+
install() {
|
|
42
|
+
['@koa/router', 'koa-router'].forEach((name) => {
|
|
43
|
+
depHooks.resolve({ name }, (_export) => {
|
|
44
|
+
if (!_export?.prototype?.register) return;
|
|
49
45
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
patcher.patch(_export.prototype, 'register', {
|
|
47
|
+
name: 'koaRouter.prototype',
|
|
48
|
+
patchType,
|
|
49
|
+
post: ({ args, result: layer }) => {
|
|
50
|
+
const [path, methods] = args;
|
|
51
|
+
if (!path || !methods || Array.isArray(path)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
if (methods.length === 0) {
|
|
56
|
+
emitRouteCoverage(path, 'use');
|
|
57
|
+
} else {
|
|
58
|
+
methods.forEach((method) => {
|
|
59
|
+
emitRouteCoverage(path, toLowerCase(method || ''));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
routeCoverage.discoveryFinished();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
core.routeCoverage.koa = {
|
|
72
|
-
install() {
|
|
73
|
-
['@koa/router', 'koa-router'].forEach((name) => {
|
|
74
|
-
depHooks.resolve(
|
|
75
|
-
{ name }, registerRouteHandler.bind(this)
|
|
76
|
-
);
|
|
63
|
+
layer.stack.unshift(routeObservationPathClosure({ path }).bind(this));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
77
67
|
});
|
|
78
68
|
}
|
|
79
69
|
};
|
|
80
|
-
|
|
81
|
-
return core.routeCoverage.koa;
|
|
82
70
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/route-coverage",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.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)",
|