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