diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-06-30 15:06:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-30 15:06:40 +0200 |
commit | 29929c97285adca090ee927cb3fd5ef8b52e451b (patch) | |
tree | 952aad8612cd6f3945778316d02df7d7d4ae07b0 /tests/lib/share20/managertest.php | |
parent | 723cf78169e7dc7138dedf70fa694b202060d8f5 (diff) | |
parent | 27059107f869c6a5758569c1e24f34f8543b245e (diff) | |
download | nextcloud-server-29929c97285adca090ee927cb3fd5ef8b52e451b.tar.gz nextcloud-server-29929c97285adca090ee927cb3fd5ef8b52e451b.zip |
Merge pull request #240 from nextcloud/password_policy_events_stable9
[stable9] add events to check passwords with the password policy app
Diffstat (limited to 'tests/lib/share20/managertest.php')
-rw-r--r-- | tests/lib/share20/managertest.php | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php index 8ebe3d4b55f..ece4ae23847 100644 --- a/tests/lib/share20/managertest.php +++ b/tests/lib/share20/managertest.php @@ -20,6 +20,7 @@ */ namespace Test\Share20; +use OC\HintException; use OCP\Files\IRootFolder; use OCP\IUserManager; use OCP\Share\Exceptions\ShareNotFound; @@ -37,6 +38,8 @@ use OCP\Security\ISecureRandom; use OCP\Security\IHasher; use OCP\Files\Mount\IMountManager; use OCP\IGroupManager; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\GenericEvent; /** * Class ManagerTest @@ -70,9 +73,11 @@ class ManagerTest extends \Test\TestCase { protected $userManager; /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ protected $rootFolder; + /** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */ + protected $eventDispatcher; public function setUp() { - + $this->logger = $this->getMock('\OCP\ILogger'); $this->config = $this->getMock('\OCP\IConfig'); $this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom'); @@ -81,6 +86,7 @@ class ManagerTest extends \Test\TestCase { $this->groupManager = $this->getMock('\OCP\IGroupManager'); $this->userManager = $this->getMock('\OCP\IUserManager'); $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder'); + $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher'); $this->l = $this->getMock('\OCP\IL10N'); $this->l->method('t') @@ -100,7 +106,8 @@ class ManagerTest extends \Test\TestCase { $this->l, $this->factory, $this->userManager, - $this->rootFolder + $this->rootFolder, + $this->eventDispatcher ); $this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider') @@ -127,7 +134,8 @@ class ManagerTest extends \Test\TestCase { $this->l, $this->factory, $this->userManager, - $this->rootFolder + $this->rootFolder, + $this->eventDispatcher ]); } @@ -146,7 +154,7 @@ class ManagerTest extends \Test\TestCase { $group = $this->getMock('\OCP\IGroup'); $group->method('getGID')->willReturn('sharedWithGroup'); - + return [ [\OCP\Share::SHARE_TYPE_USER, 'sharedWithUser'], [\OCP\Share::SHARE_TYPE_GROUP, 'sharedWithGroup'], @@ -543,17 +551,13 @@ class ManagerTest extends \Test\TestCase { ['core', 'shareapi_enforce_links_password', 'no', 'no'], ])); - $hookListner = $this->getMockBuilder('Dummy')->setMethods(['listner'])->getMock(); - \OCP\Util::connectHook('\OC\Share', 'verifyPassword', $hookListner, 'listner'); - - $hookListner->expects($this->once()) - ->method('listner') - ->with([ - 'password' => 'password', - 'accepted' => true, - 'message' => '' - ]); - + $this->eventDispatcher->expects($this->once())->method('dispatch') + ->willReturnCallback( + function($eventName, GenericEvent $event) { + $this->assertSame('OCP\PasswordPolicy::validate', $eventName); + $this->assertSame('password', $event->getSubject()); + } + ); $result = $this->invokePrivate($this->manager, 'verifyPassword', ['password']); $this->assertNull($result); } @@ -567,8 +571,15 @@ class ManagerTest extends \Test\TestCase { ['core', 'shareapi_enforce_links_password', 'no', 'no'], ])); - $dummy = new DummyPassword(); - \OCP\Util::connectHook('\OC\Share', 'verifyPassword', $dummy, 'listner'); + $this->eventDispatcher->expects($this->once())->method('dispatch') + ->willReturnCallback( + function($eventName, GenericEvent $event) { + $this->assertSame('OCP\PasswordPolicy::validate', $eventName); + $this->assertSame('password', $event->getSubject()); + throw new HintException('message', 'password not accepted'); + } + ); + $this->invokePrivate($this->manager, 'verifyPassword', ['password']); } @@ -2022,7 +2033,8 @@ class ManagerTest extends \Test\TestCase { $this->l, $factory, $this->userManager, - $this->rootFolder + $this->rootFolder, + $this->eventDispatcher ); $share = $this->getMock('\OCP\Share\IShare'); @@ -2465,13 +2477,6 @@ class ManagerTest extends \Test\TestCase { } } -class DummyPassword { - public function listner($array) { - $array['accepted'] = false; - $array['message'] = 'password not accepted'; - } -} - class DummyFactory implements IProviderFactory { /** @var IShareProvider */ @@ -2503,4 +2508,4 @@ class DummyFactory implements IProviderFactory { public function getProviderForType($shareType) { return $this->provider; } -}
\ No newline at end of file +} |