Skip to content

Commit 3f511dd

Browse files
Add test case for database ID being wrong in configuration
1 parent d53f98a commit 3f511dd

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

phpstan-baseline-dev.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ parameters:
66
count: 1
77
path: tests/src/Auth/Source/SQL2MultipleAuthTest.php
88

9+
-
10+
message: '#^Property SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\SQL2NonExistentDbTest\:\:\$config type has no value type specified in iterable type array\.$#'
11+
identifier: missingType.iterableValue
12+
count: 1
13+
path: tests/src/Auth/Source/SQL2NonExistentDbTest.php
14+
915
-
1016
message: '#^Property SimpleSAML\\Test\\Module\\sqlauth\\Auth\\Source\\SQL2SimpleTest\:\:\$config type has no value type specified in iterable type array\.$#'
1117
identifier: missingType.iterableValue
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\Module\sqlauth\Auth\Source;
6+
7+
use Exception;
8+
use PHPUnit\Framework\TestCase;
9+
10+
/*
11+
* It was possible to misconfigure the SQL2 authentication source to point to
12+
* a non-existent database. This test ensures that this misconfiguration is
13+
* detected and handled gracefully.
14+
*/
15+
#CoversClass(SimpleSAML\Module\sqlauth\Auth\Source\SQL2::class)
16+
class SQL2NonExistentDbTest extends TestCase
17+
{
18+
/** @var array<string, string> */
19+
private array $info = ['AuthId' => 'testAuthId'];
20+
21+
protected array $config = [
22+
"databases" => [
23+
"defaultdb" => [
24+
"dsn" => 'sqlite:file:defaultdb?mode=memory&cache=shared',
25+
"username" => "notused",
26+
"password" => "notused",
27+
],
28+
],
29+
"auth_queries" => [
30+
"auth_query" => [
31+
"database" => "wrong-name", // Non-existent database
32+
"query" => "select 1;",
33+
],
34+
],
35+
];
36+
37+
public function testNonExistentDatabaseFailure(): void
38+
{
39+
$this->expectException(Exception::class);
40+
(new SQL2Wrapper($this->info, $this->config))->callLogin('bob', 'password');
41+
$this->fail('Expected exception was not thrown.');
42+
}
43+
}

0 commit comments

Comments
 (0)