Skip to content

Commit

Permalink
Merge pull request #366 from zdoc01/strictssl-option
Browse files Browse the repository at this point in the history
Add support for strictSSL request option
  • Loading branch information
ttezel authored May 30, 2018
2 parents 899f326 + c1859f9 commit 26bb696
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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 @@ -479,6 +483,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

0 comments on commit 26bb696

Please sign in to comment.