diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-03-18 17:40:23 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2020-04-14 12:58:28 +0200 |
commit | 84619a5b9c58ec7f4e3d7faea8c60a187cb61243 (patch) | |
tree | 2572e5f939f8c6bd76b4611c432aad3721b0b62e /apps/user_ldap/tests | |
parent | e4d378d01e67c41fa64a12662128ba25a0b27133 (diff) | |
download | nextcloud-server-84619a5b9c58ec7f4e3d7faea8c60a187cb61243.tar.gz nextcloud-server-84619a5b9c58ec7f4e3d7faea8c60a187cb61243.zip |
use serverControls directly with LDAP calls, fixes 19127
- adapters for PHP API version to Support PHP < 7.3
- switch to pass only one base per search
- cookie logic is moved from Access to API adapters
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/user_ldap/tests')
-rw-r--r-- | apps/user_ldap/tests/AccessTest.php | 34 | ||||
-rw-r--r-- | apps/user_ldap/tests/LDAPTest.php | 3 | ||||
-rw-r--r-- | apps/user_ldap/tests/User/UserTest.php | 8 |
3 files changed, 23 insertions, 22 deletions
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index 73fd35b8960..5aec76eb385 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -442,7 +442,7 @@ class AccessTest extends TestCase { $this->assertSame($values[0], strtolower($dnFromServer)); } - + public function testSetPasswordWithDisabledChanges() { $this->expectException(\Exception::class); $this->expectExceptionMessage('LDAP password changes are disabled'); @@ -474,7 +474,7 @@ class AccessTest extends TestCase { $this->assertFalse($this->access->setPassword('CN=foo', 'MyPassword')); } - + public function testSetPasswordWithRejectedChange() { $this->expectException(\OC\HintException::class); $this->expectExceptionMessage('Password change rejected.'); @@ -540,7 +540,7 @@ class AccessTest extends TestCase { ->method('__get') ->willReturnCallback(function ($key) use ($base) { if (stripos($key, 'base') !== false) { - return $base; + return [$base]; } return null; }); @@ -548,8 +548,8 @@ class AccessTest extends TestCase { $this->ldap ->expects($this->any()) ->method('isResource') - ->willReturnCallback(function ($resource) use ($fakeConnection) { - return $resource === $fakeConnection; + ->willReturnCallback(function ($resource) { + return is_resource($resource); }); $this->ldap ->expects($this->any()) @@ -558,9 +558,9 @@ class AccessTest extends TestCase { $this->ldap ->expects($this->once()) ->method('search') - ->willReturn([$fakeSearchResultResource]); + ->willReturn($fakeSearchResultResource); $this->ldap - ->expects($this->exactly(count($base))) + ->expects($this->exactly(1)) ->method('getEntries') ->willReturn($fakeLdapEntries); @@ -572,17 +572,17 @@ class AccessTest extends TestCase { public function testSearchNoPagedSearch() { // scenario: no pages search, 1 search base $filter = 'objectClass=nextcloudUser'; - $base = ['ou=zombies,dc=foobar,dc=nextcloud,dc=com']; + $base = 'ou=zombies,dc=foobar,dc=nextcloud,dc=com'; - $fakeConnection = new \stdClass(); - $fakeSearchResultResource = new \stdClass(); + $fakeConnection = ldap_connect(); + $fakeSearchResultResource = ldap_connect(); $fakeLdapEntries = [ 'count' => 2, [ - 'dn' => 'uid=sgarth,' . $base[0], + 'dn' => 'uid=sgarth,' . $base, ], [ - 'dn' => 'uid=wwilson,' . $base[0], + 'dn' => 'uid=wwilson,' . $base, ] ]; @@ -598,19 +598,19 @@ class AccessTest extends TestCase { public function testFetchListOfUsers() { $filter = 'objectClass=nextcloudUser'; - $base = ['ou=zombies,dc=foobar,dc=nextcloud,dc=com']; + $base = 'ou=zombies,dc=foobar,dc=nextcloud,dc=com'; $attrs = ['dn', 'uid']; - $fakeConnection = new \stdClass(); - $fakeSearchResultResource = new \stdClass(); + $fakeConnection = ldap_connect(); + $fakeSearchResultResource = ldap_connect(); $fakeLdapEntries = [ 'count' => 2, [ - 'dn' => 'uid=sgarth,' . $base[0], + 'dn' => 'uid=sgarth,' . $base, 'uid' => [ 'sgarth' ], ], [ - 'dn' => 'uid=wwilson,' . $base[0], + 'dn' => 'uid=wwilson,' . $base, 'uid' => [ 'wwilson' ], ] ]; diff --git a/apps/user_ldap/tests/LDAPTest.php b/apps/user_ldap/tests/LDAPTest.php index 5df6b118487..de2d7c0d3a7 100644 --- a/apps/user_ldap/tests/LDAPTest.php +++ b/apps/user_ldap/tests/LDAPTest.php @@ -73,7 +73,8 @@ class LDAPTest extends TestCase { trigger_error($errorMessage); }); - $this->ldap->search('pseudo-resource', 'base', 'filter', []); + $fakeResource = ldap_connect(); + $this->ldap->search($fakeResource, 'base', 'filter', []); $this->assertSame($wasErrorHandlerCalled, $passThrough); restore_error_handler(); diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php index 8de71b182ba..afefaf04c78 100644 --- a/apps/user_ldap/tests/User/UserTest.php +++ b/apps/user_ldap/tests/User/UserTest.php @@ -1197,7 +1197,7 @@ class UserTest extends \Test\TestCase { $this->access->expects($this->any()) ->method('search') ->willReturnCallback(function ($filter, $base) { - if ($base === [$this->dn]) { + if($base === $this->dn) { return [ [ 'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'], @@ -1205,7 +1205,7 @@ class UserTest extends \Test\TestCase { ], ]; } - if ($base === ['cn=default,ou=policies,dc=foo,dc=bar']) { + if($base === 'cn=default,ou=policies,dc=foo,dc=bar') { return [ [ 'pwdmaxage' => ['2592000'], @@ -1260,7 +1260,7 @@ class UserTest extends \Test\TestCase { $this->access->expects($this->any()) ->method('search') ->willReturnCallback(function ($filter, $base) { - if ($base === [$this->dn]) { + if($base === $this->dn) { return [ [ 'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'], @@ -1269,7 +1269,7 @@ class UserTest extends \Test\TestCase { ] ]; } - if ($base === ['cn=custom,ou=policies,dc=foo,dc=bar']) { + if ($base === 'cn=custom,ou=policies,dc=foo,dc=bar') { return [ [ 'pwdmaxage' => ['2592000'], |