Skip to content

Commit bea1cac

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents e0eb27c + 0c9b3ff commit bea1cac

File tree

13 files changed

+169
-13
lines changed

13 files changed

+169
-13
lines changed

system/HTTP/CURLRequest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,18 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
540540
// SSL Verification
541541
if (isset($config['verify'])) {
542542
if (is_string($config['verify'])) {
543-
$file = realpath($config['ssl_key']) ?: $config['ssl_key'];
543+
$file = realpath($config['verify']) ?: $config['verify'];
544544

545545
if (! is_file($file)) {
546-
throw HTTPException::forInvalidSSLKey($config['ssl_key']);
546+
throw HTTPException::forInvalidSSLKey($config['verify']);
547547
}
548548

549549
$curlOptions[CURLOPT_CAINFO] = $file;
550-
$curlOptions[CURLOPT_SSL_VERIFYPEER] = 1;
550+
$curlOptions[CURLOPT_SSL_VERIFYPEER] = true;
551+
$curlOptions[CURLOPT_SSL_VERIFYHOST] = 2;
551552
} elseif (is_bool($config['verify'])) {
552553
$curlOptions[CURLOPT_SSL_VERIFYPEER] = $config['verify'];
554+
$curlOptions[CURLOPT_SSL_VERIFYHOST] = $config['verify'] ? 2 : 0;
553555
}
554556
}
555557

system/Test/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

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

7980
// Now load Composer's if it's available
8081
if (is_file(COMPOSER_PATH)) {

tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ public function testSSLVerification(): void
535535
$file = __FILE__;
536536

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

542541
$options = $this->request->curl_options;
@@ -545,7 +544,10 @@ public function testSSLVerification(): void
545544
$this->assertSame($file, $options[CURLOPT_CAINFO]);
546545

547546
$this->assertArrayHasKey(CURLOPT_SSL_VERIFYPEER, $options);
548-
$this->assertSame(1, $options[CURLOPT_SSL_VERIFYPEER]);
547+
$this->assertTrue($options[CURLOPT_SSL_VERIFYPEER]);
548+
549+
$this->assertArrayHasKey(CURLOPT_SSL_VERIFYHOST, $options);
550+
$this->assertSame(2, $options[CURLOPT_SSL_VERIFYHOST]);
549551
}
550552

551553
public function testSSLWithBadKey(): void
@@ -554,8 +556,7 @@ public function testSSLWithBadKey(): void
554556
$this->expectException(HTTPException::class);
555557

556558
$this->request->request('get', 'http://example.com', [
557-
'verify' => 'yes',
558-
'ssl_key' => $file,
559+
'verify' => $file,
559560
]);
560561
}
561562

tests/system/HTTP/CURLRequestTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ public function testSSLVerification(): void
518518
$file = __FILE__;
519519

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

525524
$options = $this->request->curl_options;
@@ -528,7 +527,25 @@ public function testSSLVerification(): void
528527
$this->assertSame($file, $options[CURLOPT_CAINFO]);
529528

530529
$this->assertArrayHasKey(CURLOPT_SSL_VERIFYPEER, $options);
531-
$this->assertSame(1, $options[CURLOPT_SSL_VERIFYPEER]);
530+
$this->assertTrue($options[CURLOPT_SSL_VERIFYPEER]);
531+
532+
$this->assertArrayHasKey(CURLOPT_SSL_VERIFYHOST, $options);
533+
$this->assertSame(2, $options[CURLOPT_SSL_VERIFYHOST]);
534+
}
535+
536+
public function testNoSSL(): void
537+
{
538+
$this->request->request('get', 'http://example.com', [
539+
'verify' => false,
540+
]);
541+
542+
$options = $this->request->curl_options;
543+
544+
$this->assertArrayHasKey(CURLOPT_SSL_VERIFYPEER, $options);
545+
$this->assertFalse($options[CURLOPT_SSL_VERIFYPEER]);
546+
547+
$this->assertArrayHasKey(CURLOPT_SSL_VERIFYHOST, $options);
548+
$this->assertSame(0, $options[CURLOPT_SSL_VERIFYHOST]);
532549
}
533550

534551
public function testSSLWithBadKey(): void
@@ -537,8 +554,7 @@ public function testSSLWithBadKey(): void
537554
$this->expectException(HTTPException::class);
538555

539556
$this->request->request('get', 'http://example.com', [
540-
'verify' => 'yes',
541-
'ssl_key' => $file,
557+
'verify' => $file,
542558
]);
543559
}
544560

user_guide_src/source/changelogs/v4.4.4.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Validation rules matches and differs
2727
Bugs have been fixed in the case where ``matches`` and ``differs`` in the Strict
2828
and Traditional rules validate data of non-string types.
2929

30+
The use of the `ssl_key` option in CURLRequest was removed
31+
==========================================================
32+
33+
Due to a bug, we were using the undocumented `ssl_key` config option to define the CA bundle in CURLRequest.
34+
This was fixed and is now working according to documentation. You can define your CA bundle via the `verify` option.
35+
3036
***************
3137
Message Changes
3238
***************
@@ -49,6 +55,8 @@ Deprecations
4955
Bugs Fixed
5056
**********
5157

58+
- **CURLRequest:** Fixed a bug where the hostname was checked even if options 'verify' was set to *false*.
59+
5260
See the repo's
5361
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
5462
for a complete list of bugs fixed.

user_guide_src/source/database/utilities.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,73 @@ parameter.
3030
Using the Database Utilities
3131
****************************
3232

33+
Retrieve List of Database Names
34+
================================
35+
36+
Returns an array of database names:
37+
38+
.. literalinclude:: utilities/004.php
39+
:lines: 2-
40+
41+
Determine If a Database Exists
42+
==============================
43+
44+
Sometimes it's helpful to know whether a particular database exists.
45+
Returns a boolean ``true``/``false``. Usage example:
46+
47+
.. literalinclude:: utilities/005.php
48+
:lines: 2-
49+
50+
.. note:: Replace ``database_name`` with the name of the database you are
51+
looking for. This method is case sensitive.
52+
53+
Optimize a Table
54+
================
55+
56+
Permits you to optimize a table using the table name specified in the
57+
first parameter. Returns ``true``/``false`` based on success or failure:
58+
59+
.. literalinclude:: utilities/006.php
60+
:lines: 2-
61+
62+
.. note:: Not all database platforms support table optimization. It is
63+
mostly for use with MySQL.
64+
65+
Optimize a Database
66+
===================
67+
68+
Permits you to optimize the database your DB class is currently
69+
connected to. Returns an array containing the DB status messages or
70+
``false`` on failure:
71+
72+
.. literalinclude:: utilities/008.php
73+
:lines: 2-
74+
75+
.. note:: Not all database platforms support database optimization. It
76+
it is mostly for use with MySQL.
77+
78+
Export a Query Result as a CSV File
79+
===================================
80+
81+
Permits you to generate a CSV file from a query result. The first
82+
parameter of the method must contain the result object from your
83+
query. Example:
84+
85+
.. literalinclude:: utilities/009.php
86+
:lines: 2-
87+
88+
The second, third, and fourth parameters allow you to set the delimiter
89+
newline, and enclosure characters respectively. By default commas are
90+
used as the delimiter, ``"\n"`` is used as a new line, and a double-quote
91+
is used as the enclosure. Example:
92+
93+
.. literalinclude:: utilities/010.php
94+
:lines: 2-
95+
96+
.. important:: This method will NOT write the CSV file for you. It
97+
simply creates the CSV layout. If you need to write the file
98+
use the :php:func:`write_file()` helper.
99+
33100
Export a Query Result as an XML Document
34101
========================================
35102

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$dbutil = \Config\Database::utils();
4+
5+
$dbs = $dbutil->listDatabases();
6+
7+
foreach ($dbs as $db) {
8+
echo $db;
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$dbutil = \Config\Database::utils();
4+
5+
if ($dbutil->databaseExists('database_name')) {
6+
// some code...
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$dbutil = \Config\Database::utils();
4+
5+
if ($dbutil->optimizeTable('table_name')) {
6+
echo 'Success!';
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$dbutil = \Config\Database::utils();
4+
5+
$result = $dbutil->optimizeDatabase();
6+
7+
if ($result !== false) {
8+
print_r($result);
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$db = db_connect();
4+
$dbutil = \Config\Database::utils();
5+
6+
$query = $db->query('SELECT * FROM mytable');
7+
8+
echo $dbutil->getCSVFromResult($query);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$db = db_connect();
4+
$dbutil = \Config\Database::utils();
5+
6+
$query = $db->query('SELECT * FROM mytable');
7+
8+
$delimiter = ',';
9+
$newline = "\r\n";
10+
$enclosure = '"';
11+
12+
echo $dbutil->getCSVFromResult($query, $delimiter, $newline, $enclosure);

user_guide_src/source/installation/upgrade_444.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ changed (fixed).
5858
Note that Traditional Rules should not be used to validate data that is not a
5959
string.
6060

61+
The use of the `ssl_key` option in CURLRequest was removed
62+
==========================================================
63+
64+
CURLRequest option `ssl_key` it's not recognized anymore.
65+
If in use, option `ssl_key` must be replaced with option `verify` in order to define the path
66+
to a CA bundle for CURLRequest.
67+
68+
CURLRequest option `verify` can also take *boolean* values as usual.
69+
6170
*********************
6271
Breaking Enhancements
6372
*********************

0 commit comments

Comments
 (0)