Skip to content

Commit 3ee8d7c

Browse files
Merge pull request #758 from postmanlabs/release/v1.12.0
Release version v1.12.0
2 parents 5adb932 + 3f9955d commit 3ee8d7c

File tree

13 files changed

+356
-882
lines changed

13 files changed

+356
-882
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## [Unreleased]
44

5+
## [v1.12.0] - 2024-07-22
6+
7+
### Chore
8+
9+
- Updated postman-collection sdk to version 4.4.0 in missing codegens.
10+
11+
### Fixed
12+
13+
- Fix typo in Content-Header for audio/midi files in codegens.
14+
- Added support for NTLM auth support in cURL codegen.
15+
516
## [v1.11.0] - 2024-07-10
617

718
### Chore
@@ -159,7 +170,9 @@ v1.0.0 (May 29, 2020)
159170
- Add ES6 syntax support for NodeJS Request, NodeJS Native and NodeJS Unirest
160171
- Fix snippet generation for powershell and jquery, where form data params had no type field
161172

162-
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.11.0...HEAD
173+
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.12.0...HEAD
174+
175+
[v1.12.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.11.0...v1.12.0
163176

164177
[v1.11.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.10.1...v1.11.0
165178

codegens/curl/lib/index.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
var sanitize = require('./util').sanitize,
2-
sanitizeOptions = require('./util').sanitizeOptions,
3-
getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject,
4-
addFormParam = require('./util').addFormParam,
5-
form = require('./util').form,
6-
shouldAddHttpMethod = require('./util').shouldAddHttpMethod,
7-
_ = require('./lodash'),
8-
self;
1+
const {
2+
sanitize,
3+
sanitizeOptions,
4+
getUrlStringfromUrlObject,
5+
getNtlmAuthInfo,
6+
addFormParam,
7+
form,
8+
shouldAddHttpMethod
9+
} = require('./util'),
10+
_ = require('./lodash');
11+
12+
var self;
913

1014
self = module.exports = {
1115
convert: function (request, options, callback) {
@@ -16,7 +20,7 @@ self = module.exports = {
1620
options = sanitizeOptions(options, self.getOptions());
1721

1822
var indent, trim, headersData, body, redirect, timeout, multiLine,
19-
format, snippet, silent, url, quoteType;
23+
format, snippet, silent, url, quoteType, ntlmAuth;
2024

2125
redirect = options.followRedirect;
2226
timeout = options.requestTimeoutInSeconds;
@@ -26,9 +30,16 @@ self = module.exports = {
2630
silent = options.silent;
2731
quoteType = options.quoteType === 'single' ? '\'' : '"';
2832
url = getUrlStringfromUrlObject(request.url, quoteType);
33+
ntlmAuth = getNtlmAuthInfo(request.auth, quoteType, format);
2934

30-
snippet = silent ? `curl ${form('-s', format)}` : 'curl';
35+
snippet = 'curl';
3136

37+
if (ntlmAuth) {
38+
snippet += ntlmAuth;
39+
}
40+
if (silent) {
41+
snippet += ` ${form('-s', format)}`;
42+
}
3243
if (redirect) {
3344
snippet += ` ${form('-L', format)}`;
3445
}

codegens/curl/lib/util.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,49 @@ var self = module.exports = {
144144
},
145145

146146
/**
147-
*
148-
* @param {*} urlObject The request sdk request.url object
149-
* @param {boolean} quoteType The user given quoteType
150-
* @returns {String} The final string after parsing all the parameters of the url including
151-
* protocol, auth, host, port, path, query, hash
152-
* This will be used because the url.toString() method returned the URL with non encoded query string
153-
* and hence a manual call is made to getQueryString() method with encode option set as true.
154-
*/
147+
* Generates args required for NTLM authentication to happen
148+
*
149+
* @param {*} auth - The request sdk request.auth object
150+
* @param {string} quoteType - user provided option to decide whether to use single or double quotes
151+
* @param {string} format - user provided option to decide whether to use long format or not
152+
* @returns {string} - The string to be added if NTLM auth is required
153+
*/
154+
getNtlmAuthInfo: function (auth, quoteType, format) {
155+
const ntlmAuth = auth && auth.ntlm;
156+
157+
if (!auth || auth.type !== 'ntlm' || !ntlmAuth || !ntlmAuth.count || !ntlmAuth.count()) {
158+
return '';
159+
}
160+
161+
const username = ntlmAuth.has('username') && ntlmAuth.get('username'),
162+
password = ntlmAuth.has('password') && ntlmAuth.get('password'),
163+
domain = ntlmAuth.has('domain') && ntlmAuth.get('domain');
164+
165+
if (!username && !password) {
166+
return '';
167+
}
168+
169+
var userArg = format ? '--user ' : '-u ',
170+
ntlmString = ' --ntlm ' + userArg + quoteType;
171+
172+
if (domain) {
173+
ntlmString += self.sanitize(domain, true, quoteType) + '\\';
174+
}
175+
ntlmString += self.sanitize(username, true, quoteType) + ':' + self.sanitize(password, true, quoteType);
176+
ntlmString += quoteType;
177+
178+
return ntlmString;
179+
},
180+
181+
/**
182+
*
183+
* @param {*} urlObject The request sdk request.url object
184+
* @param {boolean} quoteType The user given quoteType
185+
* @returns {String} The final string after parsing all the parameters of the url including
186+
* protocol, auth, host, port, path, query, hash
187+
* This will be used because the url.toString() method returned the URL with non encoded query string
188+
* and hence a manual call is made to getQueryString() method with encode option set as true.
189+
*/
155190
getUrlStringfromUrlObject: function (urlObject, quoteType) {
156191
var url = '';
157192
if (!urlObject) {

codegens/curl/test/unit/convert.test.js

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var expect = require('chai').expect,
1+
var _ = require('lodash'),
2+
expect = require('chai').expect,
23
{ Request } = require('postman-collection/lib/collection/request'),
34
{ Url } = require('postman-collection/lib/collection/url'),
45
convert = require('../../index').convert,
@@ -1026,5 +1027,122 @@ describe('curl convert function', function () {
10261027
});
10271028
});
10281029
});
1030+
1031+
describe('should correctly handle NTLM auth', function () {
1032+
const sampleRequest = {
1033+
'method': 'POST',
1034+
'header': [],
1035+
'auth': {
1036+
'type': 'ntlm',
1037+
'ntlm': []
1038+
},
1039+
'url': {
1040+
'raw': 'https://postman-echo.com/post',
1041+
'protocol': 'https',
1042+
'host': [
1043+
'postman-echo',
1044+
'com'
1045+
],
1046+
'path': [
1047+
'post'
1048+
]
1049+
}
1050+
};
1051+
1052+
it('when no username or password is present', function () {
1053+
const request = new Request(sampleRequest);
1054+
1055+
convert(request, {}, function (error, snippet) {
1056+
if (error) {
1057+
expect.fail(null, null, error);
1058+
}
1059+
expect(snippet).to.be.a('string');
1060+
expect(snippet).to.not.include('--ntlm');
1061+
});
1062+
});
1063+
1064+
it('when empty username and password is present', function () {
1065+
const request = new Request(Object.assign({ auth: {
1066+
'type': 'ntlm',
1067+
'ntlm': [
1068+
{key: 'username', value: ''},
1069+
{key: 'password', value: ''}
1070+
]
1071+
}}, sampleRequest));
1072+
1073+
convert(request, {}, function (error, snippet) {
1074+
if (error) {
1075+
expect.fail(null, null, error);
1076+
}
1077+
expect(snippet).to.be.a('string');
1078+
expect(snippet).to.not.include('--ntlm');
1079+
});
1080+
});
1081+
1082+
it('when correct username and password is present with single quotes as option', function () {
1083+
const request = new Request(_.set(sampleRequest, 'auth.ntlm', [
1084+
{key: 'username', value: 'joh\'n'},
1085+
{key: 'password', value: 'tennesse"e'}
1086+
]));
1087+
1088+
convert(request, { quoteType: 'single' }, function (error, snippet) {
1089+
if (error) {
1090+
expect.fail(null, null, error);
1091+
}
1092+
expect(snippet).to.be.a('string');
1093+
expect(snippet).to.equal('curl --ntlm --user \'joh\'\\\'\'n:tennesse"e\' --location' +
1094+
' --request POST \'https://postman-echo.com/post\'');
1095+
});
1096+
});
1097+
1098+
it('when correct username and password is present with double as option', function () {
1099+
const request = new Request(_.set(sampleRequest, 'auth.ntlm', [
1100+
{key: 'username', value: 'joh\'n'},
1101+
{key: 'password', value: 'tennesse"e'}
1102+
]));
1103+
1104+
convert(request, { quoteType: 'double' }, function (error, snippet) {
1105+
if (error) {
1106+
expect.fail(null, null, error);
1107+
}
1108+
expect(snippet).to.be.a('string');
1109+
expect(snippet).to.equal('curl --ntlm --user "joh\'n:tennesse\\"e" --location' +
1110+
' --request POST "https://postman-echo.com/post"');
1111+
});
1112+
});
1113+
1114+
it('when correct username and password is present with long format option disabled', function () {
1115+
const request = new Request(_.set(sampleRequest, 'auth.ntlm', [
1116+
{key: 'username', value: 'joh\'n'},
1117+
{key: 'password', value: 'tennesse"e'}
1118+
]));
1119+
1120+
convert(request, { longFormat: false }, function (error, snippet) {
1121+
if (error) {
1122+
expect.fail(null, null, error);
1123+
}
1124+
expect(snippet).to.be.a('string');
1125+
expect(snippet).to.equal('curl --ntlm -u \'joh\'\\\'\'n:tennesse"e\' -L' +
1126+
' -X POST \'https://postman-echo.com/post\'');
1127+
});
1128+
});
1129+
1130+
it('when username and password is present with domain as well', function () {
1131+
const request = new Request(_.set(sampleRequest, 'auth.ntlm', [
1132+
{key: 'username', value: 'joh\'n'},
1133+
{key: 'password', value: 'tennesse"e'},
1134+
{key: 'domain', value: 'radio'}
1135+
]));
1136+
1137+
convert(request, {}, function (error, snippet) {
1138+
if (error) {
1139+
expect.fail(null, null, error);
1140+
}
1141+
expect(snippet).to.be.a('string');
1142+
expect(snippet).to.equal('curl --ntlm --user \'radio\\joh\'\\\'\'n:tennesse"e\' --location' +
1143+
' --request POST \'https://postman-echo.com/post\'');
1144+
});
1145+
});
1146+
});
10291147
});
10301148
});

codegens/http/lib/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var contentTypeHeaderMap = {
3636
'js': 'text/javascript',
3737
'json': 'application/json',
3838
'jsonld': 'application/ld+json',
39-
'mid': 'audip/midi',
39+
'mid': 'audio/midi',
4040
'midi': 'audio/midi',
4141
'mjs': 'text/javascript',
4242
'mp3': 'audio/mpeg',

0 commit comments

Comments
 (0)