1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\monitor\TestCase\AuthSource\Ldap; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use SimpleSAML\Configuration as SspConfiguration; |
9
|
|
|
use SimpleSAML\Module\ldap\ConnectorInterface; |
|
|
|
|
10
|
|
|
use SimpleSAML\Module\ldap\Connector\Ldap as LdapConnector; |
|
|
|
|
11
|
|
|
use SimpleSAML\Module\monitor\State; |
12
|
|
|
use SimpleSAML\Module\monitor\TestData; |
13
|
|
|
use SimpleSAML\Module\monitor\TestResult; |
14
|
|
|
|
15
|
|
|
use function preg_match; |
16
|
|
|
use function str_replace; |
17
|
|
|
|
18
|
|
|
final class Configuration extends \SimpleSAML\Module\monitor\TestCaseFactory |
19
|
|
|
{ |
20
|
|
|
/** @var \SimpleSAML\Module\ConnectorInterface|null */ |
|
|
|
|
21
|
|
|
private ?ConnectorInterface $connection = null; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private string $hostname = ''; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private string $encryption = 'none'; |
28
|
|
|
|
29
|
|
|
/** @var integer */ |
30
|
|
|
private int $version = 3; |
31
|
|
|
|
32
|
|
|
/** @var integer */ |
33
|
|
|
private int $timeout = 3; |
34
|
|
|
|
35
|
|
|
/** @var bool */ |
36
|
|
|
private bool $referrals = false; |
37
|
|
|
|
38
|
|
|
/** @var bool */ |
39
|
|
|
private bool $debug = false; |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param \SimpleSAML\Module\monitor\TestData $testData |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
protected function initialize(TestData $testData): void |
48
|
|
|
{ |
49
|
|
|
$authSourceData = $testData->getInputItem('authSourceData'); |
50
|
|
|
$this->hostname = $authSourceData->getOptionalString('connection_string', '<< unset >>'); |
51
|
|
|
$this->encryption = $authSourceData->getOptionalString('encryption', 'none'); |
52
|
|
|
$this->version = $authSourceData->getOptionalInteger('version', 3); |
53
|
|
|
$this->timeout = $authSourceData->getOptionalInteger('timeout', 3); |
54
|
|
|
$this->referrals = $authSourceData->getOptionalBoolean('referrals', false); |
55
|
|
|
$this->debug = $authSourceData->getOptionalBoolean('debug', false); |
56
|
|
|
|
57
|
|
|
$this->setSubject($this->hostname); |
58
|
|
|
|
59
|
|
|
parent::initialize($testData); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function invokeTest(): void |
67
|
|
|
{ |
68
|
|
|
if (preg_match('/^(ldap[s]?:\/\/(.*))$/', $this->hostname, $matches)) { |
69
|
|
|
$connectString = $this->hostname; |
70
|
|
|
} else { |
71
|
|
|
$connectString = $this->hostname . ':' . $this->port; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$testResult = new TestResult('LDAP configuration', $connectString); |
75
|
|
|
|
76
|
|
|
try { |
77
|
|
|
$this->connection = new LdapConnector( |
78
|
|
|
$this->hostname, |
79
|
|
|
$this->encryption, |
80
|
|
|
$this->version, |
81
|
|
|
'ext_ldap', |
82
|
|
|
$this->debug, |
83
|
|
|
['network_timeout' => $this->timeout, 'referrals' => $this->referrals], |
84
|
|
|
); |
85
|
|
|
$state = State::OK; |
86
|
|
|
} catch (Exception $error) { |
87
|
|
|
$state = State::FATAL; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (isset($error)) { |
91
|
|
|
// When you feed str_replace a string, outcome will be string too, but Psalm doesn't see it that way |
92
|
|
|
$msg = str_replace('Library - LDAP __construct(): ', '', $error->getMessage()); |
93
|
|
|
} else { |
94
|
|
|
$msg = 'Configuration syntax OK'; |
95
|
|
|
$testResult->addOutput($this->connection, 'connection'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$testResult->setState($state); |
99
|
|
|
$testResult->setMessage($msg); |
100
|
|
|
$this->setTestResult($testResult); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths