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']);
 }
 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);
 }
Esempio n. 3
0
 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);
 }