3 use BookStack\Services\LdapService;
6 class LdapTest extends \TestCase
11 protected $resourceId = 'resource-test';
13 public function setUp()
16 app('config')->set(['auth.method' => 'ldap', 'services.ldap.base_dn' => 'dc=ldap,dc=local', 'auth.providers.users.driver' => 'ldap']);
17 $this->mockLdap = Mockery::mock(BookStack\Services\Ldap::class);
18 $this->app['BookStack\Services\Ldap'] = $this->mockLdap;
19 $this->mockUser = factory(User::class)->make();
22 public function test_ldap_login()
24 $this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
25 $this->mockLdap->shouldReceive('setOption')->once();
26 $this->mockLdap->shouldReceive('searchAndGetEntries')->twice()
27 ->with($this->resourceId, config('services.ldap.base_dn'), Mockery::type('string'), Mockery::type('array'))
28 ->andReturn(['count' => 1, 0 => [
29 'uid' => [$this->mockUser->name],
30 'cn' => [$this->mockUser->name],
31 'dn' => ['dc=test'.config('services.ldap.base_dn')]
33 $this->mockLdap->shouldReceive('bind')->times(1)->andReturn(true);
35 $this->visit('/login')
37 ->type($this->mockUser->name, '#username')
38 ->type($this->mockUser->password, '#password')
40 ->seePageIs('/login')->see('Please enter an email to use for this account.');