Skip to content

Commit ebcf7b7

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: Remove void return type from test methods Added basque translations Updated Luxembourgish translations [Mailer] Fix parsing Dsn with empty user/password Normalize exceptions messages containing methods references [Ldap] Incorrect determination of RelativeDistinguishedName for the "move" operation
2 parents e204da5 + ce96de9 commit ebcf7b7

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Adapter/ExtLdap/EntryManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function addAttributeValues(Entry $entry, string $attribute, array $value
7979
$con = $this->getConnectionResource();
8080

8181
if (!@ldap_mod_add($con, $entry->getDn(), [$attribute => $values])) {
82-
throw new LdapException(sprintf('Could not add values to entry "%s", attribute %s: ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
82+
throw new LdapException(sprintf('Could not add values to entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
8383
}
8484
}
8585

@@ -94,7 +94,7 @@ public function removeAttributeValues(Entry $entry, string $attribute, array $va
9494
$con = $this->getConnectionResource();
9595

9696
if (!@ldap_mod_del($con, $entry->getDn(), [$attribute => $values])) {
97-
throw new LdapException(sprintf('Could not remove values from entry "%s", attribute %s: ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
97+
throw new LdapException(sprintf('Could not remove values from entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
9898
}
9999
}
100100

@@ -159,7 +159,7 @@ public function applyOperations(string $dn, iterable $operations): void
159159

160160
private function parseRdnFromEntry(Entry $entry): string
161161
{
162-
if (!preg_match('/^([^,]+),/', $entry->getDn(), $matches)) {
162+
if (!preg_match('/(^[^,\\\\]*(?:\\\\.[^,\\\\]*)*),/', $entry->getDn(), $matches)) {
163163
throw new LdapException(sprintf('Entry "%s" malformed, could not parse RDN.', $entry->getDn()));
164164
}
165165

Tests/Adapter/ExtLdap/EntryManagerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,34 @@ public function testGetResources()
4444
$entryManager = new EntryManager($connection);
4545
$entryManager->update($entry);
4646
}
47+
48+
/**
49+
* @see https://tools.ietf.org/html/rfc4514#section-3
50+
*
51+
* @dataProvider moveWithRFC4514DistinguishedNameProvider
52+
*/
53+
public function testMoveWithRFC4514DistinguishedName(string $dn, string $expectedRdn)
54+
{
55+
$connection = $this->createMock(Connection::class);
56+
57+
$entry = new Entry($dn);
58+
$entryManager = new EntryManager($connection);
59+
60+
$method = (new \ReflectionClass(EntryManager::class))->getMethod('parseRdnFromEntry');
61+
$method->setAccessible(true);
62+
63+
$cn = $method->invokeArgs($entryManager, [$entry, 'a']);
64+
65+
$this->assertSame($expectedRdn, $cn);
66+
}
67+
68+
public function moveWithRFC4514DistinguishedNameProvider(): array
69+
{
70+
return [
71+
['CN=Simple,DC=example,DC=net', 'CN=Simple'],
72+
['CN=James \"Jim\" Smith\, III,DC=example,DC=net', 'CN=James \"Jim\" Smith\, III'],
73+
['UID=jsmith,DC=example,DC=net', 'UID=jsmith'],
74+
["CN=Before\0dAfter,DC=example,DC=net", "CN=Before\0dAfter"],
75+
];
76+
}
4777
}

0 commit comments

Comments
 (0)