Skip to content

Commit

Permalink
fix: CURLOPT_SSL_VERIFYPEER values and tests related with CURLOPT_SSL…
Browse files Browse the repository at this point in the history
…_VERIFYPEER and CURLOPT_SSL_VERIFYHOST
  • Loading branch information
NicolaeIotu committed Nov 28, 2023
1 parent 35345c7 commit 8207e01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,10 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])

$curlOptions[CURLOPT_CAINFO] = $file;
if ($config['verify'] === 'yes') {
$curlOptions[CURLOPT_SSL_VERIFYPEER] = 1;
$curlOptions[CURLOPT_SSL_VERIFYPEER] = true;
$curlOptions[CURLOPT_SSL_VERIFYHOST] = 2;
} else {
$curlOptions[CURLOPT_SSL_VERIFYPEER] = 0;
$curlOptions[CURLOPT_SSL_VERIFYPEER] = false;
$curlOptions[CURLOPT_SSL_VERIFYHOST] = 0;
}
} elseif (is_bool($config['verify'])) {
Expand Down
2 changes: 1 addition & 1 deletion tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public function testSSLVerification(): void
$this->assertSame($file, $options[CURLOPT_CAINFO]);

$this->assertArrayHasKey(CURLOPT_SSL_VERIFYPEER, $options);
$this->assertSame(1, $options[CURLOPT_SSL_VERIFYPEER]);
$this->assertTrue($options[CURLOPT_SSL_VERIFYPEER]);
}

public function testSSLWithBadKey(): void
Expand Down
17 changes: 16 additions & 1 deletion tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,27 @@ public function testSSLVerification(): void
$this->assertSame($file, $options[CURLOPT_CAINFO]);

$this->assertArrayHasKey(CURLOPT_SSL_VERIFYPEER, $options);
$this->assertSame(1, $options[CURLOPT_SSL_VERIFYPEER]);
$this->assertTrue($options[CURLOPT_SSL_VERIFYPEER]);

$this->assertArrayHasKey(CURLOPT_SSL_VERIFYHOST, $options);
$this->assertSame(2, $options[CURLOPT_SSL_VERIFYHOST]);
}

public function testNoSSL(): void
{
$this->request->request('get', 'http://example.com', [
'verify' => false,
]);

$options = $this->request->curl_options;

$this->assertArrayHasKey(CURLOPT_SSL_VERIFYPEER, $options);
$this->assertFalse($options[CURLOPT_SSL_VERIFYPEER]);

$this->assertArrayHasKey(CURLOPT_SSL_VERIFYHOST, $options);
$this->assertSame(0, $options[CURLOPT_SSL_VERIFYHOST]);
}

public function testSSLWithBadKey(): void
{
$file = 'something_obviously_bogus';
Expand Down

0 comments on commit 8207e01

Please sign in to comment.