protected function getMockConnection($methods = []) { $defaults = ['isBound', 'search', 'getEntries', 'bind', 'close']; $connection = $this->getMockBuilder(Ldap::class)->setMethods(array_merge($defaults, $methods))->getMock(); Adldap::getDefaultProvider()->setConnection($connection); return $connection; }
/** * Execute the command. */ public function handle() { $computers = Adldap::search()->computers()->get(); $i = 0; foreach ($computers as $computer) { if ($this->dispatch(new ImportComputer($computer))) { ++$i; } } $this->info("Successfully synchronized: {$i} computers."); }
/** * Execute the command. */ public function handle() { $users = Adldap::search()->users()->whereHas('mail')->whereObjectclass('user')->get(); $i = 0; if (count($users) > 0) { foreach ($users as $user) { if ($user instanceof User && $this->dispatch(new ImportUser($user))) { ++$i; } } } $this->info("Successfully synchronized: {$i} users."); }
/** * Returns the root Adldap provider instance. * * @param string $provider * * @return \Adldap\Connections\ProviderInterface */ protected function getAdldap($provider = null) { $provider = $provider ?: $this->getDefaultConnectionName(); return Adldap::getProvider($provider); }
public function testLimitationFilter() { $this->app['config']->set('adldap_auth.limitation_filter', '(mail=*)'); $credentials = ['email' => '*****@*****.**', 'password' => 'Password123']; $mockedUser = Mockery::mock('Adldap\\Models\\User'); $mockedUser->shouldReceive('getAttribute')->andReturn('jdoe'); $mockedSearch = Mockery::mock('Adldap\\Classes\\Search'); $mockedSearch->shouldReceive('select')->once()->andReturn($mockedSearch)->shouldReceive('rawFilter')->once()->withArgs(['(mail=*)'])->andReturn($mockedSearch)->shouldReceive('whereEquals')->once()->andReturn($mockedSearch)->shouldReceive('first')->once()->andReturn($mockedUser); $mockedUsers = Mockery::mock('Adldap\\Classes\\Users'); $mockedUsers->shouldReceive('search')->once()->andReturn($mockedSearch); Adldap::shouldReceive('users')->once()->andReturn($mockedUsers)->shouldReceive('authenticate')->once()->andReturn(true); $outcome = Auth::attempt($credentials); $this->assertTrue($outcome); }
public function testCredentialsKeyDoesNotExist() { $mockedSearch = Mockery::mock('Adldap\\Classes\\Search'); $mockedSearch->shouldReceive('select')->once()->andReturn($mockedSearch); $mockedUsers = Mockery::mock('Adldap\\Classes\\Users'); $mockedUsers->shouldReceive('search')->once()->andReturn($mockedSearch); Adldap::shouldReceive('users')->once()->andReturn($mockedUsers); $nonExistantInputKey = 'non-existent-key'; $this->setExpectedException('ErrorException'); Auth::attempt([$nonExistantInputKey => '*****@*****.**', 'password' => '12345']); }
/** * Authenticates a user against Active Directory. * * @param string $username * @param string $password * * @return bool */ protected function authenticate($username, $password) { return Adldap::authenticate($username, $password); }
/** * Returns a new Adldap user query. * * @return \Adldap\Query\Builder */ protected function newAdldapUserQuery() { /** @var \Adldap\Query\Builder $query */ $query = Adldap::users()->search(); $filter = $this->getLimitationFilter(); if (!empty($filter)) { // If we're provided a login limitation filter, // we'll add it to the user query. $query->rawFilter($filter); } return $query->select($this->getSelectAttributes()); }
/** * Returns true / false if the specified * computer exists in active directory. * * @return bool */ public function handle() { $computer = Adldap::search()->computers()->find($this->name); return $computer instanceof Computer; }
/** * Returns the root Adldap instance. * * @param string $provider * * @return \Adldap\Contracts\Connections\ProviderInterface */ protected function getAdldap($provider = null) { /** @var \Adldap\Adldap $ad */ $ad = Adldap::getFacadeRoot(); if (is_null($provider)) { $provider = $this->getDefaultConnectionName(); } return $ad->getManager()->get($provider); }
public function test_config_login_fallback_no_connection() { $this->app['config']->set('adldap_auth.login_fallback', true); $mockedProvider = $this->mock(Provider::class); $mockedSearch = $this->mock(Factory::class); $mockedConnection = $this->mock(ConnectionInterface::class); $mockedConnection->shouldReceive('isBound')->once()->andReturn(false); $mockedSearch->shouldReceive('select')->once()->andReturn($mockedSearch); $mockedSearch->shouldReceive('users')->once()->andReturn($mockedSearch); $mockedSearch->shouldReceive('getConnection')->once()->andReturn($mockedConnection); $manager = new Manager(); $manager->add('default', $mockedProvider); $mockedProvider->shouldReceive('search')->once()->andReturn($mockedSearch); Adldap::shouldReceive('getManager')->andReturn($manager); EloquentUser::create(['email' => '*****@*****.**', 'name' => 'John Doe', 'password' => bcrypt('Password123')]); $credentials = ['email' => '*****@*****.**', 'password' => 'Password123']; $outcome = Auth::attempt($credentials); $user = \Auth::user(); $this->assertTrue($outcome); $this->assertInstanceOf('Adldap\\Laravel\\Tests\\Models\\User', $user); $this->assertEquals('*****@*****.**', $user->email); }