1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
<?php
namespace Auth;
require_once __DIR__.'/../Base.php';
function ldap_connect($hostname, $port)
{
return LdapTest::$functions->ldap_connect($hostname, $port);
}
function ldap_set_option()
{
}
function ldap_bind($ldap, $ldap_username, $ldap_password)
{
return LdapTest::$functions->ldap_bind($ldap, $ldap_username, $ldap_password);
}
class LdapTest extends \Base
{
public static $functions;
public function setUp()
{
parent::setup();
self::$functions = $this
->getMockBuilder('stdClass')
->setMethods(array(
'ldap_connect',
'ldap_set_option',
'ldap_bind',
))
->getMock();
}
public function tearDown()
{
parent::tearDown();
self::$functions = null;
}
public function testConnectSuccess()
{
self::$functions
->expects($this->once())
->method('ldap_connect')
->with(
$this->equalTo('my_ldap_server'),
$this->equalTo(389)
)
->will($this->returnValue('my_ldap_resource'));
$ldap = new Ldap($this->container);
$this->assertNotFalse($ldap->connect());
}
public function testConnectFailure()
{
self::$functions
->expects($this->once())
->method('ldap_connect')
->with(
$this->equalTo('my_ldap_server'),
$this->equalTo(389)
)
->will($this->returnValue(false));
$ldap = new Ldap($this->container);
$this->assertFalse($ldap->connect());
}
public function testBindAnonymous()
{
self::$functions
->expects($this->once())
->method('ldap_bind')
->with(
$this->equalTo('my_ldap_connection'),
$this->equalTo(null),
$this->equalTo(null)
)
->will($this->returnValue(true));
$ldap = new Ldap($this->container);
$this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'anonymous'));
}
public function testBindUser()
{
self::$functions
->expects($this->once())
->method('ldap_bind')
->with(
$this->equalTo('my_ldap_connection'),
$this->equalTo('uid=my_user'),
$this->equalTo('my_password')
)
->will($this->returnValue(true));
$ldap = new Ldap($this->container);
$this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'user', 'uid=%s', 'something'));
}
public function testBindProxy()
{
self::$functions
->expects($this->once())
->method('ldap_bind')
->with(
$this->equalTo('my_ldap_connection'),
$this->equalTo('someone'),
$this->equalTo('something')
)
->will($this->returnValue(true));
$ldap = new Ldap($this->container);
$this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'proxy', 'someone', 'something'));
}
}
|