Skip to content

Commit

Permalink
Start implementing SSL options.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 10, 2018
1 parent e406cab commit f3f5b08
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Http/Client/Adapter/Curl.php
Expand Up @@ -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;
}
Expand Down
31 changes: 31 additions & 0 deletions tests/TestCase/Http/Client/Adapter/CurlTest.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit f3f5b08

Please sign in to comment.