Skip to content

Commit cf5c072

Browse files
authored
Merge pull request #84 from postmanlabs/release/v1.8.2
Release version v1.8.2
2 parents 6d6a626 + 9e88080 commit cf5c072

File tree

6 files changed

+109
-6
lines changed

6 files changed

+109
-6
lines changed

CHANGELOG.md

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

33
## [Unreleased]
44

5+
## [v1.8.2] - 2025-02-20
6+
7+
### Added
8+
9+
- [#13455](https://github.com/postmanlabs/postman-app-support/issues/13455) Added support for -b and --cookie options and create relavant cookie header.
10+
511
## [v1.8.1] - 2024-04-17
612

713
### Added
@@ -128,7 +134,9 @@ Newer releases follow the [Keep a Changelog](https://keepachangelog.com) format.
128134
- Conforming to the internal Postman plugin interface
129135
- Fixes for Github issues - 4770,3623,3135,4018,5737,5286, among others
130136

131-
[Unreleased]: https://github.com/postmanlabs/curl-to-postman/compare/v1.8.1...HEAD
137+
[Unreleased]: https://github.com/postmanlabs/curl-to-postman/compare/v1.8.2...HEAD
138+
139+
[v1.8.2]: https://github.com/postmanlabs/curl-to-postman/compare/v1.8.1...v1.8.2
132140

133141
[v1.8.1]: https://github.com/postmanlabs/curl-to-postman/compare/v1.8.0...v1.8.1
134142

assets/supportedOptions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ let supportedOptions = [
106106
description: 'Username and password for server authentication',
107107
format: '[string]',
108108
collectValues: false
109+
},
110+
{
111+
short: '-b',
112+
long: '--cookie',
113+
description: 'Specifies cookies to be used in the format "NAME=VALUE" or a file to read cookies from',
114+
format: '[string]',
115+
collectValues: true
109116
}
110117
];
111118
module.exports = supportedOptions;

package-lock.json

Lines changed: 2 additions & 2 deletions
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.8.1",
3+
"version": "1.8.2",
44
"description": "Convert a given CURL command to a Postman request",
55
"main": "index.js",
66
"com_postman_plugin": {

src/lib.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const commander = require('commander'),
1818
[REQUEST_BODY_LANGUAGE_JAVASCRIPT]: /^(text|application)\/(\S+\+)?javascript/,
1919
[REQUEST_BODY_LANGUAGE_XML]: /^(text|application)\/(\S+\+)?xml/,
2020
[REQUEST_BODY_LANGUAGE_HTML]: /^text\/html/
21-
};
21+
},
22+
ALLOWED_DUPLICATE_HEADERS = ['cookie'];
2223

2324
var program,
2425

@@ -177,6 +178,13 @@ var program,
177178
});
178179
}
179180

181+
// If any cookies are added under -b or --cookie arg, add them as Cookie header
182+
if (curlObj.cookie && Array.isArray(curlObj.cookie)) {
183+
curlObj.cookie.forEach((cookieVal) => {
184+
headerArray.push('Cookie: ' + this.trimQuotesFromString(cookieVal));
185+
});
186+
}
187+
180188
if (headerArray === null || headerArray.length === 0) {
181189
return retVal;
182190
}
@@ -210,7 +218,7 @@ var program,
210218
value = thisHeader.substring(keyIndex + 1, thisHeader.length).trim();
211219
/* eslint-enable */
212220

213-
if (this.headerPairs.hasOwnProperty(key)) {
221+
if (this.headerPairs.hasOwnProperty(key) && !ALLOWED_DUPLICATE_HEADERS.includes(key.toLowerCase())) {
214222
// don't add the same header twice
215223
continue;
216224
}

test/conversion.test.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,4 +1444,84 @@ describe('Curl converter should', function() {
14441444
});
14451445
});
14461446
});
1447+
1448+
describe('It should correctly generate request with cookie header', function() {
1449+
it('containing -b option', function(done) {
1450+
convert({
1451+
type: 'string',
1452+
data: `curl 'https://httpbin.org/anything' \
1453+
-b 'dashboard_beta=yes; postman-beta.track=default' \
1454+
-H 'authority: httpbin.org'
1455+
--data "{\"context\":{\"client\":{\"hl\":\"en\"}},\"state\":true}"
1456+
`
1457+
}, function (err, result) {
1458+
expect(result.result).to.equal(true);
1459+
expect(result.output.length).to.equal(1);
1460+
expect(result.output[0].type).to.equal('request');
1461+
expect(result.output[0].data.url).to.equal('https://httpbin.org/anything');
1462+
expect(result.output[0].data.method).to.equal('POST');
1463+
1464+
const headerArr = result.output[0].data.header;
1465+
expect(headerArr.length).to.equal(2);
1466+
expect(headerArr[0].key).to.equal('authority');
1467+
expect(headerArr[0].value).to.equal('httpbin.org');
1468+
expect(headerArr[1].key).to.equal('Cookie');
1469+
expect(headerArr[1].value).to.equal('dashboard_beta=yes; postman-beta.track=default');
1470+
done();
1471+
});
1472+
});
1473+
1474+
it('containing --cookie option', function(done) {
1475+
convert({
1476+
type: 'string',
1477+
data: `curl 'https://httpbin.org/anything' \
1478+
--cookie 'dashboard_beta=yes; postman-beta.track=default' \
1479+
-H 'authority: httpbin.org'
1480+
--data "{\"context\":{\"client\":{\"hl\":\"en\"}},\"state\":true}"
1481+
`
1482+
}, function (err, result) {
1483+
expect(result.result).to.equal(true);
1484+
expect(result.output.length).to.equal(1);
1485+
expect(result.output[0].type).to.equal('request');
1486+
expect(result.output[0].data.url).to.equal('https://httpbin.org/anything');
1487+
expect(result.output[0].data.method).to.equal('POST');
1488+
1489+
const headerArr = result.output[0].data.header;
1490+
expect(headerArr.length).to.equal(2);
1491+
expect(headerArr[0].key).to.equal('authority');
1492+
expect(headerArr[0].value).to.equal('httpbin.org');
1493+
expect(headerArr[1].key).to.equal('Cookie');
1494+
expect(headerArr[1].value).to.equal('dashboard_beta=yes; postman-beta.track=default');
1495+
done();
1496+
});
1497+
});
1498+
1499+
it('containing multiple cookies', function(done) {
1500+
convert({
1501+
type: 'string',
1502+
data: `curl 'https://httpbin.org/anything' \
1503+
-b 'dashboard_beta=yes; postman-beta.track=default' \
1504+
-b 'name=JohnDoe' \
1505+
-H 'authority: httpbin.org' \
1506+
--data "{\"context\":{\"client\":{\"hl\":\"en\"}},\"state\":true}"
1507+
`
1508+
}, function (err, result) {
1509+
expect(result.result).to.equal(true);
1510+
expect(result.output.length).to.equal(1);
1511+
expect(result.output[0].type).to.equal('request');
1512+
expect(result.output[0].data.url).to.equal('https://httpbin.org/anything');
1513+
expect(result.output[0].data.method).to.equal('POST');
1514+
1515+
const headerArr = result.output[0].data.header;
1516+
expect(headerArr.length).to.equal(3);
1517+
expect(headerArr[0].key).to.equal('authority');
1518+
expect(headerArr[0].value).to.equal('httpbin.org');
1519+
expect(headerArr[1].key).to.equal('Cookie');
1520+
expect(headerArr[1].value).to.equal('dashboard_beta=yes; postman-beta.track=default');
1521+
expect(headerArr[2].key).to.equal('Cookie');
1522+
expect(headerArr[2].value).to.equal('name=JohnDoe');
1523+
done();
1524+
});
1525+
});
1526+
});
14471527
});

0 commit comments

Comments
 (0)