1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\Monitor\Test; |
4
|
|
|
|
5
|
|
|
use SimpleSAML\Configuration; |
6
|
|
|
use SimpleSAML\Module\Monitor\TestCase; |
7
|
|
|
use SimpleSAML\Module\Monitor\TestData; |
8
|
|
|
use SimpleSAML\Module\Monitor\State; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Tests for TestCase\Ldap\Bind |
12
|
|
|
*/ |
13
|
|
|
class TestLdapBindTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
public function testBindSuccesful(): void |
16
|
|
|
{ |
17
|
|
|
$authSourceData = [ |
18
|
|
|
'search.username' => 'testuser', |
19
|
|
|
'search.password' => 'password', |
20
|
|
|
]; |
21
|
|
|
$connectionMock = $this->getMockBuilder('Ldapconnection')->setMethods( |
22
|
|
|
['bind'] |
23
|
|
|
)->disableOriginalConstructor()->getMock(); |
24
|
|
|
$connectionMock->expects($this->once())->method('bind')->will($this->returnValue(true)); |
25
|
|
|
$confTest = new TestCase\AuthSource\Ldap\Bind( |
26
|
|
|
new TestData([ |
27
|
|
|
'authSourceData' => Configuration::loadFromArray($authSourceData), |
28
|
|
|
'connection' => $connectionMock, |
29
|
|
|
]) |
30
|
|
|
); |
31
|
|
|
$testResult = $confTest->getTestResult(); |
32
|
|
|
|
33
|
|
|
$this->assertEquals(State::OK, $testResult->getState()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testBindFailed(): void |
37
|
|
|
{ |
38
|
|
|
$authSourceData = [ |
39
|
|
|
'search.username' => 'testuser', |
40
|
|
|
'search.password' => 'password', |
41
|
|
|
]; |
42
|
|
|
$connectionMock = $this->getMockBuilder('Ldapconnection')->setMethods( |
43
|
|
|
['bind'] |
44
|
|
|
)->disableOriginalConstructor()->getMock(); |
45
|
|
|
$connectionMock->expects($this->once())->method('bind')->will( |
46
|
|
|
$this->throwException(new \Exception()) |
47
|
|
|
); |
48
|
|
|
$confTest = new TestCase\AuthSource\Ldap\Bind( |
49
|
|
|
new TestData([ |
50
|
|
|
'authSourceData' => Configuration::loadFromArray($authSourceData), |
51
|
|
|
'connection' => $connectionMock, |
52
|
|
|
]) |
53
|
|
|
); |
54
|
|
|
$testResult = $confTest->getTestResult(); |
55
|
|
|
|
56
|
|
|
$this->assertEquals(State::FATAL, $testResult->getState()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testAuthenticationFailed(): void |
60
|
|
|
{ |
61
|
|
|
$authSourceData = [ |
62
|
|
|
'search.username' => 'testuser', |
63
|
|
|
'search.password' => 'password', |
64
|
|
|
]; |
65
|
|
|
$connectionMock = $this->getMockBuilder('Ldapconnection')->setMethods( |
66
|
|
|
['bind'] |
67
|
|
|
)->disableOriginalConstructor()->getMock(); |
68
|
|
|
$connectionMock->expects($this->once())->method('bind')->will($this->returnValue(false)); |
69
|
|
|
$confTest = new TestCase\AuthSource\Ldap\Bind( |
70
|
|
|
new TestData([ |
71
|
|
|
'authSourceData' => Configuration::loadFromArray($authSourceData), |
72
|
|
|
'connection' => $connectionMock, |
73
|
|
|
]) |
74
|
|
|
); |
75
|
|
|
$testResult = $confTest->getTestResult(); |
76
|
|
|
|
77
|
|
|
$this->assertEquals(State::ERROR, $testResult->getState()); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|