diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-01-04 09:53:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-04 09:53:10 +0100 |
commit | fe3d8ffc9003f4f8af0e15593508c7058be24473 (patch) | |
tree | f52804ae666b2a6cd83fe001f07cf3f743368595 /tests | |
parent | 2d22633568ce2cc6e3246a61d265852b793642c8 (diff) | |
parent | 4b3308bf3fd4c6fe572ee1658a7809bba20c7339 (diff) | |
download | nextcloud-server-fe3d8ffc9003f4f8af0e15593508c7058be24473.tar.gz nextcloud-server-fe3d8ffc9003f4f8af0e15593508c7058be24473.zip |
Merge pull request #13172 from nextcloud/fix-can-change-password-check
fix can change password check in case of encryption is enabled
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings/Controller/UsersControllerTest.php | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php index 74ac990be92..8294514fa50 100644 --- a/tests/Settings/Controller/UsersControllerTest.php +++ b/tests/Settings/Controller/UsersControllerTest.php @@ -11,6 +11,7 @@ namespace Tests\Settings\Controller; use OC\Accounts\AccountManager; +use OC\Encryption\Exceptions\ModuleDoesNotExistsException; use OC\Group\Group; use OC\Group\Manager; use OC\Settings\Controller\UsersController; @@ -98,7 +99,7 @@ class UsersControllerTest extends \Test\TestCase { $this->securityManager = $this->getMockBuilder(\OC\Security\IdentityProof\Manager::class)->disableOriginalConstructor()->getMock(); $this->jobList = $this->createMock(IJobList::class); $this->encryptionManager = $this->createMock(IManager::class); - + $this->l->method('t') ->will($this->returnCallback(function ($text, $parameters = []) { return vsprintf($text, $parameters); @@ -513,4 +514,49 @@ class UsersControllerTest extends \Test\TestCase { $this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus()); } + /** + * @dataProvider dataTestCanAdminChangeUserPasswords + * + * @param bool $encryptionEnabled + * @param bool $encryptionModuleLoaded + * @param bool $masterKeyEnabled + * @param bool $expected + */ + public function testCanAdminChangeUserPasswords($encryptionEnabled, + $encryptionModuleLoaded, + $masterKeyEnabled, + $expected) { + $controller = $this->getController(); + + $this->encryptionManager->expects($this->any()) + ->method('isEnabled') + ->willReturn($encryptionEnabled); + $this->encryptionManager->expects($this->any()) + ->method('getEncryptionModule') + ->willReturnCallback(function() use ($encryptionModuleLoaded) { + if ($encryptionModuleLoaded) return $this->encryptionModule; + else throw new ModuleDoesNotExistsException(); + }); + $this->encryptionModule->expects($this->any()) + ->method('needDetailedAccessList') + ->willReturn(!$masterKeyEnabled); + + $result = $this->invokePrivate($controller, 'canAdminChangeUserPasswords', []); + $this->assertSame($expected, $result); + } + + public function dataTestCanAdminChangeUserPasswords() { + return [ + // encryptionEnabled, encryptionModuleLoaded, masterKeyEnabled, expectedResult + [true, true, true, true], + [false, true, true, true], + [true, false, true, false], + [false, false, true, true], + [true, true, false, false], + [false, true, false, false], + [true, false, false, false], + [false, false, false, true], + ]; + } + } |