1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\Monitor\TestSuite\Configuration; |
4
|
|
|
|
5
|
|
|
use SimpleSAML\Module\Monitor\TestConfiguration; |
6
|
|
|
use SimpleSAML\Module\Monitor\TestCase; |
7
|
|
|
use SimpleSAML\Module\Monitor\TestData; |
8
|
|
|
use SimpleSAML\Module\Monitor\TestResult; |
9
|
|
|
use SimpleSAML\Module\Monitor\State; |
10
|
|
|
use SimpleSAML\Utils; |
11
|
|
|
|
12
|
|
|
final class Database extends \SimpleSAML\Module\Monitor\TestSuiteFactory |
13
|
|
|
{ |
14
|
|
|
/** @var string|null */ |
15
|
|
|
private $store = null; |
16
|
|
|
|
17
|
|
|
/** @var array */ |
18
|
|
|
private $metadataSources = []; |
19
|
|
|
|
20
|
|
|
/** @var array */ |
21
|
|
|
private $dependentModules = ['consent']; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private $dsn = 'undefined'; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \SimpleSAML\Module\Monitor\TestConfiguration $configuration |
29
|
|
|
*/ |
30
|
|
|
public function __construct(TestConfiguration $configuration) |
31
|
|
|
{ |
32
|
|
|
$globalConfig = $configuration->getGlobalConfig(); |
33
|
|
|
$this->store = $globalConfig->getString('store.type', 'phpsession'); |
34
|
|
|
$this->dsn = $globalConfig->getString('database.dsn'); |
35
|
|
|
$this->metadataSources = $globalConfig->getArray('metadata.sources', []); |
36
|
|
|
|
37
|
|
|
$this->setCategory('Configuration'); |
38
|
|
|
parent::__construct($configuration); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function invokeTest(): void |
46
|
|
|
{ |
47
|
|
|
if ($this->store === 'sql') { |
48
|
|
|
// We use a database for session-storage |
49
|
|
|
} elseif (in_array(['type' => 'pdo'], $this->metadataSources, true)) { |
50
|
|
|
// We use a database for metadata-storage |
51
|
|
|
} elseif ($this->areModulesDependingOnDatabase() === false) { |
52
|
|
|
$testResult = new TestResult('Database connection', '-'); |
53
|
|
|
$testResult->setState(State::SKIPPED); |
54
|
|
|
$testResult->setMessage('Database currently not in use'); |
55
|
|
|
$this->addTestResult($testResult); |
56
|
|
|
$this->setTestResult($testResult); |
57
|
|
|
return; |
58
|
|
|
} // We're using consent (TODO: but are we using consent+pdo??) |
59
|
|
|
|
60
|
|
|
$testData = new TestData(['dsn' => $this->dsn]); |
61
|
|
|
$connTest = new TestCase\Database\Connection($testData); |
62
|
|
|
$testResult = $connTest->getTestResult(); |
63
|
|
|
$this->addTestResult($testResult); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
private function areModulesDependingOnDatabase(): bool |
71
|
|
|
{ |
72
|
|
|
foreach ($this->dependentModules as $module) { |
73
|
|
|
if (\SimpleSAML\Module::isModuleEnabled($module)) { |
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|