Skip to content

Commit

Permalink
Merge branch 'release/4.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Apr 1, 2024
2 parents 28b1648 + 7bfadb5 commit 0c185ca
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 55 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.yaml
@@ -1,3 +1,11 @@
4.6.1:
date: 2024-04-01
fixed bugs:
- GH-986 Fixed the types for `pm.execution.setNextRequest`
- GH-990 Sanitized the global scope by deleting the timers properties
chores:
- Updated dependencies

4.6.0:
date: 2024-03-13
fixed bugs:
Expand Down
2 changes: 1 addition & 1 deletion lib/sandbox/cookie-store.js
Expand Up @@ -75,7 +75,7 @@ STORE_METHODS.forEach(function (method) {
// This timeout ensures that the event is processed asynchronously
// without blocking the rest of the script execution.
// Refer: https://github.com/postmanlabs/postman-app-support/issues/11064
setTimeout(() => {
this.timers.wrapped.setTimeout(() => {
// finally, dispatch event over the bridge
this.emitter.dispatch(eventName, eventId, EVENT_STORE_ACTION, method, args);
});
Expand Down
9 changes: 5 additions & 4 deletions lib/sandbox/index.js
Expand Up @@ -19,6 +19,9 @@
*/
/* global bridge */

// Setup Timerz before we delete the global timers
require('./timers');

// Although we execute the user code in a well-defined scope using the uniscope
// module but still to cutoff the reference to the globally available properties
// we sanitize the global scope by deleting the forbidden properties in this UVM
Expand All @@ -35,9 +38,7 @@
'require', 'eval', 'console',
// 3. allow uvm internals because these will be cleared by uvm itself at the end.
// make sure any new property added in uvm firmware is allowed here as well.
'bridge', '__uvm_emit', '__uvm_dispatch', '__uvm_addEventListener',
// 4.allow all the timer methods
'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate'
'bridge', '__uvm_emit', '__uvm_dispatch', '__uvm_addEventListener'
]),
deleteProperty = function (key) {
// directly delete the property without setting it to `null` or `undefined`
Expand Down Expand Up @@ -78,7 +79,7 @@ require('./purse');
// setup the ping-pong and execute routines
bridge.on('ping', require('./ping').listener('pong'));

// initialise execution
// initialize execution
require('./execute')(bridge, {
console: (typeof console !== 'undefined' ? console : null),
window: (typeof window !== 'undefined' ? window : null)
Expand Down
1 change: 1 addition & 0 deletions lib/sandbox/pmapi.js
Expand Up @@ -298,6 +298,7 @@ function Postman (execution, onRequest, onSkipRequest, onAssertion, cookieStore,
* running the collection. Passing `null` stops the collection run
* after the current request is executed.
*
* @instance
* @param {string|null} request - name of the request to run next
*/
setNextRequest: function setNextRequest (request) {
Expand Down
20 changes: 12 additions & 8 deletions lib/sandbox/timers.js
@@ -1,5 +1,5 @@
/**
* @fileoverview This file contains the module that is required to enable specialised timers that have better control
* @fileOverview This file contains the module that is required to enable specialized timers that have better control
* on a global level.
*
* @todo - the architecture of this sucks even if this "works".
Expand All @@ -13,15 +13,15 @@ const /**
FUNCTION = 'function',

/**
* The set of timer function names. We use this array to define common behaviour of all setters and clearer timer
* The set of timer function names. We use this array to define common behavior of all setters and clearer timer
* functions
*
* @constant {Array.<String>}
*/
timerFunctionNames = ['Timeout', 'Interval', 'Immediate', 'Event'],

/**
* This object defines a set of timer function names that are trigerred a number of times instead of a single time.
* This object defines a set of timer function names that are triggered a number of times instead of a single time.
* Such timers, when placed in generic rules, needs special attention.
*
* @constant {Array.<Boolean>}
Expand Down Expand Up @@ -54,7 +54,7 @@ const /**
*
* @note This is a very important piece of code from compatibility standpoint.
* The global timers need to be returned as a function that does not hold reference to the scope
* and does not retain references to scope. Aditionally, the invocation of the timer function is
* and does not retain references to scope. Additionally, the invocation of the timer function is
* done without changing the scope to avoid Illegal Invocation errors.
*
* `timerFunctionNames` returns the suffixes of all timer operations that needs a
Expand Down Expand Up @@ -82,13 +82,17 @@ const /**
isGlobalClearAvailable = (new Function(`return typeof clear${name} === 'function'`))();

if (isGlobalSetterAvailable) {
// eslint-disable-next-line no-new-func
timers[('set' + name)] = (new Function(`return function (fn, ms) { return set${name}(fn, ms); }`))();
timers[`set${name}`] = (
// eslint-disable-next-line no-new-func
new Function('_setFn', `return function set${name} (fn, ms) { return _setFn(fn, ms); }`)
)(this[`set${name}`]);
}

if (isGlobalClearAvailable) {
// eslint-disable-next-line no-new-func
timers[('clear' + name)] = (new Function(`return function (id) { return clear${name}(id); }`))();
timers[`clear${name}`] = (
// eslint-disable-next-line no-new-func
new Function('_clearFn', `return function clear${name} (id) { return _clearFn(id); }`)
)(this[`clear${name}`]);
}

return timers;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "postman-sandbox",
"version": "4.6.0",
"version": "4.6.1",
"description": "Sandbox for Postman Scripts to run in Node.js or browser",
"author": "Postman Inc.",
"license": "Apache-2.0",
Expand Down Expand Up @@ -89,7 +89,7 @@
"shelljs": "^0.8.5",
"sinon": "^12.0.1",
"sinon-chai": "^3.7.0",
"terser": "^5.29.1",
"terser": "^5.30.0",
"tsd-jsdoc": "^2.5.0",
"tv4": "1.3.0",
"uniscope": "2.2.0",
Expand Down
1 change: 0 additions & 1 deletion test/unit/sandbox-sanity.test.js
Expand Up @@ -86,7 +86,6 @@ describe('sandbox', function () {
var ignoredProps = [
'TEMPORARY', 'PERSISTENT', // DedicatedWorkerGlobalScope constants (in Browser)
'require', 'eval', 'console', // uniscope ignored
'setTimeout', 'clearTimeout', 'setInterval', 'clearInterval', 'setImmediate', 'clearImmediate'
]
var propNames = [];
Expand Down
19 changes: 8 additions & 11 deletions types/index.d.ts
@@ -1,4 +1,4 @@
// Type definitions for postman-sandbox 4.5.0
// Type definitions for postman-sandbox 4.5.1
// Project: https://github.com/postmanlabs/postman-sandbox
// Definitions by: PostmanLabs
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down Expand Up @@ -254,16 +254,6 @@ declare interface Visualizer {
clear(): void;
}

declare namespace Execution {
/**
* Sets the next request to be run after the current request, when
* running the collection. Passing `null` stops the collection run
* after the current request is executed.
* @param request - name of the request to run next
*/
function setNextRequest(request: string | null): void;
}

declare interface Execution {
request: any;
response: any;
Expand All @@ -275,6 +265,13 @@ declare interface Execution {
* The path of the current request.
*/
location: ExecutionLocation;
/**
* Sets the next request to be run after the current request, when
* running the collection. Passing `null` stops the collection run
* after the current request is executed.
* @param request - name of the request to run next
*/
setNextRequest(request: string | null): void;
}

declare interface ExecutionLocation extends Array {
Expand Down
19 changes: 8 additions & 11 deletions types/sandbox/prerequest.d.ts
@@ -1,4 +1,4 @@
// Type definitions for postman-sandbox 4.5.0
// Type definitions for postman-sandbox 4.5.1
// Project: https://github.com/postmanlabs/postman-sandbox
// Definitions by: PostmanLabs
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down Expand Up @@ -113,16 +113,6 @@ declare interface Visualizer {
clear(): void;
}

declare namespace Execution {
/**
* Sets the next request to be run after the current request, when
* running the collection. Passing `null` stops the collection run
* after the current request is executed.
* @param request - name of the request to run next
*/
function setNextRequest(request: string | null): void;
}

declare interface Execution {
/**
* Stops the current request and its scripts from executing.
Expand All @@ -133,6 +123,13 @@ declare interface Execution {
* The path of the current request.
*/
location: ExecutionLocation;
/**
* Sets the next request to be run after the current request, when
* running the collection. Passing `null` stops the collection run
* after the current request is executed.
* @param request - name of the request to run next
*/
setNextRequest(request: string | null): void;
}

declare interface ExecutionLocation extends Array {
Expand Down
17 changes: 7 additions & 10 deletions types/sandbox/test.d.ts
@@ -1,4 +1,4 @@
// Type definitions for postman-sandbox 4.5.0
// Type definitions for postman-sandbox 4.5.1
// Project: https://github.com/postmanlabs/postman-sandbox
// Definitions by: PostmanLabs
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down Expand Up @@ -119,21 +119,18 @@ declare interface Visualizer {
clear(): void;
}

declare namespace Execution {
declare interface Execution {
/**
* The path of the current request.
*/
location: ExecutionLocation;
/**
* Sets the next request to be run after the current request, when
* running the collection. Passing `null` stops the collection run
* after the current request is executed.
* @param request - name of the request to run next
*/
function setNextRequest(request: string | null): void;
}

declare interface Execution {
/**
* The path of the current request.
*/
location: ExecutionLocation;
setNextRequest(request: string | null): void;
}

declare interface ExecutionLocation extends Array {
Expand Down

0 comments on commit 0c185ca

Please sign in to comment.