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

Support SSL certificates #913

Open
marc0l92 opened this issue Nov 11, 2017 · 4 comments
Open

Support SSL certificates #913

marc0l92 opened this issue Nov 11, 2017 · 4 comments

Comments

@marc0l92
Copy link

The request library used to query the server allows to specify several client options. Some of them are related to the client certificate, the self-signed certificate validation and others.

It is possible to make this option configurable from the hook script or from the command line?

Possible dirty solution

In order to use your applicaiton with a http server with self signed certificate I added this line in the file lib/transaction-runner.js:

88:      return function() {
89:        if (_this.hookHandlerError) {
90:          return callback(_this.hookHandlerError);
91:        }
->         if(hooks.configuration) _this.configuration.http = hooks.configuration.http;
92:        return async.timesSeries(transactions.length, function(transactionIndex, iterationCallback) {
93:          transaction = transactions[transactionIndex];
94:          logger.verbose("Processing transaction #" + (transactionIndex + 1) + ":", transaction.name);
95:          logger.verbose('Running \'beforeEach\' hooks');

With this change I can now configure the request library options from my hook file:

...
hooks.beforeAll(function (transactions, done) {
  // Allow server self-signed certificates
  hooks.configuration.http.rejectUnauthorized = false;
  // Set client certificate
  hooks.configuration.http.cert = fs.readFileSync(certFile);
  hooks.configuration.http.key = fs.readFileSync(keyFile);
  done();
});
...
@honzajavorek
Copy link
Contributor

I would be quite cautious exposing the whole options, but from the description I understand you need it primarily for testing an API with complex SSL setup - certs, keys, etc. This would be related to #323. Let me rename your issue to "Support SSL certificates".

@honzajavorek honzajavorek changed the title Expose "request" options to hook scripts Support SSL certificates Nov 13, 2017
@marc0l92
Copy link
Author

Yes, you are right about the exposing of the whole options object.
I have done this only to have access to the SSL setup using one line of code.

@JonKohler
Copy link

I just added this.configuration.http.rejectUnauthorized = false, in the following code block, to dredd.js and that unblocked me. Figured I'd drop this in here for others running into this challenge.

  // This is here only because there there is no way how to spy a constructor in CoffeScript
  init(config) {
    this.configuration = applyConfiguration(config);
    this.configuration.http = {};
    this.configuration.http.rejectUnauthorized = false
    this.tests = [];
    this.stats = {

@abtris
Copy link
Contributor

abtris commented Apr 15, 2018

You don’t need change code, just set env variable as dirty hack.

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants