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