@contrast/route-coverage 1.25.0 → 1.27.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.
- package/lib/index.test.js +0 -15
- package/lib/install/express.js +22 -4
- package/lib/install/fastify.js +2 -2
- package/lib/install/hapi.js +1 -1
- package/lib/install/koa.js +2 -2
- package/lib/install/restify.js +2 -2
- package/lib/utils/methods.js +0 -1
- package/package.json +8 -7
package/lib/index.test.js
CHANGED
|
@@ -132,20 +132,5 @@ describe('route coverage', function () {
|
|
|
132
132
|
);
|
|
133
133
|
});
|
|
134
134
|
});
|
|
135
|
-
|
|
136
|
-
it('skip adding normalizedUrl if assess store does not exist', function () {
|
|
137
|
-
const event = {
|
|
138
|
-
signature: 'hello',
|
|
139
|
-
url: 'url',
|
|
140
|
-
method: 'get',
|
|
141
|
-
};
|
|
142
|
-
core.routeCoverage.discover(event);
|
|
143
|
-
|
|
144
|
-
simulateRequestScope(() => {
|
|
145
|
-
core.routeCoverage.observe({ url: 'url', method: 'get' });
|
|
146
|
-
const store = core.scopes.sources.getStore();
|
|
147
|
-
expect(store.assess).to.be.undefined;
|
|
148
|
-
}, {});
|
|
149
|
-
});
|
|
150
135
|
});
|
|
151
136
|
});
|
package/lib/install/express.js
CHANGED
|
@@ -28,7 +28,7 @@ const METHODS = [
|
|
|
28
28
|
|
|
29
29
|
const fnInspect = require('@contrast/fn-inspect');
|
|
30
30
|
const { createSignature, patchType } = require('../utils/route-info');
|
|
31
|
-
const { ArrayPrototypeJoin, StringPrototypeToLowerCase,
|
|
31
|
+
const { isString, primordials: { ArrayPrototypeJoin, StringPrototypeToLowerCase, StringPrototypeReplace, StringPrototypeReplaceAll, StringPrototypeSplit, StringPrototypeSlice } } = require('@contrast/common');
|
|
32
32
|
|
|
33
33
|
// Spec: https://contrast.atlassian.net/wiki/spaces/NOD/pages/3454861621/Node.js+Agent+Route+Signatures#Express
|
|
34
34
|
module.exports = function init(core) {
|
|
@@ -39,17 +39,35 @@ module.exports = function init(core) {
|
|
|
39
39
|
const isRoute = (layer) => !!layer.route;
|
|
40
40
|
const isRouter = (layer) => layer.name && StringPrototypeToLowerCase.call(layer.name) === 'router';
|
|
41
41
|
const isValidPath = (path) => isString(path) || Array.isArray(path) || path instanceof RegExp;
|
|
42
|
-
const regExpToPath = (regex) => regex?.source?.split('/?')[0].replaceAll('\\', '').replace('^', '');
|
|
43
|
-
const format = (url) => Array.isArray(url) ? `/[${ArrayPrototypeJoin.call(url)}]` : url instanceof RegExp ? `/{${url.toString().slice(1, -1)}}` : url;
|
|
44
42
|
const getHandleMethod = (layer) => fnInspect.funcInfo(layer.__handle)?.file.includes('express-async-errors') ? '__handle' : 'handle';
|
|
45
43
|
const getLastLayer = (router) => router?.stack[router.stack.length - 1];
|
|
46
44
|
|
|
45
|
+
function regExpToPath(regex) {
|
|
46
|
+
if (regex.source) {
|
|
47
|
+
let [path] = StringPrototypeSplit.call(regex?.source, '/?');
|
|
48
|
+
path = StringPrototypeReplaceAll.call(path, '\\', '');
|
|
49
|
+
path = StringPrototypeReplace.call(path, '^', '');
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function format(url) {
|
|
55
|
+
if (Array.isArray(url)) {
|
|
56
|
+
return `/[${ArrayPrototypeJoin.call(url)}]`;
|
|
57
|
+
} else if (url instanceof RegExp) {
|
|
58
|
+
return `/{${StringPrototypeSlice.call(url.toString(), 1, -1)}}`;
|
|
59
|
+
} else {
|
|
60
|
+
return url;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
47
64
|
function parseRoute(route) {
|
|
48
65
|
const { path } = route;
|
|
49
66
|
const method = route.methods._all ? 'all' : route.stack[0].method;
|
|
50
67
|
return { url: format(path), method };
|
|
51
68
|
}
|
|
52
69
|
|
|
70
|
+
|
|
53
71
|
function createRouteInfo(url, method, obj) {
|
|
54
72
|
return {
|
|
55
73
|
signature: createSignature(url, method, obj),
|
|
@@ -67,7 +85,7 @@ module.exports = function init(core) {
|
|
|
67
85
|
patchType,
|
|
68
86
|
post({ args }) {
|
|
69
87
|
const [req] = args;
|
|
70
|
-
const [url] = req.originalUrl
|
|
88
|
+
const [url] = StringPrototypeSplit.call(req.originalUrl, '?');
|
|
71
89
|
const { method } = req;
|
|
72
90
|
if (url && method) {
|
|
73
91
|
observe({ ...routeInfo, url, method: StringPrototypeToLowerCase.call(method) });
|
package/lib/install/fastify.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
17
|
const { getFastifyMethods } = require('../utils/methods');
|
|
18
|
-
const { StringPrototypeToLowerCase } = require('@contrast/common');
|
|
18
|
+
const { primordials: { StringPrototypeToLowerCase, StringPrototypeSplit } } = require('@contrast/common');
|
|
19
19
|
const { patchType } = require('./../utils/route-info');
|
|
20
20
|
|
|
21
21
|
// Spec: https://contrast.atlassian.net/wiki/spaces/NOD/pages/3454861621/Node.js+Agent+Route+Signatures#Fastify
|
|
@@ -56,7 +56,7 @@ module.exports = function init(core) {
|
|
|
56
56
|
const pre = ({ args }) => {
|
|
57
57
|
const [req] = args;
|
|
58
58
|
const method = StringPrototypeToLowerCase.call(req.raw?.method);
|
|
59
|
-
const [url] = req.url
|
|
59
|
+
const [url] = StringPrototypeSplit.call(req.url, /\?/);
|
|
60
60
|
routeCoverage.observe({ ...routeInfo, url, method });
|
|
61
61
|
};
|
|
62
62
|
|
package/lib/install/hapi.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const { StringPrototypeToLowerCase } = require('@contrast/common');
|
|
17
|
+
const { primordials: { StringPrototypeToLowerCase } } = require('@contrast/common');
|
|
18
18
|
const { patchType } = require('./../utils/route-info');
|
|
19
19
|
|
|
20
20
|
// Spec: https://contrast.atlassian.net/wiki/spaces/NOD/pages/3454861621/Node.js+Agent+Route+Signatures#Hapi
|
package/lib/install/koa.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
17
|
const { METHODS } = require('./../utils/methods');
|
|
18
|
-
const { StringPrototypeToLowerCase,
|
|
18
|
+
const { isString, primordials: { StringPrototypeToLowerCase, StringPrototypeSplit } } = require('@contrast/common');
|
|
19
19
|
const { createSignature, patchType } = require('./../utils/route-info');
|
|
20
20
|
|
|
21
21
|
// Spec: https://contrast.atlassian.net/wiki/spaces/NOD/pages/3454861621/Node.js+Agent+Route+Signatures#Koa
|
|
@@ -74,7 +74,7 @@ module.exports = function init(core) {
|
|
|
74
74
|
async function observationMiddleware(ctx, next) {
|
|
75
75
|
if (!ctx.request) return;
|
|
76
76
|
const { url: reqUrl, method } = ctx.request;
|
|
77
|
-
const [url] =
|
|
77
|
+
const [url] = StringPrototypeSplit.call(reqUrl, /\?/);
|
|
78
78
|
routeCoverage.observe({ ...routeInfo, url, method: StringPrototypeToLowerCase.call(method) });
|
|
79
79
|
await next();
|
|
80
80
|
}
|
package/lib/install/restify.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const { StringPrototypeToLowerCase,
|
|
17
|
+
const { isString, primordials: { StringPrototypeToLowerCase, StringPrototypeSplit } } = require('@contrast/common');
|
|
18
18
|
const { createSignature, patchType } = require('../utils/route-info');
|
|
19
19
|
|
|
20
20
|
// Spec: https://contrast.atlassian.net/wiki/spaces/NOD/pages/3454861621/Node.js+Agent+Route+Signatures#Restify
|
|
@@ -57,7 +57,7 @@ module.exports = function init(core) {
|
|
|
57
57
|
post({ args }) {
|
|
58
58
|
const [req] = args;
|
|
59
59
|
const { url: reqUrl, method } = req;
|
|
60
|
-
const [url] =
|
|
60
|
+
const [url] = StringPrototypeSplit.call(reqUrl, '?');
|
|
61
61
|
observe({ ...routeInfo, method: StringPrototypeToLowerCase.call(method), url });
|
|
62
62
|
}
|
|
63
63
|
});
|
package/lib/utils/methods.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/route-coverage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.0",
|
|
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)",
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"test": "../scripts/test.sh"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@contrast/common": "1.
|
|
21
|
-
"@contrast/config": "1.
|
|
22
|
-
"@contrast/dep-hooks": "1.
|
|
20
|
+
"@contrast/common": "1.26.0",
|
|
21
|
+
"@contrast/config": "1.34.0",
|
|
22
|
+
"@contrast/dep-hooks": "1.7.0",
|
|
23
23
|
"@contrast/fn-inspect": "^4.3.0",
|
|
24
|
-
"@contrast/logger": "1.
|
|
25
|
-
"@contrast/patcher": "1.
|
|
26
|
-
"@contrast/scopes": "1.
|
|
24
|
+
"@contrast/logger": "1.12.0",
|
|
25
|
+
"@contrast/patcher": "1.11.0",
|
|
26
|
+
"@contrast/scopes": "1.8.0",
|
|
27
|
+
"semver": "^7.6.0"
|
|
27
28
|
}
|
|
28
29
|
}
|