Skip to content

Commit

Permalink
feat: add support for vault secrets in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Joglekar committed May 21, 2024
1 parent 08677f5 commit 511ee6f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/runner/extensions/event.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var _ = require('lodash'),
createItemContext = require('../create-item-context'),

ASSERTION_FAILURE = 'AssertionFailure',
SAFE_CONTEXT_VARIABLES = ['_variables', 'environment', 'globals', 'collectionVariables', 'cookies', 'data',
'request', 'response'],
SAFE_CONTEXT_VARIABLES = ['_variables', 'environment', 'globals', 'collectionVariables', 'vaultSecrets', 'cookies',
'data', 'request', 'response'],

EXECUTION_REQUEST_EVENT_BASE = 'execution.request.',
EXECUTION_RESPONSE_EVENT_BASE = 'execution.response.',
Expand Down Expand Up @@ -522,6 +522,8 @@ module.exports = {
result && result.globals && (result.globals = new sdk.VariableScope(result.globals));
result && result.collectionVariables &&
(result.collectionVariables = new sdk.VariableScope(result.collectionVariables));
result && result.vaultSecrets &&
(result.vaultSecrets = new sdk.VariableScope(result.vaultSecrets));
result && result.request && (result.request = new sdk.Request(result.request));

// @note Since postman-sandbox@3.5.2, response object is not included in the execution
Expand Down
7 changes: 4 additions & 3 deletions lib/runner/extensions/item.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ module.exports = {
// create the context object for scripts to run
ctxTemplate = {
collectionVariables: collectionVariables,
vaultSecrets: vaultSecrets,
_variables: _variables,
globals: globals,
environment: environment,
Expand All @@ -150,7 +151,7 @@ module.exports = {
item: item,
coords: coords,
context: ctxTemplate,
trackContext: ['globals', 'environment', 'collectionVariables'],
trackContext: ['globals', 'environment', 'collectionVariables', 'vaultSecrets'],
stopOnScriptError: stopOnError,
stopOnFailure: stopOnFailure
}).done(function (prereqExecutions, prereqExecutionError, shouldSkipExecution) {
Expand Down Expand Up @@ -188,7 +189,7 @@ module.exports = {

this.queue('request', {
item: item,
vaultSecrets: vaultSecrets,
vaultSecrets: ctxTemplate.vaultSecrets,
globals: ctxTemplate.globals,
environment: ctxTemplate.environment,
collectionVariables: ctxTemplate.collectionVariables,
Expand Down Expand Up @@ -232,7 +233,7 @@ module.exports = {
item: item,
coords: coords,
context: ctxTemplate,
trackContext: ['tests', 'globals', 'environment', 'collectionVariables'],
trackContext: ['tests', 'globals', 'environment', 'collectionVariables', 'vaultSecrets'],
stopOnScriptError: stopOnError,
abortOnFailure: abortOnFailure,
stopOnFailure: stopOnFailure
Expand Down
29 changes: 19 additions & 10 deletions test/integration/inherited-entities/pm-variables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ describe('pm.variables', function () {
{ key: 'key-4', value: 'env-value-4', name: 'key-4', enabled: true }
]
},
vaultVariables: {
vaultSecrets: {
values: [
{ key: 'vault:key5', value: 'vault-value-5', enabled: true }
{ key: 'vault:key5', value: 'vault-value-5', enabled: true },
{ key: 'vault:key6', value: 'vault-value-6', enabled: true }
]
},
collection: {
Expand Down Expand Up @@ -95,7 +96,8 @@ describe('pm.variables', function () {
'key-2': 'coll-value-2',
'key-3': 'env-value-3',
'key-4': 'data-value-4',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
});
});
});
Expand Down Expand Up @@ -229,7 +231,8 @@ describe('pm.variables', function () {
'key-2': 'modified-1',
'key-3': 'env-value-3',
'key-4': 'data-value-4',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
}
]);

Expand All @@ -240,7 +243,8 @@ describe('pm.variables', function () {
'key-2': 'modified-2',
'key-3': 'modified-2',
'key-4': 'data-value-4',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
}
]);

Expand All @@ -251,7 +255,8 @@ describe('pm.variables', function () {
'key-2': 'modified-2',
'key-3': 'modified-3',
'key-4': 'modified-3',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
}
]);

Expand All @@ -262,7 +267,8 @@ describe('pm.variables', function () {
'key-2': 'modified-2',
'key-3': 'modified-3',
'key-4': 'modified-4',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
}
]);

Expand All @@ -273,7 +279,8 @@ describe('pm.variables', function () {
'key-2': 'modified-1',
'key-3': 'modified-3',
'key-4': 'modified-4',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
}
]);

Expand All @@ -284,7 +291,8 @@ describe('pm.variables', function () {
'key-2': 'modified-1',
'key-3': 'modified-3',
'key-4': 'modified-3',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
}
]);
});
Expand Down Expand Up @@ -350,7 +358,8 @@ describe('pm.variables', function () {
'key-2': 'coll-value-2',
'key-3': 'env-value-3',
'key-4': 'data-value-4',
'vault:key5': 'global-value-5'
'vault:key5': 'global-value-5',
'vault:key6': 'vault-value-6'
}
]);
});
Expand Down

0 comments on commit 511ee6f

Please sign in to comment.