Skip to content

Commit

Permalink
Merge branch 'release/7.33.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
codenirvana committed Aug 3, 2023
2 parents 86b9842 + e82ef13 commit 1a15029
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .nycrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function configOverrides(testType) {
case 'integration-legacy':
return {
statements: 45,
branches: 35,
branches: 34,
functions: 45,
lines: 45
};
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
7.33.0:
date: 2023-08-04
new features:
- >-
GH-1326 Added support for uploading binary files via base64 encoded string
in formdata and file mode body
fixed bugs:
- GH-1312 Fixed a bug where dns lookup used to fail on Node.js v20
chores:
- Updated dependencies

7.32.3:
date: 2023-06-08
fixed bugs:
- GH-1306 Fixed a bug where JWT base64 secret was not decoded correctly
chores:
- Updated dependencies

Expand Down
11 changes: 3 additions & 8 deletions lib/requester/core-body-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,13 @@ formDataBodyReducer = function (data, param) {
formParam.value = E; // make sure value is not null/undefined ever
}

// if data has a truthy content type, we mutate the value to take the options. we are assuming that
// blank string will not be considered as an accepted content type.
if (param.contentType && typeof param.contentType === STRING) {
(options || (options = {})).contentType = param.contentType;
}

// additionally parse the file name and length if sent
// @note: Add support for fileName & fileLength option in Schema & SDK.
// The filepath property overrides filename and may contain a relative path.
if (typeof param.fileName === STRING) { (options || (options = {})).filename = param.fileName; }
if (typeof param.fileLength === 'number') { (options || (options = {})).knownLength = param.fileLength; }

if (typeof param.fileName === STRING) {
(options || (options = {})).filename = param.fileName;
}

// if options were set, add them to formParam
options && (formParam.options = options);
Expand Down
39 changes: 34 additions & 5 deletions lib/requester/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ var dns = require('dns'),
// returning error synchronously causes uncaught error because listeners are not attached to error events
// on socket yet
return setImmediate(function () {
callback(null, resolvedAddr, resolvedFamily);
// when options.all is set, the callback expects an array of addresses
return options.all ?
callback(null, [{ address: resolvedAddr, family: resolvedFamily }]) :
callback(null, resolvedAddr, resolvedFamily);
});
}

Expand Down Expand Up @@ -289,20 +292,46 @@ var dns = require('dns'),
// - localhost
// - *.localhost
if (getTLD(lowercaseHost) !== LOCALHOST) {
// when options.all is set, the callback expects an array of addresses
if (options.all) {
return _lookup(options, hostLookup, lowercaseHost, function (err, addresses) {
if (err) { return callback(err); }

// error out if any of the resolved addresses are restricted
if (_.some(addresses, (addr) => {
return self.isAddressRestricted(addr && addr.address, networkOpts);
})) {
return callback(new Error(ERROR_ADDRESS_RESOLVE + hostname));
}

return callback(null, addresses);
});
}

return _lookup(options, hostLookup, lowercaseHost, function (err, addr, family) {
if (err) { return callback(err); }

return callback(self.isAddressRestricted(addr, networkOpts) ?
new Error(ERROR_ADDRESS_RESOLVE + hostname) : null, addr, family);
// error out if the resolved address is restricted
if (self.isAddressRestricted(addr, networkOpts)) {
return callback(new Error(ERROR_ADDRESS_RESOLVE + hostname));
}

return callback(null, addr, family);
});
}

// Try checking if we can connect to IPv6 localhost ('::1')
connect(LOCAL_IPV6, lookupOptions.port, function (err) {
// use IPv4 if we cannot connect to IPv6
if (err) { return callback(null, LOCAL_IPV4, 4); }
if (err) {
return options.all ?
callback(null, [{ address: LOCAL_IPV4, family: 4 }]) :
callback(null, LOCAL_IPV4, 4);
}

callback(null, LOCAL_IPV6, 6);
return options.all ?
callback(null, [{ address: LOCAL_IPV6, family: 6 }]) :
callback(null, LOCAL_IPV6, 6);
});
},

Expand Down
14 changes: 14 additions & 0 deletions lib/runner/request-helpers-presend.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ module.exports = [
disableParam && (formparam.disabled = true);
};

// handle base64 encoded file
if (!formparam.src && formparam.value && typeof formparam.value === STRING) {
formparam.value = Buffer.from(formparam.value, 'base64');

return callback();
}

// handle missing file src
if (!formparam.src || (paramIsComposite && !formparam.src.length)) {
onLoadError(new Error('missing file source'), false);
Expand Down Expand Up @@ -188,6 +195,13 @@ module.exports = [
},
// file data
file (filedata, next) {
// handle base64 encoded file
if (!filedata.src && filedata.content && typeof filedata.content === STRING) {
filedata.content = Buffer.from(filedata.content, 'base64');

return next();
}

// eslint-disable-next-line security/detect-non-literal-fs-filename
util.createReadStream(resolver, filedata.src, function (err, stream) {
if (err) {
Expand Down
98 changes: 49 additions & 49 deletions package-lock.json

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

Loading

0 comments on commit 1a15029

Please sign in to comment.