Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,11 @@ public static function session(?SessionConfig $config = null, bool $getShared =
$driverName = MySQLiHandler::class;
} elseif ($driverPlatform === 'Postgre') {
$driverName = PostgreHandler::class;
} else {
throw new InvalidArgumentException(sprintf(
'Invalid session database handler "%s" provided. Only "MySQLi" and "Postgre" are supported.',
$driverPlatform,
));
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/system/Config/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use CodeIgniter\Router\RouteCollection;
use CodeIgniter\Router\Router;
use CodeIgniter\Security\Security;
use CodeIgniter\Session\Handlers\DatabaseHandler;
use CodeIgniter\Session\Session;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockResponse;
Expand All @@ -46,6 +47,7 @@
use CodeIgniter\View\Cell;
use CodeIgniter\View\Parser;
use Config\App;
use Config\Database as DatabaseConfig;
use Config\Exceptions;
use Config\Security as SecurityConfig;
use Config\Session as ConfigSession;
Expand Down Expand Up @@ -275,6 +277,25 @@ public function testNewSessionWithInvalidHandler(string $driver): void
Services::session($config, false);
}

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testNewSessionWithInvalidDatabaseHandler(): void
{
$driver = config(DatabaseConfig::class)->tests['DBDriver'];

if (in_array($driver, ['MySQLi', 'Postgre'], true)) {
$this->markTestSkipped('This test case does not work with MySQLi and Postgre');
}

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf('Invalid session database handler "%s" provided. Only "MySQLi" and "Postgre" are supported.', $driver));

$config = new ConfigSession();

$config->driver = DatabaseHandler::class;
Services::session($config, false);
}

/**
* @return iterable<string, array{0: string}>
*/
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.6.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Bugs Fixed
**********

- **Security:** Fixed a bug where the ``sanitize_filename()`` function from the Security helper would throw an error when used in CLI requests.
- **Session:** Fixed a bug where using the ``DatabaseHandler`` with an unsupported database driver (such as ``SQLSRV``, ``OCI8``, or ``SQLite3``) did not throw an appropriate error.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
Loading