mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 10:03:27 +01:00
Bugfix/curlopt capath (#1684)
This commit is contained in:
parent
4149288b3d
commit
114516bcb4
@ -326,12 +326,20 @@ class CurlFactory implements CurlFactoryInterface
|
|||||||
$conf[CURLOPT_SSL_VERIFYHOST] = 2;
|
$conf[CURLOPT_SSL_VERIFYHOST] = 2;
|
||||||
$conf[CURLOPT_SSL_VERIFYPEER] = true;
|
$conf[CURLOPT_SSL_VERIFYPEER] = true;
|
||||||
if (is_string($options['verify'])) {
|
if (is_string($options['verify'])) {
|
||||||
$conf[CURLOPT_CAINFO] = $options['verify'];
|
// Throw an error if the file/folder/link path is not valid or doesn't exist.
|
||||||
if (!file_exists($options['verify'])) {
|
if (!file_exists($options['verify'])) {
|
||||||
throw new \InvalidArgumentException(
|
throw new \InvalidArgumentException(
|
||||||
"SSL CA bundle not found: {$options['verify']}"
|
"SSL CA bundle not found: {$options['verify']}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// If it's a directory or a link to a directory use CURLOPT_CAPATH.
|
||||||
|
// If not, it's probably a file, or a link to a file, so use CURLOPT_CAINFO.
|
||||||
|
if (is_dir($options['verify']) ||
|
||||||
|
(is_link($options['verify']) && is_dir(readlink($options['verify'])))) {
|
||||||
|
$conf[CURLOPT_CAPATH] = $options['verify'];
|
||||||
|
} else {
|
||||||
|
$conf[CURLOPT_CAINFO] = $options['verify'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,15 @@ class CurlFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(true, $_SERVER['_curl'][CURLOPT_SSL_VERIFYPEER]);
|
$this->assertEquals(true, $_SERVER['_curl'][CURLOPT_SSL_VERIFYPEER]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanSetVerifyToDir()
|
||||||
|
{
|
||||||
|
$f = new Handler\CurlFactory(3);
|
||||||
|
$f->create(new Psr7\Request('GET', 'http://foo.com'), ['verify' => __DIR__]);
|
||||||
|
$this->assertEquals(__DIR__, $_SERVER['_curl'][CURLOPT_CAPATH]);
|
||||||
|
$this->assertEquals(2, $_SERVER['_curl'][CURLOPT_SSL_VERIFYHOST]);
|
||||||
|
$this->assertEquals(true, $_SERVER['_curl'][CURLOPT_SSL_VERIFYPEER]);
|
||||||
|
}
|
||||||
|
|
||||||
public function testAddsVerifyAsTrue()
|
public function testAddsVerifyAsTrue()
|
||||||
{
|
{
|
||||||
$f = new Handler\CurlFactory(3);
|
$f = new Handler\CurlFactory(3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user