Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 2d675c1

Browse files
committed
Added test for login fallbacks with no LDAP connection.
1 parent e764815 commit 2d675c1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/AdldapTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,44 @@ public function test_config_login_fallback()
267267

268268
$this->assertFalse($outcome);
269269
}
270+
271+
public function test_config_login_fallback_no_connection()
272+
{
273+
$this->app['config']->set('adldap_auth.login_fallback', true);
274+
275+
$mockedProvider = $this->mock(Provider::class);
276+
$mockedSearch = $this->mock(Factory::class);
277+
$mockedConnection = $this->mock(ConnectionInterface::class);
278+
279+
$mockedConnection->shouldReceive('isBound')->once()->andReturn(false);
280+
281+
$mockedSearch->shouldReceive('select')->once()->andReturn($mockedSearch);
282+
$mockedSearch->shouldReceive('getConnection')->once()->andReturn($mockedConnection);
283+
284+
$manager = new Manager();
285+
286+
$manager->add('default', $mockedProvider);
287+
$mockedProvider->shouldReceive('search')->once()->andReturn($mockedSearch);
288+
289+
Adldap::shouldReceive('getManager')->andReturn($manager);
290+
291+
EloquentUser::create([
292+
'email' => '[email protected]',
293+
'name' => 'John Doe',
294+
'password' => bcrypt('Password123'),
295+
]);
296+
297+
$credentials = [
298+
'email' => '[email protected]',
299+
'password' => 'Password123',
300+
];
301+
302+
$outcome = Auth::attempt($credentials);
303+
304+
$user = \Auth::user();
305+
306+
$this->assertTrue($outcome);
307+
$this->assertInstanceOf('Adldap\Laravel\Tests\Models\User', $user);
308+
$this->assertEquals('[email protected]', $user->email);
309+
}
270310
}

0 commit comments

Comments
 (0)