|
12 | 12 | namespace Symfony\Component\Ldap\Tests;
|
13 | 13 |
|
14 | 14 | use Symfony\Component\Ldap\LdapClient;
|
| 15 | +use Symfony\Component\Ldap\Exception\ConnectionException; |
| 16 | +use Symfony\Component\Ldap\Exception\LdapException; |
15 | 17 | use Symfony\Polyfill\Php56\Php56 as p;
|
16 | 18 |
|
17 | 19 | /**
|
18 | 20 | * @requires extension ldap
|
19 | 21 | */
|
20 |
| -class LdapClientTest extends \PHPUnit_Framework_TestCase |
| 22 | +class LdapClientTest extends LdapTestCase |
21 | 23 | {
|
| 24 | + /** |
| 25 | + * Ldap client, only used for the functional tests |
| 26 | + * @var [type] |
| 27 | + */ |
| 28 | + private $ldap; |
| 29 | + |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $this->ldap = new LdapClient($this->getLdapHost(), $this->getLdapPort()); |
| 33 | + } |
| 34 | + |
22 | 35 | public function testLdapEscape()
|
23 | 36 | {
|
24 | 37 | $ldap = new LdapClient();
|
25 | 38 |
|
26 | 39 | $this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", null, p::LDAP_ESCAPE_DN));
|
27 | 40 | }
|
| 41 | + |
| 42 | + /** |
| 43 | + * @group functional |
| 44 | + */ |
| 45 | + public function testLdapQuery() |
| 46 | + { |
| 47 | + $this->ldap->bind('cn=admin,dc=symfony,dc=com', 'symfony'); |
| 48 | + $result = $this->ldap->find('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', array()); |
| 49 | + |
| 50 | + $expected = array( |
| 51 | + 'count' => 1, |
| 52 | + 0 => array( |
| 53 | + 'objectclass' => array( |
| 54 | + 'count' => 4, |
| 55 | + 0 => 'inetOrgPerson', |
| 56 | + 1 => 'organizationalPerson', |
| 57 | + 2 => 'person', |
| 58 | + 3 => 'top', |
| 59 | + ), |
| 60 | + 0 => 'objectclass', |
| 61 | + 'cn' => array( |
| 62 | + 'count' => 1, |
| 63 | + 0 => 'Fabien Potencier', |
| 64 | + ), |
| 65 | + 1 => 'cn', |
| 66 | + 'sn' => array( |
| 67 | + 'count' => 1, |
| 68 | + 0 => 'fabpot', |
| 69 | + ), |
| 70 | + 2 => 'sn', |
| 71 | + 'mail' => array( |
| 72 | + 'count' => 2, |
| 73 | + 0 => 'fabpot@symfony.com', |
| 74 | + 1 => 'fabien@potencier.com', |
| 75 | + ), |
| 76 | + 3 => 'mail', |
| 77 | + 'ou' => array( |
| 78 | + 'count' => 3, |
| 79 | + 0 => 'People', |
| 80 | + 1 => 'Maintainers', |
| 81 | + 2 => 'Founder', |
| 82 | + ), |
| 83 | + 4 => 'ou', |
| 84 | + 'givenname' => array( |
| 85 | + 'count' => 1, |
| 86 | + 0 => 'Fabien Potencier', |
| 87 | + ), |
| 88 | + 5 => 'givenname', |
| 89 | + 'description' => array( |
| 90 | + 'count' => 1, |
| 91 | + 0 => 'Founder and project lead @Symfony', |
| 92 | + ), |
| 93 | + 6 => 'description', |
| 94 | + 'count' => 7, |
| 95 | + 'dn' => 'cn=Fabien Potencier,dc=symfony,dc=com', |
| 96 | + ), |
| 97 | + ); |
| 98 | + |
| 99 | + $this->assertEquals($expected, $result); |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * @group functional |
| 104 | + * @expectedException Symfony\Component\Ldap\Exception\ConnectionException |
| 105 | + */ |
| 106 | + public function testLdapWrongPassword() |
| 107 | + { |
| 108 | + $this->ldap->bind('cn=admin,dc=symfony,dc=com', 'wrongpass'); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * @group functional |
| 113 | + */ |
| 114 | + public function testLdapNotFound() |
| 115 | + { |
| 116 | + $this->ldap->bind('cn=admin,dc=symfony,dc=com', 'symfony'); |
| 117 | + $result = $this->ldap->find('dc=symfony,dc=com', 'uid=nonexistent'); |
| 118 | + |
| 119 | + $this->assertNull($result); |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * @group functional |
| 124 | + * @expectedException Symfony\Component\Ldap\Exception\LdapException |
| 125 | + */ |
| 126 | + public<
6D46
/span> function testLdapInvalidDn() |
| 127 | + { |
| 128 | + $this->ldap->bind('cn=admin,dc=symfony,dc=com', 'symfony'); |
| 129 | + $result = $this->ldap->find('dc=invalid,dc=com', 'uid=nonexistent'); |
| 130 | + } |
28 | 131 | }
|
0 commit comments