mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Fixed failing tests caused by auth changes
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
<?php namespace Tests;
|
||||
|
||||
use BookStack\Auth\Role;
|
||||
use BookStack\Auth\Access\Ldap;
|
||||
use BookStack\Auth\User;
|
||||
@ -21,12 +22,16 @@ class LdapTest extends BrowserKitTest
|
||||
if (!defined('LDAP_OPT_REFERRALS')) define('LDAP_OPT_REFERRALS', 1);
|
||||
app('config')->set([
|
||||
'auth.method' => 'ldap',
|
||||
'auth.defaults.guard' => 'ldap',
|
||||
'services.ldap.base_dn' => 'dc=ldap,dc=local',
|
||||
'services.ldap.email_attribute' => 'mail',
|
||||
'services.ldap.display_name_attribute' => 'cn',
|
||||
'services.ldap.id_attribute' => 'uid',
|
||||
'services.ldap.user_to_groups' => false,
|
||||
'auth.providers.users.driver' => 'ldap',
|
||||
'services.ldap.version' => '3',
|
||||
'services.ldap.user_filter' => '(&(uid=${user}))',
|
||||
'services.ldap.follow_referrals' => false,
|
||||
'services.ldap.tls_insecure' => false,
|
||||
]);
|
||||
$this->mockLdap = \Mockery::mock(Ldap::class);
|
||||
$this->app[Ldap::class] = $this->mockLdap;
|
||||
@ -60,16 +65,16 @@ class LdapTest extends BrowserKitTest
|
||||
{
|
||||
$this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->once();
|
||||
$this->mockLdap->shouldReceive('setOption')->times(4);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
|
||||
$this->mockLdap->shouldReceive('setOption')->times(2);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
'cn' => [$this->mockUser->name],
|
||||
'dn' => ['dc=test' . config('services.ldap.base_dn')]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(6)->andReturn(true);
|
||||
$this->mockEscapes(4);
|
||||
$this->mockLdap->shouldReceive('bind')->times(4)->andReturn(true);
|
||||
$this->mockEscapes(2);
|
||||
|
||||
$this->mockUserLogin()
|
||||
->seePageIs('/login')->see('Please enter an email to use for this account.');
|
||||
@ -86,16 +91,16 @@ class LdapTest extends BrowserKitTest
|
||||
$this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->once();
|
||||
$ldapDn = 'cn=test-user,dc=test' . config('services.ldap.base_dn');
|
||||
$this->mockLdap->shouldReceive('setOption')->times(2);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
|
||||
$this->mockLdap->shouldReceive('setOption')->times(1);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(1)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'cn' => [$this->mockUser->name],
|
||||
'dn' => $ldapDn,
|
||||
'mail' => [$this->mockUser->email]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(3)->andReturn(true);
|
||||
$this->mockEscapes(2);
|
||||
$this->mockLdap->shouldReceive('bind')->times(2)->andReturn(true);
|
||||
$this->mockEscapes(1);
|
||||
|
||||
$this->mockUserLogin()
|
||||
->seePageIs('/')
|
||||
@ -109,8 +114,8 @@ class LdapTest extends BrowserKitTest
|
||||
$this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->once();
|
||||
$ldapDn = 'cn=test-user,dc=test' . config('services.ldap.base_dn');
|
||||
$this->mockLdap->shouldReceive('setOption')->times(2);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
|
||||
$this->mockLdap->shouldReceive('setOption')->times(1);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(1)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'cn' => [$this->mockUser->name],
|
||||
@ -120,8 +125,8 @@ class LdapTest extends BrowserKitTest
|
||||
]]);
|
||||
|
||||
|
||||
$this->mockLdap->shouldReceive('bind')->times(3)->andReturn(true);
|
||||
$this->mockEscapes(2);
|
||||
$this->mockLdap->shouldReceive('bind')->times(2)->andReturn(true);
|
||||
$this->mockEscapes(1);
|
||||
|
||||
$this->mockUserLogin()
|
||||
->seePageIs('/')
|
||||
@ -133,16 +138,16 @@ class LdapTest extends BrowserKitTest
|
||||
{
|
||||
$this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->once();
|
||||
$this->mockLdap->shouldReceive('setOption')->times(2);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
|
||||
$this->mockLdap->shouldReceive('setOption')->times(1);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(1)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
'cn' => [$this->mockUser->name],
|
||||
'dn' => ['dc=test' . config('services.ldap.base_dn')]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(3)->andReturn(true, true, false);
|
||||
$this->mockEscapes(2);
|
||||
$this->mockLdap->shouldReceive('bind')->times(2)->andReturn(true, false);
|
||||
$this->mockEscapes(1);
|
||||
|
||||
$this->mockUserLogin()
|
||||
->seePageIs('/login')->see('These credentials do not match our records.')
|
||||
@ -201,10 +206,10 @@ class LdapTest extends BrowserKitTest
|
||||
'services.ldap.group_attribute' => 'memberOf',
|
||||
'services.ldap.remove_from_groups' => false,
|
||||
]);
|
||||
$this->mockLdap->shouldReceive('connect')->times(2)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(2);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(5);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(5)
|
||||
$this->mockLdap->shouldReceive('connect')->times(1)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(1);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(4);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
@ -217,8 +222,8 @@ class LdapTest extends BrowserKitTest
|
||||
1 => "cn=ldaptester-second,ou=groups,dc=example,dc=com",
|
||||
]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(6)->andReturn(true);
|
||||
$this->mockEscapes(5);
|
||||
$this->mockLdap->shouldReceive('bind')->times(5)->andReturn(true);
|
||||
$this->mockEscapes(4);
|
||||
$this->mockExplodes(6);
|
||||
|
||||
$this->mockUserLogin()->seePageIs('/');
|
||||
@ -250,10 +255,10 @@ class LdapTest extends BrowserKitTest
|
||||
'services.ldap.group_attribute' => 'memberOf',
|
||||
'services.ldap.remove_from_groups' => true,
|
||||
]);
|
||||
$this->mockLdap->shouldReceive('connect')->times(2)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(2);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(4);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
|
||||
$this->mockLdap->shouldReceive('connect')->times(1)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(1);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(3);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(3)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
@ -265,8 +270,8 @@ class LdapTest extends BrowserKitTest
|
||||
0 => "cn=ldaptester,ou=groups,dc=example,dc=com",
|
||||
]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(5)->andReturn(true);
|
||||
$this->mockEscapes(4);
|
||||
$this->mockLdap->shouldReceive('bind')->times(4)->andReturn(true);
|
||||
$this->mockEscapes(3);
|
||||
$this->mockExplodes(2);
|
||||
|
||||
$this->mockUserLogin()->seePageIs('/');
|
||||
@ -299,10 +304,10 @@ class LdapTest extends BrowserKitTest
|
||||
'services.ldap.group_attribute' => 'memberOf',
|
||||
'services.ldap.remove_from_groups' => true,
|
||||
]);
|
||||
$this->mockLdap->shouldReceive('connect')->times(2)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(2);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(4);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
|
||||
$this->mockLdap->shouldReceive('connect')->times(1)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(1);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(3);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(3)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
@ -314,8 +319,8 @@ class LdapTest extends BrowserKitTest
|
||||
0 => "cn=ex-auth-a,ou=groups,dc=example,dc=com",
|
||||
]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(5)->andReturn(true);
|
||||
$this->mockEscapes(4);
|
||||
$this->mockLdap->shouldReceive('bind')->times(4)->andReturn(true);
|
||||
$this->mockEscapes(3);
|
||||
$this->mockExplodes(2);
|
||||
|
||||
$this->mockUserLogin()->seePageIs('/');
|
||||
@ -344,10 +349,10 @@ class LdapTest extends BrowserKitTest
|
||||
'services.ldap.group_attribute' => 'memberOf',
|
||||
'services.ldap.remove_from_groups' => true,
|
||||
]);
|
||||
$this->mockLdap->shouldReceive('connect')->times(2)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(2);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(5);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(5)
|
||||
$this->mockLdap->shouldReceive('connect')->times(1)->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->times(1);
|
||||
$this->mockLdap->shouldReceive('setOption')->times(4);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
@ -360,8 +365,8 @@ class LdapTest extends BrowserKitTest
|
||||
1 => "cn=ldaptester-second,ou=groups,dc=example,dc=com",
|
||||
]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(6)->andReturn(true);
|
||||
$this->mockEscapes(5);
|
||||
$this->mockLdap->shouldReceive('bind')->times(5)->andReturn(true);
|
||||
$this->mockEscapes(4);
|
||||
$this->mockExplodes(6);
|
||||
|
||||
$this->mockUserLogin()->seePageIs('/');
|
||||
@ -385,8 +390,8 @@ class LdapTest extends BrowserKitTest
|
||||
|
||||
$this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->once();
|
||||
$this->mockLdap->shouldReceive('setOption')->times(4);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
|
||||
$this->mockLdap->shouldReceive('setOption')->times(2);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
@ -394,8 +399,8 @@ class LdapTest extends BrowserKitTest
|
||||
'dn' => ['dc=test' . config('services.ldap.base_dn')],
|
||||
'displayname' => 'displayNameAttribute'
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(6)->andReturn(true);
|
||||
$this->mockEscapes(4);
|
||||
$this->mockLdap->shouldReceive('bind')->times(4)->andReturn(true);
|
||||
$this->mockEscapes(2);
|
||||
|
||||
$this->mockUserLogin()
|
||||
->seePageIs('/login')->see('Please enter an email to use for this account.');
|
||||
@ -415,16 +420,16 @@ class LdapTest extends BrowserKitTest
|
||||
|
||||
$this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
|
||||
$this->mockLdap->shouldReceive('setVersion')->once();
|
||||
$this->mockLdap->shouldReceive('setOption')->times(4);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(4)
|
||||
$this->mockLdap->shouldReceive('setOption')->times(2);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)
|
||||
->with($this->resourceId, config('services.ldap.base_dn'), \Mockery::type('string'), \Mockery::type('array'))
|
||||
->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
'cn' => [$this->mockUser->name],
|
||||
'dn' => ['dc=test' . config('services.ldap.base_dn')]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(6)->andReturn(true);
|
||||
$this->mockEscapes(4);
|
||||
$this->mockLdap->shouldReceive('bind')->times(4)->andReturn(true);
|
||||
$this->mockEscapes(2);
|
||||
|
||||
$this->mockUserLogin()
|
||||
->seePageIs('/login')->see('Please enter an email to use for this account.');
|
||||
@ -444,14 +449,14 @@ class LdapTest extends BrowserKitTest
|
||||
|
||||
// Standard mocks
|
||||
$this->mockLdap->shouldReceive('setVersion')->once();
|
||||
$this->mockLdap->shouldReceive('setOption')->times(2);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(2)->andReturn(['count' => 1, 0 => [
|
||||
$this->mockLdap->shouldReceive('setOption')->times(1);
|
||||
$this->mockLdap->shouldReceive('searchAndGetEntries')->times(1)->andReturn(['count' => 1, 0 => [
|
||||
'uid' => [$this->mockUser->name],
|
||||
'cn' => [$this->mockUser->name],
|
||||
'dn' => ['dc=test' . config('services.ldap.base_dn')]
|
||||
]]);
|
||||
$this->mockLdap->shouldReceive('bind')->times(3)->andReturn(true);
|
||||
$this->mockEscapes(2);
|
||||
$this->mockLdap->shouldReceive('bind')->times(2)->andReturn(true);
|
||||
$this->mockEscapes(1);
|
||||
|
||||
$this->mockLdap->shouldReceive('connect')->once()
|
||||
->with($expectedHost, $expectedPort)->andReturn($this->resourceId);
|
||||
|
Reference in New Issue
Block a user