Behat: Setting cURL options with Guzzle and Goutte

If when running your Behat tests on a https website you ever seen these errors:

[curl] 51: SSL: certificate subject name ‘ubuntu’ does not match target host name ‘mycoolwebsite’

or

[curl] 60: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [url]

then you might want to set up Guzzle (PHP HTTP client and framework) and Goutte (screen scraping and web crawling library for PHP) in a way that it ignores strict SSL rules.

When you use Mink Goutte browser emulator it uses Guzzle to make requests and that actually uses cURL to archive that. To pass cURL parameters to Goutte you need to add them into curl.options section of default/extensions/Behat\MinkExtension\Extension/goutte/guzzle_parameters. You will need to set ssl.certificate_authority to system as well, otherwise the Guzzle\Http\Client::initSsl will reset CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER parameters to some other values.

So let’s modify your behat.yml according to this:

    default:
      extensions:
        Behat\MinkExtension\Extension:
          goutte:
            guzzle_parameters:
              curl.options:
                 CURLOPT_SSL_VERIFYPEER: 0
                 CURLOPT_CERTINFO: 0
                 CURLOPT_SSL_VERIFYHOST: 0
              ssl.certificate_authority: system

After this pull request https://github.com/guzzle/guzzle/pull/498 will get merged you will be able to just do:

    default:
      extensions:
        Behat\MinkExtension\Extension:
          goutte:
            guzzle_parameters:
              ssl.certificate_authority: false

After that you won’t see any SSL errors. Bingo!

This was tested with behat v2.5.1, mink-goutte-driver v1.0.9 and guzzle v3.7.4.

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

CAPTCHA image
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">