postman-runtime 7.41.2 → 7.43.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.
@@ -21,6 +21,8 @@ var _ = require('lodash'),
21
21
  EXECUTION_COOKIES_EVENT_BASE = 'execution.cookies.',
22
22
  EXECUTION_SKIP_REQUEST_EVENT_BASE = 'execution.skipRequest.',
23
23
 
24
+ EXECUTION_VAULT_BASE = 'execution.vault.',
25
+
24
26
  COOKIES_EVENT_STORE_ACTION = 'store',
25
27
  COOKIE_STORE_PUT_METHOD = 'putCookie',
26
28
  COOKIE_STORE_UPDATE_METHOD = 'updateCookie',
@@ -240,6 +242,11 @@ module.exports = {
240
242
 
241
243
  packageResolver = _.get(this, 'options.script.packageResolver'),
242
244
 
245
+ vaultSecrets = payload.context.vaultSecrets,
246
+ // Do not assign any initial value here as it will be used
247
+ // to determine if the vault access check was done or not
248
+ hasVaultAccess,
249
+
243
250
  events;
244
251
 
245
252
  // @todo: find a better place to code this so that event is not aware of such options
@@ -387,6 +394,37 @@ module.exports = {
387
394
  }
388
395
  }.bind(this));
389
396
 
397
+ this.host.on(EXECUTION_VAULT_BASE + executionId, async function (id, cmd, ...args) {
398
+ if (hasVaultAccess === undefined) {
399
+ try {
400
+ // eslint-disable-next-line require-atomic-updates
401
+ hasVaultAccess = Boolean(await vaultSecrets?._?.allowScriptAccess(item.id));
402
+ }
403
+ catch (_) {
404
+ // eslint-disable-next-line require-atomic-updates
405
+ hasVaultAccess = false;
406
+ }
407
+ }
408
+
409
+ // Ensure error is string
410
+ // TODO identify why error objects are not being serialized correctly
411
+ const dispatch = (e, r) => { this.host.dispatch(EXECUTION_VAULT_BASE + executionId, id, e, r); };
412
+
413
+ if (!hasVaultAccess) {
414
+ return dispatch('Vault access denied');
415
+ }
416
+
417
+ if (!['get', 'set', 'unset'].includes(cmd)) {
418
+ return dispatch(`Invalid vault command: ${cmd}`);
419
+ }
420
+
421
+ // Explicitly enable tracking for vault secrets here as this will
422
+ // not be sent to sandbox who otherwise takes care of mutation tracking
423
+ vaultSecrets.enableTracking({ autoCompact: true });
424
+
425
+ dispatch(null, vaultSecrets[cmd](...args));
426
+ }.bind(this));
427
+
390
428
  this.host.on(EXECUTION_REQUEST_EVENT_BASE + executionId,
391
429
  function (scriptCursor, id, requestId, request) {
392
430
  // remove files in request body if any
@@ -458,11 +496,7 @@ module.exports = {
458
496
  // @todo: Expose this as a property in Collection SDK's Script
459
497
  timeout: payload.scriptTimeout,
460
498
  cursor: scriptCursor,
461
- context: {
462
- ..._.pick(payload.context, SAFE_CONTEXT_VARIABLES),
463
- vaultSecrets: _.get(payload.context.vaultSecrets, '_.allowScriptAccess') ?
464
- payload.context.vaultSecrets : undefined
465
- },
499
+ context: _.pick(payload.context, SAFE_CONTEXT_VARIABLES),
466
500
  resolvedPackages: resolvedPackages,
467
501
 
468
502
  // legacy options
@@ -479,6 +513,7 @@ module.exports = {
479
513
  this.host.removeAllListeners(EXECUTION_COOKIES_EVENT_BASE + executionId);
480
514
  this.host.removeAllListeners(EXECUTION_ERROR_EVENT_BASE + executionId);
481
515
  this.host.removeAllListeners(EXECUTION_SKIP_REQUEST_EVENT_BASE + executionId);
516
+ this.host.removeAllListeners(EXECUTION_VAULT_BASE + executionId);
482
517
 
483
518
  // Handle async errors as well.
484
519
  // If there was an error running the script itself, that takes precedence
@@ -529,10 +564,16 @@ module.exports = {
529
564
  result && result.globals && (result.globals = new sdk.VariableScope(result.globals));
530
565
  result && result.collectionVariables &&
531
566
  (result.collectionVariables = new sdk.VariableScope(result.collectionVariables));
532
- result && result.vaultSecrets &&
533
- (result.vaultSecrets = new sdk.VariableScope(result.vaultSecrets));
534
567
  result && result.request && (result.request = new sdk.Request(result.request));
535
568
 
569
+ // vault secrets are not sent to sandbox, thus using the scope from run context.
570
+ if (hasVaultAccess && vaultSecrets) {
571
+ result.vaultSecrets = vaultSecrets;
572
+
573
+ // Prevent mutations from being carry-forwarded to subsequent events
574
+ vaultSecrets.disableTracking();
575
+ }
576
+
536
577
  // @note Since postman-sandbox@3.5.2, response object is not included in the execution
537
578
  // result.
538
579
  // Refer: https://github.com/postmanlabs/postman-sandbox/pull/512
@@ -152,7 +152,8 @@ module.exports = {
152
152
  item: item,
153
153
  coords: coords,
154
154
  context: ctxTemplate,
155
- trackContext: ['globals', 'environment', 'collectionVariables', 'vaultSecrets'],
155
+ // No need to include vaultSecrets here as runtime takes care of tracking internally
156
+ trackContext: ['globals', 'environment', 'collectionVariables'],
156
157
  stopOnScriptError: stopOnError,
157
158
  stopOnFailure: stopOnFailure
158
159
  }).done(function (prereqExecutions, prereqExecutionError, shouldSkipExecution) {
@@ -234,7 +235,8 @@ module.exports = {
234
235
  item: item,
235
236
  coords: coords,
236
237
  context: ctxTemplate,
237
- trackContext: ['tests', 'globals', 'environment', 'collectionVariables', 'vaultSecrets'],
238
+ // No need to include vaultSecrets here as runtime takes care of tracking internally
239
+ trackContext: ['tests', 'globals', 'environment', 'collectionVariables'],
238
240
  stopOnScriptError: stopOnError,
239
241
  abortOnFailure: abortOnFailure,
240
242
  stopOnFailure: stopOnFailure
@@ -80,7 +80,8 @@ module.exports = {
80
80
  new VariableScope(state.vaultSecrets);
81
81
  state.collectionVariables = VariableScope.isVariableScope(state.collectionVariables) ?
82
82
  state.collectionVariables : new VariableScope(state.collectionVariables);
83
- state._variables = new VariableScope();
83
+ state._variables = VariableScope.isVariableScope(state.localVariables) ?
84
+ state.localVariables : new VariableScope(state.localVariables);
84
85
 
85
86
  // prepare the vault variable scope
86
87
  prepareVaultVariableScope(state.vaultSecrets);
@@ -121,6 +121,7 @@ _.assign(Runner.prototype, {
121
121
  vaultSecrets: options.vaultSecrets,
122
122
  // @todo Move to item level to support Item and ItemGroup variables
123
123
  collectionVariables: collection.variables,
124
+ localVariables: options.localVariables,
124
125
  certificates: options.certificates,
125
126
  proxies: options.proxies
126
127
  }, runOptions)));
@@ -201,7 +201,7 @@ module.exports = {
201
201
  const url = new Url(domain);
202
202
 
203
203
  // @note URL path is ignored
204
- return `${url.protocol || 'https'}://${url.getRemote()}/*`;
204
+ return `${url.protocol || 'https'}://${url.getRemote()}:*/*`;
205
205
  }));
206
206
  });
207
207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postman-runtime",
3
- "version": "7.41.2",
3
+ "version": "7.43.0",
4
4
  "description": "Underlying library of executing Postman Collections",
5
5
  "author": "Postman Inc.",
6
6
  "license": "Apache-2.0",
@@ -55,8 +55,8 @@
55
55
  "node-oauth1": "1.3.0",
56
56
  "performance-now": "2.1.0",
57
57
  "postman-collection": "4.5.0",
58
- "postman-request": "2.88.1-postman.39",
59
- "postman-sandbox": "5.1.1",
58
+ "postman-request": "2.88.1-postman.40",
59
+ "postman-sandbox": "5.1.2",
60
60
  "postman-url-encoder": "3.0.5",
61
61
  "serialised-error": "1.1.3",
62
62
  "strip-json-comments": "3.1.1",