2012-07-17 32 views
3

我正在嘗試將Behat帶到https受保護的項目,並且在啓動捲曲請求時水貂失敗。如何在Mink中配置捲曲參數?

Scenario: Loggin in        # features/debt.feature:6 
    Given I am on "/"        # FeatureContext::visit() 
     [curl] 51: SSL: certificate subject name 'ubuntu' does not match target host name 'wizard' [url] https://wizard/admin/dev.php/ [info] array (
     'url' => 'https://wizard/admin/dev.php/', 
     'content_type' => NULL, 
     'http_code' => 0, 
     'header_size' => 0, 
     'request_size' => 0, 
     'filetime' => -1, 
     'ssl_verify_result' => 1, 
     'redirect_count' => 0, 
     'total_time' => 0.061943, 
     'namelookup_time' => 0.000234, 
     'connect_time' => 0.000344, 
     'pretransfer_time' => 0, 
     'size_upload' => 0, 
     'size_download' => 0, 
     'speed_download' => 0, 
     'speed_upload' => 0, 
     'download_content_length' => -1, 
     'upload_content_length' => -1, 
     'starttransfer_time' => 0, 
     'redirect_time' => 0, 
     'certinfo' => 
     array (
     ), 
    ) [debug] * About to connect() to wizard port 443 (#0) 
     * Trying 127.0.0.1... * connected 
     * Connected to wizard (127.0.0.1) port 443 (#0) 
     * successfully set certificate verify locations: 
     * CAfile: none 
     CApath: /etc/ssl/certs 
     * SSL connection using DHE-RSA-AES256-SHA 
     * Server certificate: 
     *  subject: CN=ubuntu 
     *  start date: 2011-05-23 08:26:04 GMT 
     *  expire date: 2021-05-20 08:26:04 GMT 
     * SSL: certificate subject name 'ubuntu' does not match target host name 'wizard' 
     * Closing connection #0 

的問題可以通過設置這兩個參數捲曲來解決:

CURLOPT_SSL_VERIFYPEER = false 
CURLOPT_CERTINFO = false 

我知道,貂皮內部使用狂飲,從而啓動捲曲的請求。如何正確實例化curl選項的guzzle客戶端?

回答

4

是的,它是已知的問題,現在唯一的辦法就是像這樣在你的behat.yml:

default: 
    paths: 
     features: . 
     bootstrap: %behat.paths.features%/bootstrap  
    extensions: 
     Behat\MinkExtension\Extension: 
      base_url: http://yourhost/ 
      goutte: 
       guzzle_parameters: 
        ssl.certificate_authority: system 
        curl.options: 
         64: false # CURLOPT_SSL_VERIFYPEER 
         172: false # CURLOPT_CERTINFO 
0

水貂使用內部初始化Guzzle的Goutte(請參閱:https://github.com/fabpot/Goutte/blob/master/Goutte/Client.php#L45)。

這裏是你如何能初始化狂飲解決您的問題:https://github.com/fabpot/Goutte/issues/63#issuecomment-6371727

雖然有解決這一問題的多種途徑,我可以看到最簡單的解決方案現在

其他(也許更乾淨)的方式會改變服務定義與編譯器通道,並使其調用setClient()。

+0

嗨,畢業你迴應。我在githug上看到過你的帖子,但是想知道是否可以使用behat.yml傳遞參數來進行goutte和guzzle?我們需要的不是'behat.mink.goutte.server_parameters'嗎? – Dziamid 2012-07-17 15:47:06

+0

哦,我得到的GuzzleClient是沒有任何參數instanciated。 – Dziamid 2012-07-17 16:35:37

+0

你究竟在哪裏調用setClient()? – Dziamid 2012-07-17 16:52:28

0

我的解決方案:

/** 
* 
* @BeforeScenario 
* @return void 
*/ 
public function doNotCheckSsl() 
{ 
    $strUrl = $this->getMinkParameter('base_url'); 
    $objGuzzleClient = new GuzzleClient($strUrl); 
    $objGuzzleClient->setSslVerification(false, false, 0); 
    $objClient = new GoutteClient(); 
    $objDriver = new GoutteDriver($objClient); 
    $objClient->setClient($objGuzzleClient); 

    $objSession = new Session($objDriver); 
    $objSession->start(); 
    $this->getMink()->registerSession('sess', $objSession); 
    $this->getMink()->setDefaultSessionName('sess'); 
} 
1

現在你需要設置什麼behat.yml是這樣的:這個拉請求https://github.com/guzzle/guzzle/pull/498合併

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 

後,你將是一個只能這樣做:

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

請注意,我使用字符串常量而不是整數,因爲它們更可讀。你不必在這裏使用整數,因爲在Guzzle中完成適當的常量/整數轉換。

此外,我已經添加CURLOPT_SSL_VERIFYHOST這將解決您的問題。