Skip to content

Commit 90a805b

Browse files
committed
Merge branch 'release/7.42.0'
2 parents 9ede743 + 1308c7b commit 90a805b

File tree

11 files changed

+275
-54
lines changed

11 files changed

+275
-54
lines changed

CHANGELOG.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
7.42.0:
2+
date: 2024-09-04
3+
new features:
4+
- GH-1452 Enabled async access to vault secrets
5+
- GH-1413 Added support for initializing local variables
6+
chores:
7+
- GH-1452 Update dependencies
8+
19
7.41.2:
210
date: 2024-08-16
311
fixed bugs:

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ runner.run(collection, {
5151
// Globals (a "VariableScope" from the SDK)
5252
globals: new sdk.VariableScope(),
5353

54+
// Local variables (a "VariableScope" from the SDK)
55+
localVariables: new sdk.VariableScope(),
56+
5457
// Execute a folder/request using id/name or path
5558
entrypoint: {
5659
// execute a folder/request using id or name

lib/runner/extensions/event.command.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ var _ = require('lodash'),
2121
EXECUTION_COOKIES_EVENT_BASE = 'execution.cookies.',
2222
EXECUTION_SKIP_REQUEST_EVENT_BASE = 'execution.skipRequest.',
2323

24+
EXECUTION_VAULT_BASE = 'execution.vault.',
25+
2426
COOKIES_EVENT_STORE_ACTION = 'store',
2527
COOKIE_STORE_PUT_METHOD = 'putCookie',
2628
COOKIE_STORE_UPDATE_METHOD = 'updateCookie',
@@ -240,8 +242,17 @@ module.exports = {
240242

241243
packageResolver = _.get(this, 'options.script.packageResolver'),
242244

245+
vaultSecrets = payload.context.vaultSecrets,
246+
allowVaultAccess = _.get(vaultSecrets, '_.allowScriptAccess'),
247+
243248
events;
244249

250+
// Explicitly enable tracking for vault secrets here as this will
251+
// not be sent to sandbox who otherwise takes care of mutation tracking
252+
if (allowVaultAccess) {
253+
vaultSecrets.enableTracking({ autoCompact: true });
254+
}
255+
245256
// @todo: find a better place to code this so that event is not aware of such options
246257
if (abortOnFailure) {
247258
abortOnError = true;
@@ -387,6 +398,22 @@ module.exports = {
387398
}
388399
}.bind(this));
389400

401+
this.host.on(EXECUTION_VAULT_BASE + executionId, function (id, cmd, ...args) {
402+
// Ensure error is string
403+
// TODO identify why error objects are not being serialized correctly
404+
const dispatch = (e, r) => { this.host.dispatch(EXECUTION_VAULT_BASE + executionId, id, e, r); };
405+
406+
if (!allowVaultAccess) {
407+
return dispatch('Vault access denied');
408+
}
409+
410+
if (!['get', 'set', 'unset'].includes(cmd)) {
411+
return dispatch(`Invalid vault command: ${cmd}`);
412+
}
413+
414+
dispatch(null, vaultSecrets[cmd](...args));
415+
}.bind(this));
416+
390417
this.host.on(EXECUTION_REQUEST_EVENT_BASE + executionId,
391418
function (scriptCursor, id, requestId, request) {
392419
// remove files in request body if any
@@ -458,11 +485,7 @@ module.exports = {
458485
// @todo: Expose this as a property in Collection SDK's Script
459486
timeout: payload.scriptTimeout,
460487
cursor: scriptCursor,
461-
context: {
462-
..._.pick(payload.context, SAFE_CONTEXT_VARIABLES),
463-
vaultSecrets: _.get(payload.context.vaultSecrets, '_.allowScriptAccess') ?
464-
payload.context.vaultSecrets : undefined
465-
},
488+
context: _.pick(payload.context, SAFE_CONTEXT_VARIABLES),
466489
resolvedPackages: resolvedPackages,
467490

468491
// legacy options
@@ -479,6 +502,7 @@ module.exports = {
479502
this.host.removeAllListeners(EXECUTION_COOKIES_EVENT_BASE + executionId);
480503
this.host.removeAllListeners(EXECUTION_ERROR_EVENT_BASE + executionId);
481504
this.host.removeAllListeners(EXECUTION_SKIP_REQUEST_EVENT_BASE + executionId);
505+
this.host.removeAllListeners(EXECUTION_VAULT_BASE + executionId);
482506

483507
// Handle async errors as well.
484508
// If there was an error running the script itself, that takes precedence
@@ -529,10 +553,16 @@ module.exports = {
529553
result && result.globals && (result.globals = new sdk.VariableScope(result.globals));
530554
result && result.collectionVariables &&
531555
(result.collectionVariables = new sdk.VariableScope(result.collectionVariables));
532-
result && result.vaultSecrets &&
533-
(result.vaultSecrets = new sdk.VariableScope(result.vaultSecrets));
534556
result && result.request && (result.request = new sdk.Request(result.request));
535557

558+
// vault secrets are not sent to sandbox, thus using the scope from run context.
559+
if (allowVaultAccess && vaultSecrets) {
560+
result.vaultSecrets = vaultSecrets;
561+
562+
// Prevent mutations from being carry-forwarded to subsequent events
563+
vaultSecrets.disableTracking();
564+
}
565+
536566
// @note Since [email protected], response object is not included in the execution
537567
// result.
538568
// Refer: https://github.com/postmanlabs/postman-sandbox/pull/512

lib/runner/extensions/item.command.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ module.exports = {
152152
item: item,
153153
coords: coords,
154154
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'],
156157
stopOnScriptError: stopOnError,
157158
stopOnFailure: stopOnFailure
158159
}).done(function (prereqExecutions, prereqExecutionError, shouldSkipExecution) {
@@ -234,7 +235,8 @@ module.exports = {
234235
item: item,
235236
coords: coords,
236237
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'],
238240
stopOnScriptError: stopOnError,
239241
abortOnFailure: abortOnFailure,
240242
stopOnFailure: stopOnFailure

lib/runner/extensions/waterfall.command.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ module.exports = {
8080
new VariableScope(state.vaultSecrets);
8181
state.collectionVariables = VariableScope.isVariableScope(state.collectionVariables) ?
8282
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);
8485

8586
// prepare the vault variable scope
8687
prepareVaultVariableScope(state.vaultSecrets);

lib/runner/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ _.assign(Runner.prototype, {
121121
vaultSecrets: options.vaultSecrets,
122122
// @todo Move to item level to support Item and ItemGroup variables
123123
collectionVariables: collection.variables,
124+
localVariables: options.localVariables,
124125
certificates: options.certificates,
125126
proxies: options.proxies
126127
}, runOptions)));

package-lock.json

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postman-runtime",
3-
"version": "7.41.2",
3+
"version": "7.42.0",
44
"description": "Underlying library of executing Postman Collections",
55
"author": "Postman Inc.",
66
"license": "Apache-2.0",
@@ -55,8 +55,8 @@
5555
"node-oauth1": "1.3.0",
5656
"performance-now": "2.1.0",
5757
"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",
6060
"postman-url-encoder": "3.0.5",
6161
"serialised-error": "1.1.3",
6262
"strip-json-comments": "3.1.1",

test/integration/inherited-entities/pm-variables.test.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ var _ = require('lodash'),
44
describe('pm.variables', function () {
55
var testRun,
66
runOptions = {
7+
localVariables: {
8+
values: [
9+
{ key: 'key-1', value: 'local-value-1', name: 'key-1', enabled: true },
10+
{ key: 'key-7', value: 'local-value-7', name: 'key-7', enabled: true }
11+
]
12+
},
713
data: [{
814
'key-4': 'data-value-4'
915
}],
@@ -95,26 +101,26 @@ describe('pm.variables', function () {
95101

96102
consoleLogs.forEach(function (consoleLog) {
97103
expect(consoleLog).to.eql({
98-
'key-1': 'global-value-1',
104+
'key-1': 'local-value-1',
99105
'key-2': 'coll-value-2',
100106
'key-3': 'env-value-3',
101107
'key-4': 'data-value-4',
102108
'vault:key5': 'global-value-5',
103-
'vault:key6': 'vault-value-6'
109+
'key-7': 'local-value-7'
104110
});
105111
});
106112
});
107113

108114
it('should be honoured in request URL', function () {
109115
var url = testRun.request.getCall(0).args[3].url.toString(),
110-
expectedParam = 'global-value-1:coll-value-2:env-value-3:data-value-4:global-value-5';
116+
expectedParam = 'local-value-1:coll-value-2:env-value-3:data-value-4:global-value-5';
111117

112118
expect(url).to.equal('https://postman-echo.com/get?param=' + expectedParam);
113119
});
114120

115121
it('should be honoured in auth', function () {
116122
var response = testRun.response.getCall(0).args[2],
117-
expectedToken = 'global-value-1:coll-value-2:env-value-3:data-value-4:global-value-5';
123+
expectedToken = 'local-value-1:coll-value-2:env-value-3:data-value-4:global-value-5';
118124

119125
expect(response.json()).to.deep.nested.include({
120126
'headers.authorization': 'Bearer ' + expectedToken
@@ -235,7 +241,7 @@ describe('pm.variables', function () {
235241
'key-3': 'env-value-3',
236242
'key-4': 'data-value-4',
237243
'vault:key5': 'global-value-5',
238-
'vault:key6': 'vault-value-6'
244+
'key-7': 'local-value-7'
239245
}
240246
]);
241247

@@ -247,7 +253,7 @@ describe('pm.variables', function () {
247253
'key-3': 'modified-2',
248254
'key-4': 'data-value-4',
249255
'vault:key5': 'global-value-5',
250-
'vault:key6': 'vault-value-6'
256+
'key-7': 'local-value-7'
251257
}
252258
]);
253259

@@ -259,7 +265,7 @@ describe('pm.variables', function () {
259265
'key-3': 'modified-3',
260266
'key-4': 'modified-3',
261267
'vault:key5': 'global-value-5',
262-
'vault:key6': 'vault-value-6'
268+
'key-7': 'local-value-7'
263269
}
264270
]);
265271

@@ -271,7 +277,7 @@ describe('pm.variables', function () {
271277
'key-3': 'modified-3',
272278
'key-4': 'modified-4',
273279
'vault:key5': 'global-value-5',
274-
'vault:key6': 'vault-value-6'
280+
'key-7': 'local-value-7'
275281
}
276282
]);
277283

@@ -283,7 +289,7 @@ describe('pm.variables', function () {
283289
'key-3': 'modified-3',
284290
'key-4': 'modified-4',
285291
'vault:key5': 'global-value-5',
286-
'vault:key6': 'vault-value-6'
292+
'key-7': 'local-value-7'
287293
}
288294
]);
289295

@@ -295,7 +301,7 @@ describe('pm.variables', function () {
295301
'key-3': 'modified-3',
296302
'key-4': 'modified-3',
297303
'vault:key5': 'global-value-5',
298-
'vault:key6': 'vault-value-6'
304+
'key-7': 'local-value-7'
299305
}
300306
]);
301307
});
@@ -362,7 +368,7 @@ describe('pm.variables', function () {
362368
'key-3': 'env-value-3',
363369
'key-4': 'data-value-4',
364370
'vault:key5': 'global-value-5',
365-
'vault:key6': 'vault-value-6'
371+
'key-7': 'local-value-7'
366372
}
367373
]);
368374
});

test/integration/sanity/variable-changes.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('variable changes', function () {
2626
pm.environment.set('environment', 'environment value');
2727
pm.globals.set('globals', 'globals value');
2828
pm.collectionVariables.set('collection', 'collection value');
29-
pm.vault.set('secret1', 'vault value');
29+
await pm.vault.set('secret1', 'vault value');
3030
`
3131
}
3232
}, {
@@ -35,7 +35,7 @@ describe('variable changes', function () {
3535
exec: `
3636
pm.environment.set("environment", "environment updated value");
3737
pm.collectionVariables.set("collection", "collection updated value");
38-
pm.vault.set('secret1', 'vault updated value');
38+
await pm.vault.set('secret1', 'vault updated value');
3939
`
4040
}
4141
}],

0 commit comments

Comments
 (0)