@usebruno/js 0.9.1 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usebruno/js",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "license": "MIT",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -17,7 +17,7 @@
17
17
  "@usebruno/query": "0.1.0",
18
18
  "ajv": "^8.12.0",
19
19
  "atob": "^2.1.2",
20
- "axios": "^0.26.0",
20
+ "axios": "^1.5.1",
21
21
  "btoa": "^1.2.1",
22
22
  "chai": "^4.3.7",
23
23
  "chai-string": "^1.5.0",
@@ -28,6 +28,7 @@
28
28
  "moment": "^2.29.4",
29
29
  "nanoid": "3.3.4",
30
30
  "node-fetch": "2.*",
31
- "uuid": "^9.0.0"
31
+ "uuid": "^9.0.0",
32
+ "node-vault": "^0.10.2"
32
33
  }
33
34
  }
package/src/bru.js CHANGED
@@ -1,6 +1,8 @@
1
1
  const Handlebars = require('handlebars');
2
2
  const { cloneDeep } = require('lodash');
3
3
 
4
+ const envVariableNameRegex = /^(?!\d)[\w-]*$/;
5
+
4
6
  class Bru {
5
7
  constructor(envVariables, collectionVariables, processEnvVars, collectionPath) {
6
8
  this.envVariables = envVariables;
@@ -59,10 +61,24 @@ class Bru {
59
61
  throw new Error('Key is required');
60
62
  }
61
63
 
64
+ if (envVariableNameRegex.test(key) === false) {
65
+ throw new Error(
66
+ `Variable name: "${key}" contains invalid characters!` +
67
+ ' Names must only contain alpha-numeric characters, "-", "_" and cannot start with a digit.'
68
+ );
69
+ }
70
+
62
71
  this.collectionVariables[key] = value;
63
72
  }
64
73
 
65
74
  getVar(key) {
75
+ if (envVariableNameRegex.test(key) === false) {
76
+ throw new Error(
77
+ `Variable name: "${key}" contains invalid characters!` +
78
+ ' Names must only contain alpha-numeric characters and cannot start with a digit.'
79
+ );
80
+ }
81
+
66
82
  return this.collectionVariables[key];
67
83
  }
68
84
  }
@@ -26,6 +26,7 @@ const axios = require('axios');
26
26
  const fetch = require('node-fetch');
27
27
  const chai = require('chai');
28
28
  const CryptoJS = require('crypto-js');
29
+ const NodeVault = require('node-vault');
29
30
 
30
31
  class ScriptRuntime {
31
32
  constructor() {}
@@ -46,6 +47,11 @@ class ScriptRuntime {
46
47
  const req = new BrunoRequest(request);
47
48
  const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
48
49
  const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []);
50
+ const additionalContextRoots = get(scriptingConfig, 'additionalContextRoots', []);
51
+ const additionalContextRootsAbsolute = lodash
52
+ .chain(additionalContextRoots)
53
+ .map((acr) => (acr.startsWith('/') ? acr : path.join(collectionPath, acr)))
54
+ .value();
49
55
 
50
56
  const whitelistedModules = {};
51
57
 
@@ -83,7 +89,7 @@ class ScriptRuntime {
83
89
  require: {
84
90
  context: 'sandbox',
85
91
  external: true,
86
- root: [collectionPath],
92
+ root: [collectionPath, ...additionalContextRootsAbsolute],
87
93
  mock: {
88
94
  // node libs
89
95
  path,
@@ -107,7 +113,8 @@ class ScriptRuntime {
107
113
  'node-fetch': fetch,
108
114
  'crypto-js': CryptoJS,
109
115
  ...whitelistedModules,
110
- fs: allowScriptFilesystemAccess ? fs : undefined
116
+ fs: allowScriptFilesystemAccess ? fs : undefined,
117
+ 'node-vault': NodeVault
111
118
  }
112
119
  }
113
120
  });
@@ -196,7 +203,8 @@ class ScriptRuntime {
196
203
  'node-fetch': fetch,
197
204
  'crypto-js': CryptoJS,
198
205
  ...whitelistedModules,
199
- fs: allowScriptFilesystemAccess ? fs : undefined
206
+ fs: allowScriptFilesystemAccess ? fs : undefined,
207
+ 'node-vault': NodeVault
200
208
  }
201
209
  }
202
210
  });
@@ -28,6 +28,7 @@ const nanoid = require('nanoid');
28
28
  const axios = require('axios');
29
29
  const fetch = require('node-fetch');
30
30
  const CryptoJS = require('crypto-js');
31
+ const NodeVault = require('node-vault');
31
32
 
32
33
  class TestRuntime {
33
34
  constructor() {}
@@ -48,6 +49,11 @@ class TestRuntime {
48
49
  const res = new BrunoResponse(response);
49
50
  const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
50
51
  const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []);
52
+ const additionalContextRoots = get(scriptingConfig, 'additionalContextRoots', []);
53
+ const additionalContextRootsAbsolute = lodash
54
+ .chain(additionalContextRoots)
55
+ .map((acr) => (acr.startsWith('/') ? acr : path.join(collectionPath, acr)))
56
+ .value();
51
57
 
52
58
  const whitelistedModules = {};
53
59
 
@@ -101,7 +107,7 @@ class TestRuntime {
101
107
  require: {
102
108
  context: 'sandbox',
103
109
  external: true,
104
- root: [collectionPath],
110
+ root: [collectionPath, ...additionalContextRootsAbsolute],
105
111
  mock: {
106
112
  // node libs
107
113
  path,
@@ -125,7 +131,8 @@ class TestRuntime {
125
131
  'node-fetch': fetch,
126
132
  'crypto-js': CryptoJS,
127
133
  ...whitelistedModules,
128
- fs: allowScriptFilesystemAccess ? fs : undefined
134
+ fs: allowScriptFilesystemAccess ? fs : undefined,
135
+ 'node-vault': NodeVault
129
136
  }
130
137
  }
131
138
  });