1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor\TestSuite; |
4
|
|
|
|
5
|
|
|
use \SimpleSAML\Module\monitor\TestConfiguration as TestConfiguration; |
6
|
|
|
use \SimpleSAML\Module\monitor\State as State; |
7
|
|
|
use \SimpleSAML\Module\monitor\TestCase as TestCase; |
8
|
|
|
use \SimpleSAML\Module\monitor\TestData as TestData; |
9
|
|
|
|
10
|
|
|
class Modules extends \SimpleSAML\Module\monitor\TestSuiteFactory |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private $requiredApacheModules = array(); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
// Important!! Modules-names are handled case-sensitive!! |
21
|
|
|
private $storeApacheDependencies = array(); |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private $moduleApacheDependencies = array( |
27
|
|
|
'negotiateext' => 'mod_auth_kerb|mod_auth_gssapi' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $requiredPhpModules = array(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private $storePhpDependencies = array( |
39
|
|
|
'memcache' => 'memcached|memcache', |
40
|
|
|
'phpsession' => 'session', |
41
|
|
|
'redis' => 'redis', |
42
|
|
|
'redissentinel' => 'redis', |
43
|
|
|
'riak:Store' => 'riak', |
44
|
|
|
'sql' => 'PDO' |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
private $modulePhpDependencies = array( |
51
|
|
|
'authfacebook' => array('curl', 'json'), |
52
|
|
|
'authYubiKey' => 'curl', |
53
|
|
|
// TODO: consent only requires pdo when database backend is used.. Should probably add this to required-list when processing metadata |
54
|
|
|
// 'consent' => 'PDO', |
55
|
|
|
'consentAdmin' => 'PDO', |
56
|
|
|
'ldap' => 'ldap', |
57
|
|
|
'memcacheMonitor' => 'memcached|memcache', |
58
|
|
|
'negotiate' => 'krb5', |
59
|
|
|
'radius' => 'radius', |
60
|
|
|
'riak' => 'riak', |
61
|
|
|
'sqlauth' => 'PDO' |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param TestData|null $testData |
66
|
|
|
* |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
protected function initialize($testData = null) |
70
|
|
|
{ |
71
|
|
|
$this->setRequiredApacheModules(); |
|
|
|
|
72
|
|
|
$this->setRequiredPhpModules(); |
73
|
|
|
$this->setRequiredSspModules(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
private function addRequiredPhpModule($module) |
80
|
|
|
{ |
81
|
|
|
if (!in_array($module, $this->requiredPhpModules)) { |
82
|
|
|
$this->requiredPhpModules[] = $module; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
private function setRequiredPhpModules() |
91
|
|
|
{ |
92
|
|
|
// PHP modules required |
93
|
|
|
$composerFile = \SimpleSAML\Utils\System::resolvePath('composer.json'); |
94
|
|
|
$composerData = file_get_contents($composerFile); |
95
|
|
|
$composer = json_decode($composerData, true); |
96
|
|
|
$composerRequired = $composer['require']; |
97
|
|
|
|
98
|
|
|
foreach ($composerRequired as $ext => $ver) { |
99
|
|
|
if (preg_match('/^ext-/', $ext)) { |
100
|
|
|
$this->addRequiredPhpModule(substr($ext, 4)); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// Determine extra required modules |
105
|
|
|
$configuration = $this->getConfiguration(); |
106
|
|
|
$globalConfig = $configuration->getGlobalConfig(); |
107
|
|
|
$store = $globalConfig->getValue('store.type'); |
108
|
|
|
if (array_key_exists($store, $this->storePhpDependencies)) { |
109
|
|
|
$this->addRequiredPhpModule($this->storePhpDependencies[$store]); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
private function setRequiredSspModules() |
117
|
|
|
{ |
118
|
|
|
$modules = \SimpleSAML\Module::getModules(); |
119
|
|
|
foreach ($modules as $module) { |
120
|
|
|
if (\SimpleSAML\Module::isModuleEnabled($module)) { |
121
|
|
|
if (array_key_exists($module, $this->moduleApacheDependencies)) { |
122
|
|
|
$dependencies = \SimpleSAML\Utils\Arrays::Arrayize($this->moduleApacheDependencies[$module]); |
123
|
|
|
foreach ($dependencies as $dependency) { |
124
|
|
|
$this->addRequiredApacheModule($dependency); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
if (array_key_exists($module, $this->modulePhpDependencies)) { |
128
|
|
|
$dependencies = \SimpleSAML\Utils\Arrays::Arrayize($this->modulePhpDependencies[$module]); |
129
|
|
|
foreach ($dependencies as $dependency) { |
130
|
|
|
$this->addRequiredPhpModule($dependency); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
public function getAvailableApacheModules() |
141
|
|
|
{ |
142
|
|
|
$configuration = $this->getConfiguration(); |
143
|
|
|
return $configuration->getAvailableApacheModules(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return array |
148
|
|
|
*/ |
149
|
|
|
public function getAvailablePhpModules() |
150
|
|
|
{ |
151
|
|
|
$configuration = $this->getConfiguration(); |
152
|
|
|
return $configuration->getAvailablePhpModules(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return array |
157
|
|
|
*/ |
158
|
|
|
private function getRequiredApacheModules() |
159
|
|
|
{ |
160
|
|
|
return $this->requiredApacheModules; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return array |
166
|
|
|
*/ |
167
|
|
|
private function getRequiredPhpModules() |
168
|
|
|
{ |
169
|
|
|
return $this->requiredPhpModules; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return array<string,array> |
175
|
|
|
*/ |
176
|
|
|
private function getModuleDependencies() |
|
|
|
|
177
|
|
|
{ |
178
|
|
|
return ['Apache' => $this->moduleApacheDependencies, 'Php' => $this->modulePhpDependencies]; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return void |
183
|
|
|
*/ |
184
|
|
|
protected function invokeTestSuite() |
185
|
|
|
{ |
186
|
|
|
$configuration = $this->getConfiguration(); |
187
|
|
|
|
188
|
|
|
// Test Apache modules |
189
|
|
|
$testData = new TestData([ |
190
|
|
|
'available' => $configuration->getAvailableApacheModules(), |
191
|
|
|
'required' => $this->getRequiredApacheModules(), |
192
|
|
|
'dependencies' => $this->moduleApacheDependencies, |
193
|
|
|
'type' => 'Apache', |
194
|
|
|
'testClass' => TestCase\Module\Apache, |
195
|
|
|
]); |
196
|
|
|
$apacheTest = new Modules\ModuleSet($configuration, $testData); |
197
|
|
|
$apacheTestResult = $apacheTest->getTestResult(); |
198
|
|
|
|
199
|
|
|
// Test Php modules |
200
|
|
|
$testData = new TestData([ |
201
|
|
|
'available' => $configuration->getAvailablePhpModules(), |
202
|
|
|
'required' => $this->getRequiredPhpModules(), |
203
|
|
|
'dependencies' => $this->modulePhpDependencies, |
204
|
|
|
'type' => 'Php', |
205
|
|
|
'testClass' => TestCase\Module\Php, |
206
|
|
|
]); |
207
|
|
|
$phpTest = new Modules\ModuleSet($configuration, $testData); |
208
|
|
|
$phpTestResult = $phpTest->getTestResult(); |
209
|
|
|
|
210
|
|
|
// TODO: Sort out code below |
211
|
|
|
$this->processTestResults($apacheTestResult, $phpTestResult); |
|
|
|
|
212
|
|
|
|
213
|
|
|
$this->calculateState(); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param array $output |
218
|
|
|
* |
219
|
|
|
* @return void |
220
|
|
|
*/ |
221
|
|
|
protected function processTestResults($output) |
222
|
|
|
{ |
223
|
|
|
$availableModules = $this->getAvailableModules(); |
|
|
|
|
224
|
|
|
$tests = $this->getTests(); |
225
|
|
|
|
226
|
|
|
foreach ($availableModules as $category => $available) { |
227
|
|
|
$categories = array_fill(0, count($tests), $category); |
228
|
|
|
if (!isSet($output[$category])) { |
229
|
|
|
$modules = array_map( |
230
|
|
|
function($test, $category) { |
231
|
|
|
return ($test->getCategory() === $category) ? $test->getModuleName() : false; |
232
|
|
|
}, $tests, $categories |
233
|
|
|
); |
234
|
|
|
$modules = array_diff($modules, array(false)); |
235
|
|
|
$output[$category][] = array(State::OK, $category, implode(', ', $modules), "All required modules are loaded"); |
236
|
|
|
} |
237
|
|
|
$this->addMessages($output[$category], $category); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.