Skip to content

Commit

Permalink
Merge branch 'release/v1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhwaneet Bhatt committed Mar 2, 2023
2 parents 3d4b25b + 088d93d commit b9c38f3
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 27 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# cURL to Postman Importer Changelog

#### v1.1.3 (February 03, 2023)
* Fixed issue [#5182](https://github.com/postmanlabs/postman-app-support/issues/5182) where cURL in Windows cmd formats were not imported correctly.
#### v1.3.0 (March 02, 2023)
* Fix for [#8087](https://github.com/postmanlabs/postman-app-support/issues/8087) - Add support to convert digest and NTLM auth types

#### v1.2.0 (February 07, 2023)
* Fix an issue where a correct error is thrown if curl string has invalid args

#### v1.1.3 (February 03, 2023)
* Fixed issue [#5182](https://github.com/postmanlabs/postman-app-support/issues/5182) where cURL in Windows cmd formats were not imported correctly.

#### v1.1.2 (January 10, 2023)
* Changed regex to check for prefix space in url with query parameters for given curl string

Expand All @@ -16,7 +19,7 @@
* Fixes #8433 - non-apostrophed ('...') url with multiple params support in cURL import.

#### v1.0.0 (October 18, 2021)
* Fixed issue where file references were not present in imported cURL.
* Fixed issue where file references were not present in imported cURL.
* Fixed issue where formdata value were not un-escaped correctly.
* Fixed issue where raw formdata string with boundary were not converted as formdata body.
* Fixed issue where escaped single character sequence were not correctly represented in request body.
Expand Down
14 changes: 12 additions & 2 deletions assets/supportedOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,23 @@ let supportedOptions = [
},
{
long: '--basic',
description: 'Overrides previous auth settings',
description: 'Use HTTP Basic authentication',
collectValues: false
},
{
long: '--digest',
description: 'Use HTTP Digest authentication',
collectValues: false
},
{
long: '--ntlm',
description: 'Use NTLM Digest authentication',
collectValues: false
},
{
short: '-u',
long: '--user',
description: 'Basic auth ( -u <username:password>)',
description: 'Username and password for server authentication',
format: '[string]',
collectValues: false
}
Expand Down
2 changes: 0 additions & 2 deletions assets/unnecessaryOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ let unnecessaryOptions = [
'--compressed',
'--create-dirs',
'--crlf',
'--digest',
'--disable-eprt',
'--disable-epsv',
'-q',
Expand Down Expand Up @@ -70,7 +69,6 @@ let unnecessaryOptions = [
'--no-npn',
'--no-sessionid',
'--ntlm-wb',
'--ntlm',
'--parallel-max',
'-Z',
'--parallel',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "curl-to-postmanv2",
"version": "1.2.0",
"version": "1.3.0",
"description": "Convert a given CURL command to a Postman request",
"main": "index.js",
"com_postman_plugin": {
Expand Down
59 changes: 48 additions & 11 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,53 @@ var program,
return retVal;
},

/**
* Generates the auth object for the request
*
* @param {Object} curlObj The curl object
* @returns {Object} The auth object
*/
getAuth: function(curlObj) {
let authObject;

// It is a valid cURL to have only username, in that case keep password empty
const userParts = curlObj.user.split(':') || [];
if (userParts.length === 1) {
userParts[1] = '';
}

if (curlObj.digest === true) {
authObject = {
type: 'digest',
digest: [
{ key: 'username', value: userParts[0], type: 'string' },
{ key: 'password', value: userParts[1], type: 'string' }
]
};
}
else if (curlObj.ntlm === true) {
authObject = {
type: 'ntlm',
ntlm: [
{ key: 'username', value: userParts[0], type: 'string' },
{ key: 'password', value: userParts[1], type: 'string' }
]
};
}
else {
// Fallback to basic auth
authObject = {
type: 'basic',
basic: [
{ key: 'username', value: userParts[0], type: 'string' },
{ key: 'password', value: userParts[1], type: 'string' }
]
};
}

return authObject;
},

resetProgram: function() {
this.requestUrl = '';
},
Expand Down Expand Up @@ -520,7 +567,6 @@ var program,
sanitizedArgs,
curlObj,
request = {},
basicAuthParts,
content_type,
urlData = '',
bodyArr = [],
Expand Down Expand Up @@ -575,16 +621,7 @@ var program,
request.body = {};

if (curlObj.user) {
basicAuthParts = curlObj.user.split(':') || [];
if (basicAuthParts.length >= 2) {
request.auth = {
type: 'basic',
basic: [
{ key: 'username', value: basicAuthParts[0], type: 'string' },
{ key: 'password', value: basicAuthParts[1], type: 'string' }
]
};
}
request.auth = this.getAuth(curlObj);
}

content_type = this.getLowerCaseHeader('content-type', this.headerPairs);
Expand Down
46 changes: 39 additions & 7 deletions test/conversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,46 @@ describe('Curl converter should', function() {
done();
});

it('convert a simple GET request with Basic auth', function (done) {
var result = Converter.convertCurlToRequest('curl --request GET -u testUser:testPass --url http://www.google.com');
describe('auth', function () {
it('convert a simple GET request with Basic auth', function () {
const result = Converter.convertCurlToRequest('curl -u testUser:testPass --url "http://postman-echo.com/get"');

expect(result.auth.type).to.equal('basic');
expect(result.auth.basic[0].key).to.equal('username');
expect(result.auth.basic[1].key).to.equal('password');
expect(result.auth.type).to.equal('basic');
expect(result.auth.basic[0].key).to.equal('username');
expect(result.auth.basic[0].value).to.equal('testUser');
expect(result.auth.basic[1].key).to.equal('password');
expect(result.auth.basic[1].value).to.equal('testPass');
});

done();
it('convert a simple GET request with Digest auth', function () {
const result = Converter.convertCurlToRequest('curl -u testUser:testPass --digest "http://postman-echo.com/get"');

expect(result.auth.type).to.equal('digest');
expect(result.auth.digest[0].key).to.equal('username');
expect(result.auth.digest[0].value).to.equal('testUser');
expect(result.auth.digest[1].key).to.equal('password');
expect(result.auth.digest[1].value).to.equal('testPass');
});

it('convert a simple GET request with NTLM auth', function () {
const result = Converter.convertCurlToRequest('curl -u testUser:testPass --ntlm "http://postman-echo.com/get"');

expect(result.auth.type).to.equal('ntlm');
expect(result.auth.ntlm[0].key).to.equal('username');
expect(result.auth.ntlm[0].value).to.equal('testUser');
expect(result.auth.ntlm[1].key).to.equal('password');
expect(result.auth.ntlm[1].value).to.equal('testPass');
});

it('convert a simple GET request with Basic auth with only username', function () {
const result = Converter.convertCurlToRequest('curl -u testUser --url "http://postman-echo.com/get"');

expect(result.auth.type).to.equal('basic');
expect(result.auth.basic[0].key).to.equal('username');
expect(result.auth.basic[0].value).to.equal('testUser');
expect(result.auth.basic[1].key).to.equal('password');
expect(result.auth.basic[1].value).to.equal('');
});
});

it('convert a request with a forced POST', function (done) {
Expand Down Expand Up @@ -896,7 +928,7 @@ describe('Curl converter should', function() {
}, function (err, result) {
expect(result.result).to.equal(false);
expect(result.reason).to.equal(
'Only the URL can be provided without an option preceding it.All other inputs must be specified via options.'
'Only the URL can be provided without an option preceding it. All other inputs must be specified via options.'
);
done();
});
Expand Down

0 comments on commit b9c38f3

Please sign in to comment.