Skip to content
New issue

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

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

Already on GitHub? Sign in 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 all commits
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
47 changes: 47 additions & 0 deletions tests/request.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import axios from 'axios';
import { expect } from 'chai';

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

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

const uri = 'https://foo/bar';
const originalAxiosRequest = axios.request;
const mockedAxiosRequest = (options) => {
return Promise.resolve(options);
};
before(() => {
axios.request = mockedAxiosRequest;
});

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);
});
});
});
});
});