Search code examples
restseleniumdrupal-7behat

Behat selenium tests trust self signed SSL cerificate


For our automated testing of our Drupal site, we are using Behat test scripts. On our local development machines we are using a self signed SSL certificate that is created by Acquia Devdesktop. Running the tests in the different browsers with Behat is no problem since you can trust the certificate in the browser itself. However for the REST interfaces where no browser is being opened it is a different story. Behat will not accept the self signed certificate since it is "unsecure".

When running the REST test this is the error we get:

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

With the testcase itself is nothing wrong because it worked before we enabled the SSL certificate. We tried to edit the configuration .yml file with the options from the documentation and other tickets but with no luck.

Is there a way to trust a self signed certificate for the REST interface tests? If you need more information please let me know.

Edit: Added the YML config and composer.json file

//composer.json
{
      "require": {
              "drupal/drupal-extension": "~3.0",
              "emuse/behat-html-formatter": "dev-master",
              "behatch/contexts": "*",
              "guzzlehttp/guzzle": "dev-master",
              "behat/mink-goutte-driver": "dev-master"
          },
          "config": {
                  "bin-dir": "bin/"
          }
}

Note I removed my url from the yml file below.

default:
    suites:
        default:
            contexts:
                - FeatureContextDrupal
                - behatch:browser
                - Drupal\DrupalExtension\Context\MinkContext
                - Drupal\DrupalExtension\Context\DrupalContext
                - Drupal\DrupalExtension\Context\DrushContext
                - Drupal\DrupalExtension\Context\MessageContext
                - behatch:debug
                - behatch:system
                - behatch:json
                - behatch:table
                - behatch:rest
                - behatch:xml
            formatters:
                html:
                    output_path: %paths.base%/build/html/behat
    extensions:
        Sanpi\Behatch\Extension: ~
        emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
            name: html
        Behat\MinkExtension:
            goutte:
                guzzle_parameters:
                    verify: false
                    ssl.certificate_authority: false
            selenium2:
                wd_host: http://localhost:4444/wd/hub
            base_url: "https://myurl.devcloud.acquia-sites.com/"
        Drupal\DrupalExtension:
            blackbox: ~
            api_driver: 'drupal'
            drush:
                alias: 'ns-test'
            drupal:
                drupal_root: '/var/www/html/utcfs.dev/docroot'


chrome:
  extensions:
    Behat\MinkExtension:
      selenium2:
        browser: chrome
        capabilities: { "browser": "chrome", "browserName": "chrome", "version": "*", "browserVersion": "*" }

iexplore:
  extensions:
    Behat\MinkExtension:
      selenium2:
        browser: internet explorer
        capabilities: { "browser": "internet explorer", "browserName": "internet explorer", "version": "*", "browserVersion": "*" }

Solution

  • Found my answer on GitHub:

    For Goutte 4+ (which uses Symfony's HttpClient instead of Guzzle):

    extension:
      Behat\MinkExtension:
        goutte:
          server_parameters:
            verify_host: false
            verify_peer: false
    

    For Behat3/MinkExtension2.2

    extensions:
        Behat\MinkExtension:
          base_url: 'https://localhost'
          sessions:
            default:
              goutte:
                guzzle_parameters:
                  defaults:
                    verify: false
    

    Lower versions (1.x)

      extensions:
        Behat\MinkExtension:
          goutte:
            guzzle_parameters:
              verify: false