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