1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\Monitor; |
4
|
|
|
|
5
|
|
|
class Monitor |
6
|
|
|
{ |
7
|
|
|
/** @var \SimpleSAML\Module\Monitor\TestConfiguration */ |
8
|
|
|
private $configuration; |
9
|
|
|
|
10
|
|
|
/** @var array */ |
11
|
|
|
private $results = []; |
12
|
|
|
|
13
|
|
|
/** @var array */ |
14
|
|
|
private $state = []; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param \SimpleSAML\Module\Monitor\TestConfiguration $testConfiguration |
19
|
|
|
*/ |
20
|
|
|
public function __construct(TestConfiguration $testConfiguration) |
21
|
|
|
{ |
22
|
|
|
$this->setTestConfiguration($testConfiguration); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function invokeTestSuites(): void |
30
|
|
|
{ |
31
|
|
|
$this->invokeModuleCheck(); |
32
|
|
|
$this->invokeConfigurationCheck(); |
33
|
|
|
$this->invokeStoreCheck(); |
34
|
|
|
$this->invokeAuthSourceCheck(); |
35
|
|
|
$this->invokeMetadataCheck(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return \SimpleSAML\Module\Monitor\TestConfiguration |
41
|
|
|
*/ |
42
|
|
|
public function getTestConfiguration(): TestConfiguration |
43
|
|
|
{ |
44
|
|
|
return $this->configuration; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param \SimpleSAML\Module\Monitor\TestConfiguration $testConfiguration |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
private function setTestConfiguration(TestConfiguration $testConfiguration): void |
53
|
|
|
{ |
54
|
|
|
$this->configuration = $testConfiguration; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
|
public function getResults(): array |
62
|
|
|
{ |
63
|
|
|
return $this->results; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return integer |
69
|
|
|
*/ |
70
|
|
|
public function getState(): int |
71
|
|
|
{ |
72
|
|
|
$filtered = array_diff($this->state, [State::SKIPPED, State::NOSTATE]); |
73
|
|
|
return empty($filtered) ? State::NOSTATE : min($filtered); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
private function invokeModuleCheck(): void |
81
|
|
|
{ |
82
|
|
|
$testsuite = new TestSuite\Modules($this->configuration); |
83
|
|
|
$this->results['modules'] = $testsuite->getArrayizeTestResults(); |
84
|
|
|
$this->state[] = $testsuite->calculateState(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
private function invokeConfigurationCheck(): void |
92
|
|
|
{ |
93
|
|
|
$testsuite = new TestSuite\Configuration($this->configuration); |
94
|
|
|
$this->results['configuration'] = $testsuite->getArrayizeTestResults(); |
95
|
|
|
$this->state[] = $testsuite->calculateState(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return void |
101
|
|
|
*/ |
102
|
|
|
private function invokeStoreCheck(): void |
103
|
|
|
{ |
104
|
|
|
$testsuite = new TestSuite\Store($this->configuration); |
105
|
|
|
$this->results['store'] = $testsuite->getArrayizeTestResults(); |
106
|
|
|
$this->state[] = $testsuite->calculateState(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
private function invokeAuthSourceCheck(): void |
114
|
|
|
{ |
115
|
|
|
$testsuite = new TestSuite\AuthSources($this->configuration); |
116
|
|
|
$testResult = $testsuite->getTestResult(); |
117
|
|
|
$this->state[] = $testsuite->calculateState(); |
118
|
|
|
$this->results['authsources'] = $testResult->getOutput(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return void |
124
|
|
|
*/ |
125
|
|
|
private function invokeMetadataCheck(): void |
126
|
|
|
{ |
127
|
|
|
$testsuite = new TestSuite\Metadata($this->configuration); |
128
|
|
|
$testResult = $testsuite->getTestResult(); |
129
|
|
|
$this->state[] = $testsuite->calculateState(); |
130
|
|
|
$this->results['metadata'] = $testResult->getOutput(); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|