function let(LdapManager $ldap, LdapQueryBuilder $qb, LdapQuery $query, LdapConnectionInterface $connection) { $groups = new LdapObjectCollection(); $groups->add(new LdapObject(['name' => 'Foo', 'dn' => 'cn=Foo,dc=example,dc=local'])); $groups->add(new LdapObject(['guid' => '291d8444-9d5b-4b0a-a6d7-853408f704d5', 'dn' => 'cn=Bar,dc=example,dc=local'])); $groups->add(new LdapObject(['sid' => 'S-1-5-18', 'dn' => 'cn=LocalSys,dc=example,dc=local'])); $groups->add(new LdapObject(['name' => 'Just a DN', 'dn' => 'cn=Stuff,dc=example,dc=local'])); $roleMap = ['ROLE_AWESOME' => ['foo'], 'ROLE_ADMIN' => ['291d8444-9d5b-4b0a-a6d7-853408f704d5'], 'ROLE_DN' => ['cn=Stuff,dc=example,dc=local'], 'ROLE_SID' => ['S-1-5-18']]; $attrMap = ['username' => 'username', 'accountNonLocked' => 'locked', 'accountNonExpired' => 'accountExpirationDate', 'enabled' => 'disabled', 'credentialsNonExpired' => 'passwordMustChange', 'guid' => 'guid', 'groups' => 'groups', 'stringRepresentation' => 'username']; $config = new DomainConfiguration('foo.bar'); $filter = new ADFilterBuilder(); $ldapObject = new LdapObject($this->attr, ['user'], ['user'], 'user'); $query->getSingleResult()->willReturn($ldapObject); $query->getResult()->willReturn($groups); $query->getArrayResult()->willReturn([['name' => 'foo'], ['name' => 'bar']]); $qb->from(LdapObjectType::USER)->willReturn($qb); $qb->from('group')->willReturn($qb); $qb->select(["username", "locked", "accountExpirationDate", "disabled", "passwordMustChange", "guid", "groups", "username"])->willReturn($qb); $qb->select(["name", "sid", "guid"])->willReturn($qb); $qb->select('name')->willReturn($qb); $qb->where(['username' => 'foo'])->willReturn($qb); $qb->getLdapQuery()->willReturn($query); $qb->filter()->willReturn($filter); $qb->where($filter->hasMemberRecursively($this->attr['guid'], 'members'))->willReturn($qb); $ldap->buildLdapQuery()->willReturn($qb); $connection->getConfig()->willReturn($config); $ldap->getConnection()->willReturn($connection); $this->beConstructedWith($ldap, $attrMap, $roleMap, true); }
function it_should_throw_a_user_not_found_exception_if_too_many_results_are_returned_from_ldap() { $this->query->getSingleResult()->willThrow(new MultiResultException()); $this->shouldThrow('\\Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException')->duringLoadUserByUsername('foo'); }