我正在尝试将Behat带到https安全项目,并且在启动curl请求时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
我知道Mink在内部使用guzzle,它会启动curl请求。如何使用curl选项正确实例化guzzle客户端?
答案 0 :(得分:5)
是的,它已知问题,现在唯一的解决办法是你的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
答案 1 :(得分:2)
现在你需要在behat.yml中设置:
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
在合并拉取请求https://github.com/guzzle/guzzle/pull/498之后,您将能够执行以下操作:
default:
extensions:
Behat\MinkExtension\Extension:
goutte:
guzzle_parameters:
ssl.certificate_authority: false
请注意我使用字符串常量而不是整数字,因为它们更具可读性。你不必在这里使用整数,因为在Guzzle中完成了正确的常数/整数转换。
另外,我添加了CURLOPT_SSL_VERIFYHOST来解决你的问题。
答案 2 :(得分:0)
Mink使用Goutte在内部初始化Guzzle(参见:https://github.com/fabpot/Goutte/blob/master/Goutte/Client.php#L45)。
以下是如何初始化Guzzle以解决您的问题:https://github.com/fabpot/Goutte/issues/63#issuecomment-6371727
虽然有多种方法可以解决这个问题,但我现在能看到的最简单的解决方案是
其他(可能更干净)的方法是使用编译器传递来改变服务定义,并使其调用setClient()。
答案 3 :(得分: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' );
}