首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHPUnit上下文中的口吻卷曲误差51

PHPUnit上下文中的口吻卷曲误差51
EN

Stack Overflow用户
提问于 2016-03-16 18:09:32
回答 1查看 1.2K关注 0票数 2

我有一个Laravel应用程序,它使用一个web服务来验证一个字段,其余的调用都是通过HTTPS进行的。当我通过浏览器发布表单时,一切都很好。当我作为测试运行相同的phpunit时,Guzzle失败了:

exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 51: SSL: certificate verification failed (result: 5)

我尝试了什么:

在口香糖之前,我直接卷曲,这给了我同样的行为。我尝试使用curl_setopt($curl, CURLOPT_CAINFO, '/path/to/cacert.pem');显式地在代码中设置仙人掌,但没有任何效果。

我试着(同样的结果)用口香糖指向仙人掌。

代码语言:javascript
复制
$response = $client->request('GET', $url, [
    'auth' => ['user', 'pass'],
    'verify' => '/path/to/cacert.pem'
]);

3- phpinfo说Apache正在使用它的本地curl,命令行php使用不同的curl,所以我将其符号链接到Apache版本,同样的结果。

4-设置了curl.cainfo和openssl.cainfo。

5- /usr/local/etc/openssl/cert.pem存在

6-将-d openssl.cainfo传递给命令行上的phpunit,什么也不做。

代码:

代码语言:javascript
复制
private function curl_rest_call($url){

    // $curl = curl_init() ;

    // curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    // curl_setopt($curl, CURLOPT_USERPWD, "user:pass");

    // curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    // curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
    // curl_setopt($curl, CURLOPT_CAINFO, '/path/to/cacert.pem');

    // curl_setopt($curl, CURLOPT_URL, $url);
    // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    // $rest = curl_exec($curl);
    // $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);

    // curl_close($curl);
    // $result = json_decode($rest) ;

    // $result->status = $httpStatus ;

    // return $result ;

    $client = new Guzzle();
    $response = $client->request('GET', $url, [
        'auth' => ['user', 'pass'],
        'verify' => '/path/to/cacert.pem'
    ]);

    $result = json_decode($response->getBody()->getContents()) ;
    $result->status = $response->getStatusCode() ;

    return $result ;

}

测试:

代码语言:javascript
复制
public function testSuccessfulSignup(){

    $this->visit('/free-software')
        ->type('test@mail.com', 'mail')
        ->type('Philip', 'first_name')
        ->type('Fry', 'last_name')
        ->select('Freelancer', 'profile')
        ->type('Other', 'industry')
        ->select('Canada', 'country')
        ->type('(514) 278-8666', 'phone_number')
        ->press('Try Harmony Now!')
        ->seePageIs('/success');
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-17 14:13:29

问题就在这里。

我从命令行调用phpunit,因为它是一个php脚本,而不是二进制脚本,它在与one服务器使用的php不同的位置调用php的默认系统安装,因此忽略了cacert指令和php.ini配置。

虽然理论上不应该这样,但它完全忽略了-d openssl.cainfo开关和CURL_CA_BUNDLE环境变量( curl使用的)

最后,我在PATH变量上添加了webserver版本,以便调用phpunit将加载正确的仙人掌信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36043676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档