imbo / behat-api-extension

API extension for Behat, used to ease testing of JSON-based APIs
MIT License
109 stars 42 forks source link

SSL verify = false #65

Closed vitalyiegorov closed 6 years ago

vitalyiegorov commented 6 years ago

@christeredvartsen We want to use this extension within local development and we are facing:

cURL error 60: SSL certificate problem: self signed certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) (GuzzleHttp\Exception\RequestException)

Any workaround for this?

christeredvartsen commented 6 years ago

Currently I think you would have to do that through a middleware. If you override setClient in your feature context class you could do something like this:

<?php
use Imbo\BehatApiExtension\Context\ApiContext;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\RequestInterface;

class FeatureContext extends ApiContext {
    public function setClient(ClientInterface $client) {
        $client->getConfig('handler')->push(function(callable $handler) {
            return function(RequestInterface $request, array $options) use ($handler) {
                $options['verify'] = false;
                return $handler($request, $options);
            };
        });

        return parent::setClient($client);
    }
}

I haven't tested the code above, but I think it might work as expected.

It would probably be a good idea to expose the configuration for the client in the extension configuration though...

If the snippet works and you feel it's an adequate solution to your problem please close the issue.

vitalyiegorov commented 6 years ago

@christeredvartsen Added PR #66