@contrast/core 1.34.1 → 1.35.1

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/app-info.js CHANGED
@@ -16,8 +16,9 @@
16
16
  'use strict';
17
17
 
18
18
  const os = require('os');
19
- const path = require('path');
20
19
  const fs = require('fs');
20
+ const path = require('path');
21
+ const semver = require('semver'); // eslint-disable-line node/no-extraneous-require
21
22
  const process = require('process');
22
23
  const { IntentionalError } = require('@contrast/common');
23
24
  const { findPackageJsonSync } = require('@contrast/find-package-json');
@@ -33,6 +34,7 @@ module.exports = function (core) {
33
34
  const { logger, config } = core;
34
35
  const { app_root, cmd_ignore_list, exclusive_entrypoint } = config.agent.node;
35
36
 
37
+ checkPreLoadFlag();
36
38
  const cmd = getCommand();
37
39
  const pkgInfo = getPackageInfo();
38
40
  const entrypoint = getEntrypoint();
@@ -55,7 +57,7 @@ module.exports = function (core) {
55
57
  app_dir: pkgInfo.dir,
56
58
  version: config.application.version || pkgInfo.packageData.version,
57
59
  serverVersion: config.server.version,
58
- node_version: process.version,
60
+ nodeVersion: process.version,
59
61
  appPath: config.application.path || pkgInfo.dir,
60
62
  serverName: config.server.name,
61
63
  serverType: config.server.type,
@@ -67,6 +69,26 @@ module.exports = function (core) {
67
69
  return core.appInfo;
68
70
 
69
71
 
72
+ function checkPreLoadFlag() {
73
+ const { version, execArgv } = process;
74
+ [
75
+ { range: '>=18.19.0', flags: ['--import'] },
76
+ { range: '>=16.17.0 <18.19.0', flags: ['--loader'] },
77
+ { range: '<16.17.0', flags: ['-r', '--require'] }
78
+ ].forEach(({ range, flags }) => {
79
+ if (
80
+ semver.satisfies(version, range) &&
81
+ !execArgv.some((el, idx) => el === '@contrast/agent' && flags.includes(execArgv[idx - 1]))
82
+ ) {
83
+ logger.warn(
84
+ 'For Node LTS %s, use %s command to run the agent. See: https://docs.contrastsecurity.com/en/install-node-js.html',
85
+ range,
86
+ flags
87
+ );
88
+ }
89
+ });
90
+ }
91
+
70
92
  /**
71
93
  * Generates a command string based on ARGV and process.argv0, which will be used
72
94
  * for the `appInfo.cmd` field. This function will throw if any of the config's
@@ -23,7 +23,9 @@ describe('core app-info', function () {
23
23
  release: sinon.stub().returns('1.23.45'),
24
24
  hostname: sinon.stub().returns('hostname'),
25
25
  };
26
+ });
26
27
 
28
+ it('builds out app data from os and process information', function () {
27
29
  appInfo = proxyquire(
28
30
  './app-info',
29
31
  {
@@ -35,9 +37,7 @@ describe('core app-info', function () {
35
37
  }
36
38
  }
37
39
  )(core);
38
- });
39
40
 
40
- it('builds out app data from os and process information', function () {
41
41
  expect(appInfo).to.deep.include({
42
42
  os: {
43
43
  type: 'Linux',
@@ -48,7 +48,7 @@ describe('core app-info', function () {
48
48
  hostname: 'hostname',
49
49
  indexFile: __filename,
50
50
  serverVersion: undefined,
51
- node_version: 'v14.17.5',
51
+ nodeVersion: 'v14.17.5',
52
52
  appPath: '/',
53
53
  serverName: 'zoing',
54
54
  serverType: 'Node.js',
@@ -79,4 +79,52 @@ describe('core app-info', function () {
79
79
 
80
80
  process.env.npm_package_json = npm_package_json;
81
81
  });
82
+
83
+ [
84
+ { version: 'v20.12.0', range: '>=18.19.0', badFlag: '-r', goodFlag: ['--import'] },
85
+ { version: 'v18.18.0', range: '>=16.17.0 <18.19.0', badFlag: '-r', goodFlag: ['--loader'] },
86
+ { version: 'v16.16.0', range: '<16.17.0', badFlag: '--loader', goodFlag: ['-r', '--require'] }
87
+ ].forEach(({ version, range, badFlag, goodFlag }) => {
88
+ it('logs a warning if non-recommended preload flag is used ', function() {
89
+ appInfo = proxyquire(
90
+ './app-info',
91
+ {
92
+ os,
93
+ process: {
94
+ ...process,
95
+ argv: ['node', __filename],
96
+ version,
97
+ execArgv: [badFlag, '@contrast/agent']
98
+ }
99
+ }
100
+ )(core);
101
+ expect(core.logger.warn).to.have.been.calledWith(
102
+ 'For Node LTS %s, use %s command to run the agent. See: https://docs.contrastsecurity.com/en/install-node-js.html',
103
+ range,
104
+ goodFlag
105
+ );
106
+ });
107
+ });
108
+
109
+ [
110
+ { version: 'v20.12.0', goodFlag: '--import' },
111
+ { version: 'v18.18.0', goodFlag: '--loader' },
112
+ { version: 'v16.16.0', goodFlag: '--require' }
113
+ ].forEach(({ version, goodFlag }) => {
114
+ it('does not log a warning if recommended preload flag is used ', function() {
115
+ appInfo = proxyquire(
116
+ './app-info',
117
+ {
118
+ os,
119
+ process: {
120
+ ...process,
121
+ argv: ['node', __filename],
122
+ version,
123
+ execArgv: [goodFlag, '@contrast/agent']
124
+ }
125
+ }
126
+ )(core);
127
+ expect(core.logger.warn).not.to.have.been.called;
128
+ });
129
+ });
82
130
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/core",
3
- "version": "1.34.1",
3
+ "version": "1.35.1",
4
4
  "description": "Preconfigured Contrast agent core services and models",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -16,9 +16,12 @@
16
16
  "test": "../scripts/test.sh"
17
17
  },
18
18
  "dependencies": {
19
- "@contrast/common": "1.23.0",
19
+ "@contrast/common": "1.24.0",
20
+ "@contrast/config": "1.31.0",
20
21
  "@contrast/find-package-json": "^1.0.0",
21
22
  "@contrast/fn-inspect": "^4.3.0",
22
- "axios": "^1.6.8"
23
+ "@contrast/logger": "1.8.5",
24
+ "@contrast/patcher": "1.7.5",
25
+ "axios": "^1.7.4"
23
26
  }
24
27
  }