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 validateSslCertificate to node client #354

Merged
merged 3 commits into from
Jun 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/rest/Twilio.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ Twilio.prototype.request = function request(opts) {
});
};

/* jshint ignore:start */
/**
* Validate that a request to the new SSL certificate is successful.
* @throws {RestException} if the request fails
*/
/* jshint ignore:end */
Twilio.prototype.validateSslCert = function validateSslCert() {
return this.httpClient.request({
method: 'GET',
uri: 'https://api.twilio.com:8443/2010-04-01/.json',
}).then((response) => {
if (response.statusCode < 200 || response.statusCode >= 300) {
throw RestException(response);
}

return response;
});
};

Object.defineProperty(Twilio.prototype,
'accounts', {
get: function() {
Expand Down
44 changes: 44 additions & 0 deletions spec/integration/rest/Twilio.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
var proxyquire = require('proxyquire');
var _ = require('lodash'); /* jshint ignore:line */
var Holodeck = require('../holodeck'); /* jshint ignore:line */
var Response = require(
'../../../lib/http/response'); /* jshint ignore:line */
var RestException = require(
'../../../lib/base/RestException'); /* jshint ignore:line */
var Twilio = require('../../../lib'); /* jshint ignore:line */

var client;
var holodeck;

describe('validateSslCert', function() {
beforeEach(function() {
holodeck = new Holodeck();
client = new Twilio('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'AUTHTOKEN', {
httpClient: holodeck,
});
});

it('Should successfully validate a working SSL certificate', function() {
holodeck.mock(new Response(200, ''));

let resp = client.validateSslCert();

resp.finally(() => {
expect(resp.isFulfilled()).toBe(true);
done();

});
});

it('should fail to validate a broken SSL certificate', function(done) {
holodeck.mock(new Response(504, ''));

let resp = client.validateSslCert();

resp.finally(() => {
expect(resp.isRejected()).toBe(true);
done();
});
});
});