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; |
|
|
|
|
9
|
|
|
use SimpleSAML\Module\ldap\ConnectorInterface; |
|
|
|
|
10
|
|
|
use SimpleSAML\Module\monitor\State; |
11
|
|
|
use SimpleSAML\Module\monitor\TestData; |
12
|
|
|
use SimpleSAML\Module\monitor\TestResult; |
13
|
|
|
|
14
|
|
|
use function str_replace; |
15
|
|
|
|
16
|
|
|
final class Bind extends \SimpleSAML\Module\monitor\TestCaseFactory |
17
|
|
|
{ |
18
|
|
|
/** @var \SimpleSAML\Module\ldap\ConnectorInterface */ |
19
|
|
|
private ConnectorInterface $connection; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
private string $username; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
private string $password; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param \SimpleSAML\Module\monitor\TestData $testData |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
protected function initialize(TestData $testData): void |
34
|
|
|
{ |
35
|
|
|
$this->connection = $testData->getInputItem('connection'); |
36
|
|
|
$authSourceData = $testData->getInputItem('authSourceData'); |
37
|
|
|
|
38
|
|
|
$this->username = $authSourceData->getString('search.username'); |
39
|
|
|
$this->password = $authSourceData->getString('search.password'); |
40
|
|
|
|
41
|
|
|
parent::initialize($testData); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
public function invokeTest(): void |
49
|
|
|
{ |
50
|
|
|
try { |
51
|
|
|
$bind = $this->connection->bind($this->username, $this->password); |
|
|
|
|
52
|
|
|
} catch (Exception $error) { |
53
|
|
|
// Fallthru |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$testResult = new TestResult('LDAP Bind', $this->username); |
57
|
|
|
if (isset($error)) { |
58
|
|
|
$msg = str_replace('Library - LDAP bind(): ', '', $error->getMessage()); |
59
|
|
|
$testResult->setState(State::FATAL); |
60
|
|
|
} else { |
61
|
|
|
$msg = 'Bind succesful'; |
62
|
|
|
$testResult->setState(State::OK); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$testResult->setMessage($msg); |
66
|
|
|
$this->setTestResult($testResult); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: