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

Add support for strictSSL request option #366

Merged
merged 1 commit into from
May 30, 2018
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var T = new Twit({
access_token: '...',
access_token_secret: '...',
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
strictSSL: true, // optional - requires SSL certificates to be valid.
})

//
Expand Down
8 changes: 8 additions & 0 deletions lib/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ Twitter.prototype._buildReqOpts = function (method, path, params, isStreaming, c
reqOpts.timeout = self.config.timeout_ms;
}

if (typeof self.config.strictSSL !== 'undefined') {
reqOpts.strictSSL = self.config.strictSSL;
}

try {
// finalize the `path` value by building it using user-supplied params
path = helpers.moveParamsIntoPath(finalParams, path)
Expand Down Expand Up @@ -477,6 +481,10 @@ Twitter.prototype._validateConfigOrThrow = function (config) {
throw new TypeError('Twit config `timeout_ms` must be a Number. Got: ' + config.timeout_ms + '.');
}

if (typeof config.strictSSL !== 'undefined' && typeof config.strictSSL !== 'boolean') {
throw new TypeError('Twit config `strictSSL` must be a Boolean. Got: ' + config.strictSSL + '.');
}

if (config.app_only_auth) {
var auth_type = 'app-only auth'
var required_keys = required_for_app_auth
Expand Down
14 changes: 14 additions & 0 deletions tests/twit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ describe('twit', function () {

done()
})

it('throws when config provides invalid strictSSL option', function (done) {
assert.throws(function () {
var twit = new Twit({
consumer_key: 'a'
, consumer_secret: 'a'
, access_token: 'a'
, access_token_secret: 'a'
, strictSSL: 'a'
})
}, Error)

done()
})
})

describe('setAuth()', function () {
Expand Down