@contrast/route-coverage 1.12.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.
package/lib/index.js CHANGED
@@ -57,6 +57,7 @@ module.exports = function init(core) {
57
57
  return;
58
58
  }
59
59
 
60
+ route.url = info.url;
60
61
  const store = scopes.sources.getStore();
61
62
  if (store && !store.route) {
62
63
  store.route = route;
@@ -78,8 +78,9 @@ module.exports = function init(core) {
78
78
  const [req] = data.args;
79
79
  const method = req?.method && toLowerCase(req.method);
80
80
  const url = `${req.baseUrl}${req._parsedUrl.pathname}`;
81
+ const normalizedUrl = req.route.path;
81
82
  const { signature } = signatureMap.get(route.signature);
82
- if (method) routeCoverage.observe({ signature, url, method });
83
+ if (method) routeCoverage.observe({ signature, url, method, normalizedUrl });
83
84
  }
84
85
  });
85
86
  }
@@ -92,7 +93,7 @@ module.exports = function init(core) {
92
93
  }
93
94
 
94
95
  function discoverRoute({ signature, url, method }) {
95
- routeCoverage.discover({ signature, url, method });
96
+ routeCoverage.discover({ signature, url, method, normalizedUrl: url });
96
97
  }
97
98
 
98
99
  function instrumentRoute(router, route) {
@@ -58,7 +58,8 @@ module.exports = function init(core) {
58
58
  pre(data) {
59
59
  const [request] = data.args;
60
60
  const { method } = request.raw;
61
- emitObservation(url, method);
61
+ const [parsedUrl] = request.url.split(/\?/);
62
+ emitObservation(parsedUrl, url, method);
62
63
  },
63
64
  });
64
65
  }
@@ -69,17 +70,18 @@ module.exports = function init(core) {
69
70
  */
70
71
  function emitRouteCoverage(url, method) {
71
72
  method = toLowerCase(method);
72
- const event = { signature: createSignature(url, method), url, method };
73
+ const event = { signature: createSignature(url, method), url, method, normalizedUrl: url };
73
74
  routeCoverage.discover(event);
74
75
  }
75
76
 
76
77
  /**
77
78
  * @param {string} url
79
+ * @param {string} normalizedUrl
78
80
  * @param {string=} method
79
81
  */
80
- function emitObservation(url, method) {
82
+ function emitObservation(url, normalizedUrl, method) {
81
83
  method = method && toLowerCase(method);
82
- routeCoverage.observe({ method, url });
84
+ routeCoverage.observe({ method, url, normalizedUrl });
83
85
  }
84
86
 
85
87
  return core.routeCoverage.fastify = {
@@ -21,7 +21,7 @@ module.exports = function init(core) {
21
21
  const { patcher, depHooks, routeCoverage } = core;
22
22
 
23
23
  function emitRouteCoverage(url, method) {
24
- const event = { signature: createSignature(url, method), url, method };
24
+ const event = { signature: createSignature(url, method), url, method, normalizedUrl: url };
25
25
  routeCoverage.discover(event);
26
26
  }
27
27
 
@@ -30,8 +30,9 @@ module.exports = function init(core) {
30
30
  const req = ctx.request;
31
31
 
32
32
  if (req) {
33
- const { method } = req;
34
- routeCoverage.observe({ url: path, method: toLowerCase(method || '') });
33
+ const { url: reqUrl, method } = req;
34
+ const [url] = reqUrl.split(/\?/);
35
+ routeCoverage.observe({ url, method: toLowerCase(method || ''), normalizedUrl: path });
35
36
  }
36
37
 
37
38
  await next();
@@ -31,6 +31,6 @@ function createSignature(path, method = '') {
31
31
  * @param {Pick<import('../index').RouteInfo, 'method' | 'url'>} info
32
32
  * @return {string}
33
33
  */
34
- const routeIdentifier = (info) => `${info.method}.${info.url}`;
34
+ const routeIdentifier = (info) => `${info.method}.${info.normalizedUrl}`;
35
35
 
36
36
  module.exports = { createSignature, routeIdentifier, patchType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/route-coverage",
3
- "version": "1.12.0",
3
+ "version": "1.13.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,6 +17,6 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.15.1"
20
+ "@contrast/common": "1.16.0"
21
21
  }
22
22
  }