Skip to content

Commit

Permalink
Merge branch 'postmanlabs:develop' into fix/golang-ioutils
Browse files Browse the repository at this point in the history
  • Loading branch information
panapol-p authored Jul 28, 2024
2 parents f9bc785 + c9c7244 commit 21eb0b8
Show file tree
Hide file tree
Showing 60 changed files with 837 additions and 1,343 deletions.
27 changes: 22 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@

## [Unreleased]

## [v1.10.1] - 2024-05-06
## [v1.12.0] - 2024-07-22

### Chore

## [v1.10.0] - 2024-05-02
- Updated postman-collection sdk to version 4.4.0 in missing codegens.

### Fixed

- Fix typo in Content-Header for audio/midi files in codegens.
- Added support for NTLM auth support in cURL codegen.

## [v1.11.0] - 2024-07-10

### Chore

- Updated postman-collection to v4.4.0.

## [v1.10.1] - 2024-05-06

### Fixed

Expand Down Expand Up @@ -155,11 +170,13 @@ v1.0.0 (May 29, 2020)
- Add ES6 syntax support for NodeJS Request, NodeJS Native and NodeJS Unirest
- Fix snippet generation for powershell and jquery, where form data params had no type field

[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.10.1...HEAD
[Unreleased]: https://github.com/postmanlabs/postman-code-generators/compare/v1.12.0...HEAD

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

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

[v1.10.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.9.0...v1.10.0
[v1.10.1]: https://github.com/postmanlabs/postman-code-generators/compare/v1.10.0...v1.9.0

[v1.9.0]: https://github.com/postmanlabs/postman-code-generators/compare/v1.8.0...v1.9.0

Expand Down
32 changes: 16 additions & 16 deletions codegens/csharp-httpclient/test/unit/convert.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var expect = require('chai').expect,
sdk = require('postman-collection'),
{ Request } = require('postman-collection/lib/collection/request'),
convert = require('../../lib/index').convert,
mainCollection = require('./fixtures/testcollection/collection.json'),
testCollection = require('./fixtures/testcollection/collectionForEdge.json'),
Expand All @@ -13,7 +13,7 @@ describe('csharp httpclient function', function () {

describe('csharp-httpclient convert function', function () {
it('should return expected snippet', function () {
var request = new sdk.Request(mainCollection.item[10].request),
var request = new Request(mainCollection.item[10].request),
options = {
indentCount: 1,
indentType: 'Tab'
Expand All @@ -30,7 +30,7 @@ describe('csharp httpclient function', function () {
});

describe('convert function', function () {
var request = new sdk.Request(testCollection.item[0].request),
var request = new Request(testCollection.item[0].request),
snippetArray,
options = {
includeBoilerplate: true,
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('csharp httpclient function', function () {
});

it('should create custom HttpMethod when method is non-standard', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'NOTNORMAL',
'header': [],
'url': {
Expand All @@ -116,7 +116,7 @@ describe('csharp httpclient function', function () {
});

it('should add fake body when content type header added to empty body', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'DELETE',
'body': {},
'header': [
Expand All @@ -137,7 +137,7 @@ describe('csharp httpclient function', function () {
});

// it('should only include one System.IO using with multiple files', function () {
// var request = new sdk.Request({
// var request = new Request({
// 'method': 'POST',
// 'header': [],
// 'body': {
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('csharp httpclient function', function () {
// });

it('should include multiple form content when file has multiple sources', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'header': [],
'body': {
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('csharp httpclient function', function () {
});

it('should include graphql body in the snippet', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'header': [],
'body': {
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('csharp httpclient function', function () {
});

it('should add blank graphql variables when invalid', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'header': [],
'body': {
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('csharp httpclient function', function () {
});

it('should not add multiport form content when disabled', function () {
var request = new sdk.Request(mainCollection.item[15].request);
var request = new Request(mainCollection.item[15].request);
convert(request, {}, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
Expand All @@ -288,7 +288,7 @@ describe('csharp httpclient function', function () {
});

it('should run add content as string on raw request', function () {
var request = new sdk.Request(mainCollection.item[12].request);
var request = new Request(mainCollection.item[12].request);
convert(request, {}, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
Expand All @@ -303,7 +303,7 @@ describe('csharp httpclient function', function () {
});

it('should add a file on file request', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'url': 'https://google.com',
'header': [],
Expand All @@ -324,7 +324,7 @@ describe('csharp httpclient function', function () {
});

it('should add all enabled headers to request', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'url': 'https://postman-echo.com/post',
'header': [
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('csharp httpclient function', function () {
});

it('should skip disabled form url encoded values', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'header': [],
'url': 'https://postman-echo.com/post',
Expand Down Expand Up @@ -390,7 +390,7 @@ describe('csharp httpclient function', function () {
});

it('should skip collection initialization when no urlencoded values are enabled', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'header': [],
'url': 'https://postman-echo.com/post',
Expand All @@ -415,7 +415,7 @@ describe('csharp httpclient function', function () {
});

it('should skip creating multipart form data content when all values are disabled', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'header': [],
'url': 'https://postman-echo.com/post',
Expand Down
14 changes: 7 additions & 7 deletions codegens/csharp-restsharp/test/unit/convert.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var expect = require('chai').expect,
sdk = require('postman-collection'),
{ Request } = require('postman-collection/lib/collection/request'),
convert = require('../../lib/index').convert,
mainCollection = require('./fixtures/testcollection/collection.json'),
testCollection = require('./fixtures/testcollection/collectionForEdge.json'),
Expand All @@ -13,7 +13,7 @@ describe('csharp restsharp function', function () {

describe('csharp-restsharp convert function', function () {
it('should return expected snippet - Async', function () {
var request = new sdk.Request(mainCollection.item[4].request),
var request = new Request(mainCollection.item[4].request),
options = {
indentCount: 1,
indentType: 'Tab',
Expand All @@ -31,7 +31,7 @@ describe('csharp restsharp function', function () {
});

it('should return expected snippet json params', function () {
var request = new sdk.Request(mainCollection.item[5].request),
var request = new Request(mainCollection.item[5].request),
options = {
indentCount: 1,
indentType: 'Tab',
Expand All @@ -50,7 +50,7 @@ describe('csharp restsharp function', function () {
});

describe('convert function', function () {
var request = new sdk.Request(testCollection.item[0].request),
var request = new Request(testCollection.item[0].request),
snippetArray,
options = {
includeBoilerplate: true,
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('csharp restsharp function', function () {
});

it('should trim header keys and not trim header values', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'GET',
'header': [
{
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('csharp restsharp function', function () {
});

it('should generate snippets for no files in form data', function () {
var request = new sdk.Request({
var request = new Request({
'method': 'POST',
'header': [],
'body': {
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('csharp restsharp function', function () {
const sampleUA = 'Safari/605.1.15',
expectValue = `UserAgent = "${sampleUA}",`;

var request = new sdk.Request({
var request = new Request({
'method': 'GET',
'header': [
{
Expand Down
31 changes: 21 additions & 10 deletions codegens/curl/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
var sanitize = require('./util').sanitize,
sanitizeOptions = require('./util').sanitizeOptions,
getUrlStringfromUrlObject = require('./util').getUrlStringfromUrlObject,
addFormParam = require('./util').addFormParam,
form = require('./util').form,
shouldAddHttpMethod = require('./util').shouldAddHttpMethod,
_ = require('./lodash'),
self;
const {
sanitize,
sanitizeOptions,
getUrlStringfromUrlObject,
getNtlmAuthInfo,
addFormParam,
form,
shouldAddHttpMethod
} = require('./util'),
_ = require('./lodash');

var self;

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

var indent, trim, headersData, body, redirect, timeout, multiLine,
format, snippet, silent, url, quoteType;
format, snippet, silent, url, quoteType, ntlmAuth;

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

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

if (ntlmAuth) {
snippet += ntlmAuth;
}
if (silent) {
snippet += ` ${form('-s', format)}`;
}
if (redirect) {
snippet += ` ${form('-L', format)}`;
}
Expand Down
51 changes: 43 additions & 8 deletions codegens/curl/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,49 @@ var self = module.exports = {
},

/**
*
* @param {*} urlObject The request sdk request.url object
* @param {boolean} quoteType The user given quoteType
* @returns {String} The final string after parsing all the parameters of the url including
* protocol, auth, host, port, path, query, hash
* This will be used because the url.toString() method returned the URL with non encoded query string
* and hence a manual call is made to getQueryString() method with encode option set as true.
*/
* Generates args required for NTLM authentication to happen
*
* @param {*} auth - The request sdk request.auth object
* @param {string} quoteType - user provided option to decide whether to use single or double quotes
* @param {string} format - user provided option to decide whether to use long format or not
* @returns {string} - The string to be added if NTLM auth is required
*/
getNtlmAuthInfo: function (auth, quoteType, format) {
const ntlmAuth = auth && auth.ntlm;

if (!auth || auth.type !== 'ntlm' || !ntlmAuth || !ntlmAuth.count || !ntlmAuth.count()) {
return '';
}

const username = ntlmAuth.has('username') && ntlmAuth.get('username'),
password = ntlmAuth.has('password') && ntlmAuth.get('password'),
domain = ntlmAuth.has('domain') && ntlmAuth.get('domain');

if (!username && !password) {
return '';
}

var userArg = format ? '--user ' : '-u ',
ntlmString = ' --ntlm ' + userArg + quoteType;

if (domain) {
ntlmString += self.sanitize(domain, true, quoteType) + '\\';
}
ntlmString += self.sanitize(username, true, quoteType) + ':' + self.sanitize(password, true, quoteType);
ntlmString += quoteType;

return ntlmString;
},

/**
*
* @param {*} urlObject The request sdk request.url object
* @param {boolean} quoteType The user given quoteType
* @returns {String} The final string after parsing all the parameters of the url including
* protocol, auth, host, port, path, query, hash
* This will be used because the url.toString() method returned the URL with non encoded query string
* and hence a manual call is made to getQueryString() method with encode option set as true.
*/
getUrlStringfromUrlObject: function (urlObject, quoteType) {
var url = '';
if (!urlObject) {
Expand Down
Loading

0 comments on commit 21eb0b8

Please sign in to comment.