]> BookStack Code Mirror - bookstack/blob - tests/Auth/LdapTest.php
Cleaned tests up, Started LDAP tests, Created LDAP wrapper
[bookstack] / tests / Auth / LdapTest.php
1 <?php
2
3 use BookStack\Services\LdapService;
4 use BookStack\User;
5
6 class LdapTest extends \TestCase
7 {
8
9     protected $mockLdap;
10     protected $mockUser;
11     protected $resourceId = 'resource-test';
12
13     public function setUp()
14     {
15         parent::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();
20     }
21
22     public function test_ldap_login()
23     {
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')]
32             ]]);
33         $this->mockLdap->shouldReceive('bind')->times(1)->andReturn(true);
34
35         $this->visit('/login')
36             ->see('Username')
37             ->type($this->mockUser->name, '#username')
38             ->type($this->mockUser->password, '#password')
39             ->press('Sign In')
40             ->seePageIs('/login')->see('Please enter an email to use for this account.');
41     }
42
43 }