Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Dec 2, 2023
2 parents e0eb27c + 0c9b3ff commit bea1cac
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 13 deletions.
8 changes: 5 additions & 3 deletions system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,18 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
// SSL Verification
if (isset($config['verify'])) {
if (is_string($config['verify'])) {
$file = realpath($config['ssl_key']) ?: $config['ssl_key'];
$file = realpath($config['verify']) ?: $config['verify'];

if (! is_file($file)) {
throw HTTPException::forInvalidSSLKey($config['ssl_key']);
throw HTTPException::forInvalidSSLKey($config['verify']);
}

$curlOptions[CURLOPT_CAINFO] = $file;
$curlOptions[CURLOPT_SSL_VERIFYPEER] = 1;
$curlOptions[CURLOPT_SSL_VERIFYPEER] = true;
$curlOptions[CURLOPT_SSL_VERIFYHOST] = 2;
} elseif (is_bool($config['verify'])) {
$curlOptions[CURLOPT_SSL_VERIFYPEER] = $config['verify'];
$curlOptions[CURLOPT_SSL_VERIFYHOST] = $config['verify'] ? 2 : 0;
}
}

Expand Down
1 change: 1 addition & 0 deletions system/Test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

// Initialize and register the loader with the SPL autoloader stack.
Services::autoloader()->initialize(new Autoload(), new Modules())->register();
Services::autoloader()->loadHelpers();

// Now load Composer's if it's available
if (is_file(COMPOSER_PATH)) {
Expand Down
11 changes: 6 additions & 5 deletions tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ public function testSSLVerification(): void
$file = __FILE__;

$this->request->request('get', 'http://example.com', [
'verify' => 'yes',
'ssl_key' => $file,
'verify' => $file,
]);

$options = $this->request->curl_options;
Expand All @@ -545,7 +544,10 @@ 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 testSSLWithBadKey(): void
Expand All @@ -554,8 +556,7 @@ public function testSSLWithBadKey(): void
$this->expectException(HTTPException::class);

$this->request->request('get', 'http://example.com', [
'verify' => 'yes',
'ssl_key' => $file,
'verify' => $file,
]);
}

Expand Down
26 changes: 21 additions & 5 deletions tests/system/HTTP/CURLRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ public function testSSLVerification(): void
$file = __FILE__;

$this->request->request('get', 'http://example.com', [
'verify' => 'yes',
'ssl_key' => $file,
'verify' => $file,
]);

$options = $this->request->curl_options;
Expand All @@ -528,7 +527,25 @@ 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
Expand All @@ -537,8 +554,7 @@ public function testSSLWithBadKey(): void
$this->expectException(HTTPException::class);

$this->request->request('get', 'http://example.com', [
'verify' => 'yes',
'ssl_key' => $file,
'verify' => $file,
]);
}

Expand Down
8 changes: 8 additions & 0 deletions user_guide_src/source/changelogs/v4.4.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Validation rules matches and differs
Bugs have been fixed in the case where ``matches`` and ``differs`` in the Strict
and Traditional rules validate data of non-string types.

The use of the `ssl_key` option in CURLRequest was removed
==========================================================

Due to a bug, we were using the undocumented `ssl_key` config option to define the CA bundle in CURLRequest.
This was fixed and is now working according to documentation. You can define your CA bundle via the `verify` option.

***************
Message Changes
***************
Expand All @@ -49,6 +55,8 @@ Deprecations
Bugs Fixed
**********

- **CURLRequest:** Fixed a bug where the hostname was checked even if options 'verify' was set to *false*.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.
67 changes: 67 additions & 0 deletions user_guide_src/source/database/utilities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,73 @@ parameter.
Using the Database Utilities
****************************

Retrieve List of Database Names
================================

Returns an array of database names:

.. literalinclude:: utilities/004.php
:lines: 2-

Determine If a Database Exists
==============================

Sometimes it's helpful to know whether a particular database exists.
Returns a boolean ``true``/``false``. Usage example:

.. literalinclude:: utilities/005.php
:lines: 2-

.. note:: Replace ``database_name`` with the name of the database you are
looking for. This method is case sensitive.

Optimize a Table
================

Permits you to optimize a table using the table name specified in the
first parameter. Returns ``true``/``false`` based on success or failure:

.. literalinclude:: utilities/006.php
:lines: 2-

.. note:: Not all database platforms support table optimization. It is
mostly for use with MySQL.

Optimize a Database
===================

Permits you to optimize the database your DB class is currently
connected to. Returns an array containing the DB status messages or
``false`` on failure:

.. literalinclude:: utilities/008.php
:lines: 2-

.. note:: Not all database platforms support database optimization. It
it is mostly for use with MySQL.

Export a Query Result as a CSV File
===================================

Permits you to generate a CSV file from a query result. The first
parameter of the method must contain the result object from your
query. Example:

.. literalinclude:: utilities/009.php
:lines: 2-

The second, third, and fourth parameters allow you to set the delimiter
newline, and enclosure characters respectively. By default commas are
used as the delimiter, ``"\n"`` is used as a new line, and a double-quote
is used as the enclosure. Example:

.. literalinclude:: utilities/010.php
:lines: 2-

.. important:: This method will NOT write the CSV file for you. It
simply creates the CSV layout. If you need to write the file
use the :php:func:`write_file()` helper.

Export a Query Result as an XML Document
========================================

Expand Down
9 changes: 9 additions & 0 deletions user_guide_src/source/database/utilities/004.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$dbutil = \Config\Database::utils();

$dbs = $dbutil->listDatabases();

foreach ($dbs as $db) {
echo $db;
}
7 changes: 7 additions & 0 deletions user_guide_src/source/database/utilities/005.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

$dbutil = \Config\Database::utils();

if ($dbutil->databaseExists('database_name')) {
// some code...
}
7 changes: 7 additions & 0 deletions user_guide_src/source/database/utilities/006.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

$dbutil = \Config\Database::utils();

if ($dbutil->optimizeTable('table_name')) {
echo 'Success!';
}
9 changes: 9 additions & 0 deletions user_guide_src/source/database/utilities/008.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$dbutil = \Config\Database::utils();

$result = $dbutil->optimizeDatabase();

if ($result !== false) {
print_r($result);
}
8 changes: 8 additions & 0 deletions user_guide_src/source/database/utilities/009.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$db = db_connect();
$dbutil = \Config\Database::utils();

$query = $db->query('SELECT * FROM mytable');

echo $dbutil->getCSVFromResult($query);
12 changes: 12 additions & 0 deletions user_guide_src/source/database/utilities/010.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$db = db_connect();
$dbutil = \Config\Database::utils();

$query = $db->query('SELECT * FROM mytable');

$delimiter = ',';
$newline = "\r\n";
$enclosure = '"';

echo $dbutil->getCSVFromResult($query, $delimiter, $newline, $enclosure);
9 changes: 9 additions & 0 deletions user_guide_src/source/installation/upgrade_444.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ changed (fixed).
Note that Traditional Rules should not be used to validate data that is not a
string.

The use of the `ssl_key` option in CURLRequest was removed
==========================================================

CURLRequest option `ssl_key` it's not recognized anymore.
If in use, option `ssl_key` must be replaced with option `verify` in order to define the path
to a CA bundle for CURLRequest.

CURLRequest option `verify` can also take *boolean* values as usual.

*********************
Breaking Enhancements
*********************
Expand Down

0 comments on commit bea1cac

Please sign in to comment.