Skip to content

Commit

Permalink
rename ssl client certs options into --ssl-client-cert-list and add a…
Browse files Browse the repository at this point in the history
…n example of ssl client cert list
  • Loading branch information
chengchengmu committed Feb 21, 2020
1 parent e547143 commit 7efa7c8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ Newman supports SSL client certificates, via the following CLI options (availabl

#### Use a ssl client certificates configuration file (supports multiple certificates per run)

- --ssl-client-certs<br/>
The path to the ssl client certs configuration file (json format). See [examples/multiple-ssl-client-certs.json](https://github.com/postmanlabs/newman/blob/develop/examples/multiple-ssl-client-certs.json)
- --ssl-client-cert-list<br/>
The path to the ssl client certificate list configuration file (json format). See [examples/ssl-client-cert-list.json](https://github.com/postmanlabs/newman/blob/develop/examples/ssl-client-cert-list.json)
This option allows multiple ssl client certificiates and different ssl client certificate per url or hostname.
This option and --ssl-client-cert, --ssl-client-key and --ssl-client-passphrase are exclusives.

Expand Down
2 changes: 1 addition & 1 deletion bin/newman.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ program
.option('--timeout-script [n]', 'Specify a timeout for script (in milliseconds).', util.cast.integer, 0)
.option('--ignore-redirects', 'If present, Newman will not follow HTTP Redirects.')
.option('-k, --insecure', 'Disables SSL validations.')
.option('--ssl-client-certs <path>',
.option('--ssl-client-cert-list <path>',
'Specify the path to the Client SSL certificates configuration file (json format).' +
'\nThis option different ssl client certificate per url/hostname.' +
'\nThis option and --ssl-client-cert, --ssl-client-key and --ssl-client-passphrase are exclusives.')
Expand Down
16 changes: 16 additions & 0 deletions examples/ssl-client-cert-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"name": "domain1",
"matches": ["https://test.domain1.com/*", "https://www.domain1/*"],
"key": {"src": "./client.domain1.key"},
"cert": {"src": "./client.domain1.crt"},
"passphrase": "changeme"
},
{
"name": "domain2",
"matches": ["https://domain2.com/*"],
"key": {"src": "./client.domain2.key"},
"cert": {"src": "./client.domain2.crt"},
"passphrase": "changeme"
}
]
16 changes: 8 additions & 8 deletions lib/run/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,29 @@ module.exports = function (options, callback) {
// to store the exported content from reporters
emitter.exports = [];

let secureFileResolver, sslClientCerts;
let secureFileResolver, sslClientCertList;

secureFileResolver = new SecureFS(options.workingDir, options.insecureFileRead);
sslClientCerts = [];
sslClientCertList = [];

if (options.sslClientCert && options.sslClientCerts) {
if (options.sslClientCert && options.sslClientCertList) {
err = 'newman: too many ssl client cert options: use only one of them.';

return callback(new Error(err));
}

// new client certificate option that manages client certificate <-> url mapping
if (options.sslClientCerts) {
if (options.sslClientCertList) {
try {
sslClientCerts = JSON.parse(secureFileResolver.readFileSync(options.sslClientCerts));
sslClientCertList = JSON.parse(secureFileResolver.readFileSync(options.sslClientCertList));
}
catch (error) {
return callback(new Error('newman: unable to read the ssl client certificates file'));
}
}
// keeping this option to pass one client certificate for all urls
if (options.sslClientCert) {
sslClientCerts = [{
sslClientCertList = [{
name: 'client-cert',
matches: [sdk.UrlMatchPattern.MATCH_ALL_URLS],
key: { src: options.sslClientKey },
Expand Down Expand Up @@ -193,8 +193,8 @@ module.exports = function (options, callback) {
timings: Boolean(options.verbose),
extendedRootCA: options.sslExtraCaCerts
},
certificates: (options.sslClientCerts || options.sslClientCert) &&
new sdk.CertificateList({}, sslClientCerts)
certificates: (options.sslClientCertList || options.sslClientCert) &&
new sdk.CertificateList({}, sslClientCertList)
}, function (err, run) {
if (err) { return callback(err); }

Expand Down
4 changes: 2 additions & 2 deletions test/cli/ssl-client-cert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ describe('SSL Client certificates', function () {

it('should not work when both client certificate options are used', function (done) {
// eslint-disable-next-line max-len
exec('node ./bin/newman.js run test/fixtures/run/multiple-ssl-client-certs.json --ssl-client-certs test/fixtures/ssl/sslClientCerts.json --ssl-client-cert test/fixtures/ssl/client.crt --ssl-client-key test/fixtures/ssl/client.key --ssl-client-passphrase password -k', function (code) {
exec('node ./bin/newman.js run test/fixtures/run/ssl-client-cert-list.json --ssl-client-cert-list test/fixtures/ssl/sslClientCertList.json --ssl-client-cert test/fixtures/ssl/client.crt --ssl-client-key test/fixtures/ssl/client.key --ssl-client-passphrase password -k', function (code) {
expect(code, 'should have exit code different than 0').to.not.equal(0);
done();
});
});

it('should work correctly with multiple client certificates', function (done) {
// eslint-disable-next-line max-len
exec('node ./bin/newman.js run test/fixtures/run/multiple-ssl-client-certs.json --verbose --ssl-client-certs ./test/fixtures/ssl/sslClientCerts.json -k', function (code) {
exec('node ./bin/newman.js run test/fixtures/run/ssl-client-cert-list.json --verbose --ssl-client-cert-list ./test/fixtures/ssl/sslClientCertList.json -k', function (code) {
expect(code, 'should have exit code of 0').to.equal(0);
done();
});
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/library/ssl-client-cert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ describe('SSL Client certificates', function () {

it('should work correctly with multiple client certificates', function (done) {
newman.run({
collection: 'test/fixtures/run/multiple-ssl-client-certs.json',
sslClientCerts: 'test/fixtures/ssl/sslClientCerts.json',
collection: 'test/fixtures/run/ssl-client-cert-list.json',
sslClientCertList: 'test/fixtures/ssl/sslClientCertList.json',
insecure: true
}, done);
});
Expand Down

0 comments on commit 7efa7c8

Please sign in to comment.