Skip to content

Commit 698d2df

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: Fix LICENSE CI check fixes retrieving multiple values for extra fields [String] Remove duplicates in fold maps fail with a meaningful error when a needed package is missing [DependencyInjection] Fix combinatory explosion when autowiring union and intersection types Update license years (last time) [Tests] New iteration of removing `$this` occurrences in future static data providers
2 parents c5c9736 + 7ae6e91 commit 698d2df

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2004-2023 Fabien Potencier
1+
Copyright (c) 2004-present Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

Security/LdapUserProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ private function getAttributeValue(Entry $entry, string $attribute)
174174
}
175175

176176
$values = $entry->getAttribute($attribute);
177+
if (!\in_array($attribute, [$this->uidKey, $this->passwordAttribute])) {
178+
return $values;
179+
}
177180

178181
if (1 !== \count($values)) {
179182
throw new InvalidArgumentException(sprintf('Attribute "%s" has multiple values.', $attribute));

Tests/Security/LdapUserProviderTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,52 @@ public function testLoadUserByIdentifierIsSuccessfulWithPasswordAttribute()
333333
$this->assertInstanceOf(LdapUser::class, $provider->loadUserByIdentifier('foo'));
334334
}
335335

336+
public function testLoadUserByIdentifierIsSuccessfulWithMultipleExtraAttributes()
337+
{
338+
$result = $this->createMock(CollectionInterface::class);
339+
$query = $this->createMock(QueryInterface::class);
340+
$query
341+
->expects($this->once())
342+
->method('execute')
343+
->willReturn($result)
344+
;
345+
$ldap = $this->createMock(LdapInterface::class);
346+
$memberOf = [
347+
'cn=foo,ou=MyBusiness,dc=symfony,dc=com',
348+
'cn=bar,ou=MyBusiness,dc=symfony,dc=com',
349+
];
350+
$result
351+
->expects($this->once())
352+
->method('offsetGet')
353+
->with(0)
354+
->willReturn(new Entry('foo', [
355+
'sAMAccountName' => ['foo'],
356+
'userpassword' => ['bar'],
357+
'memberOf' => $memberOf,
358+
]))
359+
;
360+
$result
361+
->expects($this->once())
362+
->method('count')
363+
->willReturn(1)
364+
;
365+
$ldap
366+
->expects($this->once())
367+
->method('escape')
368+
->willReturn('foo')
369+
;
370+
$ldap
371+
->expects($this->once())
372+
->method('query')
373+
->willReturn($query)
374+
;
375+
376+
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, [], 'sAMAccountName', '({uid_key}={user_identifier})', 'userpassword', ['memberOf']);
377+
$user = $provider->loadUserByIdentifier('foo');
378+
$this->assertInstanceOf(LdapUser::class, $user);
379+
$this->assertSame(['memberOf' => $memberOf], $user->getExtraFields());
380+
}
381+
336382
public function testRefreshUserShouldReturnUserWithSameProperties()
337383
{
338384
$ldap = $this->createMock(LdapInterface::class);

0 commit comments

Comments
 (0)