Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix #139 strictSsl: false option being ignored #146

Merged
merged 2 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wrappers/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export default function(options, cb) {
};
}

if (options.agentOptions || options.strictSSL) {
if (options.agentOptions || options.strictSSL != undefined) {
const agentOptions = {
...(options.strictSSL) && { rejectUnauthorized: options.strictSSL },
...(options.strictSSL != undefined) && { rejectUnauthorized: options.strictSSL },
...options.agentOptions
};
requestOptions.httpAgent = new http.Agent(agentOptions);
Expand Down
46 changes: 46 additions & 0 deletions tests/request.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import axios from 'axios';
import { expect } from 'chai';

const originalAxiosRequest = axios.request;
const mockedAxiosRequest = (options) => {
return Promise.resolve(options);
};
axios.request = mockedAxiosRequest;

import request from '../src/wrappers/request';

describe('Request wrapper tests', () => {

const uri = 'https://foo/bar';

after(() => {
axios.request = originalAxiosRequest;
});

describe('default export', () => {
describe('should pass through strictSSL option properly', () => {
it('should create agentOptions if strictSSL === true', (done) => {
request({ uri, strictSSL: true }, (err, options) => {
expect(options.httpsAgent).to.be.defined;
expect(options.httpsAgent.options.rejectUnauthorized).to.be.true;
done(err);
});
});

it('should create agentOptions if strictSSL === false', (done) => {
request({ uri, strictSSL: false }, (err, options) => {
expect(options.httpsAgent).to.be.defined;
expect(options.httpsAgent.options.rejectUnauthorized).to.be.false;
done(err);
});
});

it('should not create agentOptions if strictSSL === undefined', (done) => {
request({ uri }, (err, options) => {
expect(options.httpsAgent).to.be.undefined;
done(err);
});
});
});
});
});