Skip to content

Commit b9c38f3

Browse files
author
Dhwaneet Bhatt
committed
Merge branch 'release/v1.3.0'
2 parents 3d4b25b + 088d93d commit b9c38f3

File tree

7 files changed

+107
-27
lines changed

7 files changed

+107
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# cURL to Postman Importer Changelog
22

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

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

9+
#### v1.1.3 (February 03, 2023)
10+
* Fixed issue [#5182](https://github.com/postmanlabs/postman-app-support/issues/5182) where cURL in Windows cmd formats were not imported correctly.
11+
912
#### v1.1.2 (January 10, 2023)
1013
* Changed regex to check for prefix space in url with query parameters for given curl string
1114

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

1821
#### v1.0.0 (October 18, 2021)
19-
* Fixed issue where file references were not present in imported cURL.
22+
* Fixed issue where file references were not present in imported cURL.
2023
* Fixed issue where formdata value were not un-escaped correctly.
2124
* Fixed issue where raw formdata string with boundary were not converted as formdata body.
2225
* Fixed issue where escaped single character sequence were not correctly represented in request body.

assets/supportedOptions.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,23 @@ let supportedOptions = [
8787
},
8888
{
8989
long: '--basic',
90-
description: 'Overrides previous auth settings',
90+
description: 'Use HTTP Basic authentication',
91+
collectValues: false
92+
},
93+
{
94+
long: '--digest',
95+
description: 'Use HTTP Digest authentication',
96+
collectValues: false
97+
},
98+
{
99+
long: '--ntlm',
100+
description: 'Use NTLM Digest authentication',
91101
collectValues: false
92102
},
93103
{
94104
short: '-u',
95105
long: '--user',
96-
description: 'Basic auth ( -u <username:password>)',
106+
description: 'Username and password for server authentication',
97107
format: '[string]',
98108
collectValues: false
99109
}

assets/unnecessaryOptions.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ let unnecessaryOptions = [
1010
'--compressed',
1111
'--create-dirs',
1212
'--crlf',
13-
'--digest',
1413
'--disable-eprt',
1514
'--disable-epsv',
1615
'-q',
@@ -70,7 +69,6 @@ let unnecessaryOptions = [
7069
'--no-npn',
7170
'--no-sessionid',
7271
'--ntlm-wb',
73-
'--ntlm',
7472
'--parallel-max',
7573
'-Z',
7674
'--parallel',

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "curl-to-postmanv2",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Convert a given CURL command to a Postman request",
55
"main": "index.js",
66
"com_postman_plugin": {

src/lib.js

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,53 @@ var program,
195195
return retVal;
196196
},
197197

198+
/**
199+
* Generates the auth object for the request
200+
*
201+
* @param {Object} curlObj The curl object
202+
* @returns {Object} The auth object
203+
*/
204+
getAuth: function(curlObj) {
205+
let authObject;
206+
207+
// It is a valid cURL to have only username, in that case keep password empty
208+
const userParts = curlObj.user.split(':') || [];
209+
if (userParts.length === 1) {
210+
userParts[1] = '';
211+
}
212+
213+
if (curlObj.digest === true) {
214+
authObject = {
215+
type: 'digest',
216+
digest: [
217+
{ key: 'username', value: userParts[0], type: 'string' },
218+
{ key: 'password', value: userParts[1], type: 'string' }
219+
]
220+
};
221+
}
222+
else if (curlObj.ntlm === true) {
223+
authObject = {
224+
type: 'ntlm',
225+
ntlm: [
226+
{ key: 'username', value: userParts[0], type: 'string' },
227+
{ key: 'password', value: userParts[1], type: 'string' }
228+
]
229+
};
230+
}
231+
else {
232+
// Fallback to basic auth
233+
authObject = {
234+
type: 'basic',
235+
basic: [
236+
{ key: 'username', value: userParts[0], type: 'string' },
237+
{ key: 'password', value: userParts[1], type: 'string' }
238+
]
239+
};
240+
}
241+
242+
return authObject;
243+
},
244+
198245
resetProgram: function() {
199246
this.requestUrl = '';
200247
},
@@ -520,7 +567,6 @@ var program,
520567
sanitizedArgs,
521568
curlObj,
522569
request = {},
523-
basicAuthParts,
524570
content_type,
525571
urlData = '',
526572
bodyArr = [],
@@ -575,16 +621,7 @@ var program,
575621
request.body = {};
576622

577623
if (curlObj.user) {
578-
basicAuthParts = curlObj.user.split(':') || [];
579-
if (basicAuthParts.length >= 2) {
580-
request.auth = {
581-
type: 'basic',
582-
basic: [
583-
{ key: 'username', value: basicAuthParts[0], type: 'string' },
584-
{ key: 'password', value: basicAuthParts[1], type: 'string' }
585-
]
586-
};
587-
}
624+
request.auth = this.getAuth(curlObj);
588625
}
589626

590627
content_type = this.getLowerCaseHeader('content-type', this.headerPairs);

test/conversion.test.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,46 @@ describe('Curl converter should', function() {
235235
done();
236236
});
237237

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

241-
expect(result.auth.type).to.equal('basic');
242-
expect(result.auth.basic[0].key).to.equal('username');
243-
expect(result.auth.basic[1].key).to.equal('password');
242+
expect(result.auth.type).to.equal('basic');
243+
expect(result.auth.basic[0].key).to.equal('username');
244+
expect(result.auth.basic[0].value).to.equal('testUser');
245+
expect(result.auth.basic[1].key).to.equal('password');
246+
expect(result.auth.basic[1].value).to.equal('testPass');
247+
});
244248

245-
done();
249+
it('convert a simple GET request with Digest auth', function () {
250+
const result = Converter.convertCurlToRequest('curl -u testUser:testPass --digest "http://postman-echo.com/get"');
251+
252+
expect(result.auth.type).to.equal('digest');
253+
expect(result.auth.digest[0].key).to.equal('username');
254+
expect(result.auth.digest[0].value).to.equal('testUser');
255+
expect(result.auth.digest[1].key).to.equal('password');
256+
expect(result.auth.digest[1].value).to.equal('testPass');
257+
});
258+
259+
it('convert a simple GET request with NTLM auth', function () {
260+
const result = Converter.convertCurlToRequest('curl -u testUser:testPass --ntlm "http://postman-echo.com/get"');
261+
262+
expect(result.auth.type).to.equal('ntlm');
263+
expect(result.auth.ntlm[0].key).to.equal('username');
264+
expect(result.auth.ntlm[0].value).to.equal('testUser');
265+
expect(result.auth.ntlm[1].key).to.equal('password');
266+
expect(result.auth.ntlm[1].value).to.equal('testPass');
267+
});
268+
269+
it('convert a simple GET request with Basic auth with only username', function () {
270+
const result = Converter.convertCurlToRequest('curl -u testUser --url "http://postman-echo.com/get"');
271+
272+
expect(result.auth.type).to.equal('basic');
273+
expect(result.auth.basic[0].key).to.equal('username');
274+
expect(result.auth.basic[0].value).to.equal('testUser');
275+
expect(result.auth.basic[1].key).to.equal('password');
276+
expect(result.auth.basic[1].value).to.equal('');
277+
});
246278
});
247279

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

0 commit comments

Comments
 (0)