Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// RequestDefinition Tests
const reqDef: pmCollection.RequestDefinition = {
url: "string"
};
reqDef.url; // $ExpectType string | Url
reqDef.method; // $ExpectType string | undefined
reqDef.header; // $ExpectType HeaderDefinition | undefined
reqDef.body; // $ExpectType RequestBody | undefined
reqDef.auth; // $ExpectType RequestAuthDefinition | undefined
reqDef.proxy; // $ExpectType ProxyConfigDefinition | undefined
reqDef.certificate; // $ExpectType CertificateDefinition | undefined
// Request Tests
let req = new pmCollection.Request("string");
req = new pmCollection.Request(reqDef);
req.auth; // $ExpectType RequestAuth | undefined
req.body; // $ExpectType RequestBody | undefined
req.certificate; // $ExpectType Certificate | undefined
req.headers; // $ExpectType HeaderList
req.method; // $ExpectType string
req.proxy; // $ExpectType ProxyConfig | undefined
req.url; // $ExpectType Url
req.update(reqDef); // $ExpectType void
req.authorizeUsing("string"); // $ExpectType void
req.authorizeUsing({}); // $ExpectType void
req.authorizeUsing(null); // $ExpectType void
req.authorizeUsing("string", new pmCollection.VariableList(p, []));
// RequestDefinition Tests
const reqDef: pmCollection.RequestDefinition = {
url: "string"
};
reqDef.url; // $ExpectType string | Url
reqDef.method; // $ExpectType string | undefined
reqDef.header; // $ExpectType HeaderDefinition | undefined
reqDef.body; // $ExpectType RequestBody | undefined
reqDef.auth; // $ExpectType RequestAuthDefinition | undefined
reqDef.proxy; // $ExpectType ProxyConfigDefinition | undefined
reqDef.certificate; // $ExpectType CertificateDefinition | undefined
// Request Tests
let req = new pmCollection.Request("string");
req = new pmCollection.Request(reqDef);
req.auth; // $ExpectType RequestAuth | undefined
req.body; // $ExpectType RequestBody | undefined
req.certificate; // $ExpectType Certificate | undefined
req.headers; // $ExpectType HeaderList
req.method; // $ExpectType string
req.proxy; // $ExpectType ProxyConfig | undefined
req.url; // $ExpectType Url
req.update(reqDef); // $ExpectType void
req.authorizeUsing("string"); // $ExpectType void
req.authorizeUsing({}); // $ExpectType void
req.authorizeUsing(null); // $ExpectType void
req.authorizeUsing("string", new pmCollection.VariableList(p, []));
}
});
// Get the failures. If there was an error running the script itself, that takes precedence
if (!err && (abortOnFailure || stopOnFailure)) {
err = postProcessContext(result, assertionFailed); // also use async assertions
}
// Ensure that we have SDK instances, not serialized plain objects.
// @todo - should this be handled by the sandbox?
result && result._variables && (result._variables = new sdk.VariableScope(result._variables));
result && result.environment && (result.environment = new sdk.VariableScope(result.environment));
result && result.globals && (result.globals = new sdk.VariableScope(result.globals));
result && result.collectionVariables &&
(result.collectionVariables = new sdk.VariableScope(result.collectionVariables));
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 result.
// Refer: https://github.com/postmanlabs/postman-sandbox/pull/512
// Adding back here to avoid breaking change in `script` callback.
// @todo revisit script callback args in runtime v8.
payload.context && payload.context.response &&
(result.response = new sdk.Response(payload.context.response));
// persist the pm.variables for the next script
result && result._variables &&
(payload.context._variables = new sdk.VariableScope(result._variables));
// persist the pm.variables for the next request
result && result._variables && (this.state._variables = new sdk.VariableScope(result._variables));
// persist the mutated request in payload context,
async.map(collection.item, function (item, cb) {
var request = new sdk.Request(item.request);
convert(request, options, function (err, snippet) {
if (err) {
return cb(err);
}
return cb(null, {
name: item.name,
snippet: snippet
});
});
}, function (err, snippets) {
if (err) {
'key': thisParams[param].name,
'value': defaultVal,
'type': 'text',
'enabled': true
});
}
else if (thisParams[param].in === 'path') {
if (!rPathVariables) {
rPathVariables = {};
}
rPathVariables[thisParams[param].name] = defaultVal;
}
}
}
var request = new Request({
method: rMethod,
name: rName,
url: rUrl,
header: rHeaders
}),
item = new Item({name: rName});
var requestBodyJSON = {
mode: rDataMode
};
if (rDataMode === "formdata") {
requestBodyJSON.formdata = rData;
}
else if (rDataMode === "urlencoded") {
requestBodyJSON.urlencoded = rData;
this.environment = sdk.VariableScope.isVariableScope(context.environment) ?
context.environment : new sdk.VariableScope(context.environment, null, {enableTracking: true, changeTracker: {compressed: true}});
this._variables = sdk.VariableScope.isVariableScope(context._variables) ?
context._variables : new sdk.VariableScope(context._variables, null, {enableTracking: true, changeTracker: {compressed: true}});
this.globals = sdk.VariableScope.isVariableScope(context.globals) ?
context.globals : new sdk.VariableScope(context.globals, null, {enableTracking: true, changeTracker: {compressed: true}});
this.collectionVariables = sdk.VariableScope.isVariableScope(context.collectionVariables) ?
context.collectionVariables : new sdk.VariableScope(context.collectionVariables, null, {enableTracking: true, changeTracker: {compressed: true}});
if (TARGETS_WITH_REQUEST[this.target] || _.has(context, PROPERTY.REQUEST)) {
/**
* @note:
* this reference is passed on as `pm.request`, pm api adds helper functions like `to` to `pm.request`
* sandbox overrides collection Request.prototype.toJSON to remove helpers before toJSON, see `purse.js`
*/
this.request = sdk.Request.isRequest(context.request) ? context.request : new sdk.Request(context.request);
}
if (TARGETS_WITH_RESPONSE[this.target] || _.has(context, PROPERTY.RESPONSE)) {
/**
* @note:
* this reference is passed on as `pm.response`, pm api adds helper functions like `to` to `pm.response`
* sandbox overrides collection Response.prototype.toJSON to remove helpers before toJSON, see `purse.js`
*/
this.response = sdk.Response.isResponse(context.response) ?
context.response : new sdk.Response(context.response);
}
this.return = {};
};
authorizeRequest = function (request, done) {
if (!request.auth) {
return done();
}
var clonedReq = new sdk.Request(request.toJSON()),
auth = clonedReq.auth,
authInterface = createAuthInterface(auth),
handler = AuthLoader.getHandler(auth.type);
if (handler) {
handler.sign(authInterface, clonedReq, function () { return done(null, clonedReq); });
}
else {
return done(new Error('runtime~authorizeRequest: could not find handler for auth type ' + auth.type));
}
};