Skip to content
Snippets Groups Projects
Commit ae79284d authored by Hendrik Grahl's avatar Hendrik Grahl
Browse files

Issue #3153216 by grahl: Error: Cannot use object of type...

Issue #3153216 by grahl: Error: Cannot use object of type Symfony\Component\Ldap\Entry as array in Drupal\ldap_servers\LdapGroupManager->groupUserMembershipsFromUserAttr()
parent 9cdd7f69
No related branches found
Tags 8.x-4.0-beta1
No related merge requests found
......@@ -472,7 +472,7 @@ class LdapGroupManager extends LdapBaseManager {
* @return array
* Array of group dns in mixed case or FALSE on error.
*/
public function groupMembershipsFromUser($username): array {
public function groupMembershipsFromUser(string $username): array {
$group_dns = [];
if (!$this->checkAvailability()) {
return $group_dns;
......@@ -505,22 +505,19 @@ class LdapGroupManager extends LdapBaseManager {
* @see groupMembershipsFromUser()
*/
public function groupUserMembershipsFromUserAttr(Entry $ldap_entry): array {
$all_group_dns = [];
if (!$this->checkAvailability() || !$this->server->isGroupUserMembershipAttributeInUse()) {
return $all_group_dns;
return [];
}
$group_attribute = $this->server->getGroupUserMembershipAttribute();
if (!$ldap_entry->hasAttribute($group_attribute, FALSE)) {
return $all_group_dns;
return [];
}
$level = 0;
$all_group_dns = [];
$members_group_dns = $ldap_entry->getAttribute($group_attribute, FALSE);
if (isset($members_group_dns['count'])) {
unset($members_group_dns['count']);
}
$orFilters = [];
foreach ($members_group_dns as $member_group_dn) {
$all_group_dns[] = $member_group_dn;
......
<?php
declare(strict_types = 1);
namespace Drupal\Tests\ldap_servers\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\ldap_servers\Entity\Server;
use Drupal\ldap_servers\FakeBridge;
use Symfony\Component\Ldap\Entry;
/**
* Group manager test.
*
* @group ldap
*/
class GroupManagerTest extends EntityKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['ldap_servers', 'externalauth'];
/**
* Server.
*
* @var \Drupal\ldap_servers\Entity\Server
*/
protected $server;
/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();
$this->installEntitySchema('ldap_server');
$this->server = Server::create(['id' => 'example']);
$this->server->set('grp_user_memb_attr', 'memberOf');
$this->server->set('grp_user_memb_attr_exists', TRUE);
$bridge = new FakeBridge(
$this->container->get('logger.channel.ldap_servers'),
$this->container->get('entity_type.manager')
);
$bridge->setBindResult(TRUE);
$this->container->set('ldap.bridge', $bridge);
}
/**
* Test group users membership from user attribute.
*/
public function testGroupUserMembershipsFromUserAttr(): void {
/** @var \Drupal\ldap_servers\LdapGroupManager $group_manager */
$group_manager = $this->container->get('ldap.group_manager');
$memberships = [
'cn=group1,ou=people,dc=hogwarts,dc=edu',
'cn=group2,ou=people,dc=hogwarts,dc=edu',
];
$entry = new Entry('cn=hpotter,ou=people,dc=hogwarts,dc=edu', [
'cn' => [0 => 'hpotter'],
'mail' => [
0 => 'hpotter@hogwarts.edu',
1 => 'hpotter@students.hogwarts.edu',
],
'memberOf' => $memberships,
]
);
$group_manager->setServer($this->server);
$result = $group_manager->groupUserMembershipsFromUserAttr($entry);
self::assertEquals($memberships, $result);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment