diff --git a/src/Http/Client/Adapter/Curl.php b/src/Http/Client/Adapter/Curl.php index 89b60a0c88b..9af12b701c6 100644 --- a/src/Http/Client/Adapter/Curl.php +++ b/src/Http/Client/Adapter/Curl.php @@ -80,9 +80,20 @@ public function buildOptions(Request $request, array $options) $out[CURLOPT_POSTFIELDS] = $body->getContents(); } + $optionMap = [ + 'timeout' => CURLOPT_TIMEOUT, + 'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER, + 'ssl_verify_host' => CURLOPT_SSL_VERIFYHOST, + 'ssl_verify_depth' => 9000, + 'ssl_allow_self_signed' => false, + ]; + if (isset($options['timeout'])) { $out[CURLOPT_TIMEOUT] = $options['timeout']; } + if (isset($options['ssl_verify_peer'])) { + $out[CURLOPT_SSL_VERIFYPEER] = $options['ssl_verify_peer']; + } return $out; } diff --git a/tests/TestCase/Http/Client/Adapter/CurlTest.php b/tests/TestCase/Http/Client/Adapter/CurlTest.php index d2d534297fd..310ff108288 100644 --- a/tests/TestCase/Http/Client/Adapter/CurlTest.php +++ b/tests/TestCase/Http/Client/Adapter/CurlTest.php @@ -146,6 +146,37 @@ public function testBuildOptionsPut() $this->assertSame($expected, $result); } + /** + * Test converting client options into curl ones. + * + * @return void + */ + public function testBuildOptionsSsl() + { + $options = [ + 'ssl_verify_host' => true, + 'ssl_verify_peer' => true, + 'ssl_verify_peer_name' => true, + 'ssl_verify_depth' => 9000, + 'ssl_allow_self_signed' => false, + ]; + $request = new Request('http://localhost/things', 'GET'); + $result = $this->curl->buildOptions($request, $options); + $expected = [ + CURLOPT_URL => 'http://localhost/things', + CURLOPT_HTTP_VERSION => '1.1', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => true, + CURLOPT_HTTPHEADER => [ + 'Connection: close', + 'User-Agent: CakePHP', + ], + CURLOPT_HTTPGET => true, + CURLOPT_SSL_VERIFYPEER => true + ]; + $this->assertSame($expected, $result); + } + /** * Test the send method by using cakephp:// protocol. *