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\Search |
11
|
|
|
*/ |
12
|
|
|
class TestLdapSearchTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
public function testSearchSuccesful() |
15
|
|
|
{ |
16
|
|
|
$authSourceData = [ |
17
|
|
|
'search.base' => 'OU=example,DC=example,DC=org', |
18
|
|
|
'search.username' => 'testuser', |
19
|
|
|
'search.password' => 'password', |
20
|
|
|
]; |
21
|
|
|
$connectionMock = $this->getMock('LdapSearch', array('searchfordn')); |
22
|
|
|
$connectionMock->expects($this->once())->method('searchfordn')->will($this->returnValue(true)); |
23
|
|
|
$confTest = new TestCase\AuthSource\Ldap\Search( |
24
|
|
|
new TestData([ |
25
|
|
|
'authSourceData' => $authSourceData, |
26
|
|
|
'connection' => $connectionMock, |
27
|
|
|
]) |
28
|
|
|
); |
29
|
|
|
$testResult = $confTest->getTestResult(); |
30
|
|
|
|
31
|
|
|
$this->assertEquals(State::OK, $testResult->getState()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testSearchFailed() |
35
|
|
|
{ |
36
|
|
|
$authSourceData = [ |
37
|
|
|
'search.base' => 'OU=example,DC=example,DC=org', |
38
|
|
|
'search.username' => 'CN=testuser,OU=example,DC=example,DC=org', |
39
|
|
|
'search.password' => 'password', |
40
|
|
|
]; |
41
|
|
|
$connectionMock = $this->getMock('LdapSearch', array('searchfordn')); |
42
|
|
|
$connectionMock->expects($this->once())->method('searchfordn')->will($this->throwException(new \SimpleSAML_Error_Error('UNHANDLEDEXCEPTION'))); |
43
|
|
|
$confTest = new TestCase\AuthSource\Ldap\Search( |
44
|
|
|
new TestData([ |
45
|
|
|
'authSourceData' => $authSourceData, |
46
|
|
|
'connection' => $connectionMock, |
47
|
|
|
]) |
48
|
|
|
); |
49
|
|
|
$testResult = $confTest->getTestResult(); |
50
|
|
|
|
51
|
|
|
$this->assertEquals(State::ERROR, $testResult->getState()); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|