diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-11-19 19:18:00 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-11-27 09:56:12 +0100 |
commit | 1a886b1472cad1fb04e8073d2749514e2d97a506 (patch) | |
tree | a66f332dcf0b2a9123f40b36dc0532103b8e9461 /tests | |
parent | a2046db6d011bef399f7952b2daf18734d6290ad (diff) | |
download | nextcloud-server-1a886b1472cad1fb04e8073d2749514e2d97a506.tar.gz nextcloud-server-1a886b1472cad1fb04e8073d2749514e2d97a506.zip |
Add typed events for password_policy
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 55 | ||||
-rw-r--r-- | tests/lib/User/DatabaseTest.php | 32 |
2 files changed, 49 insertions, 38 deletions
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 26008c2a3de..3e34a64acf3 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -27,6 +27,7 @@ use OC\Share20\DefaultShareProvider; use OC\Share20\Exception; use OC\Share20\Manager; use OC\Share20\Share; +use OCP\EventDispatcher\Event; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; @@ -42,16 +43,18 @@ use OCP\ILogger; use OCP\IServerContainer; use OCP\IURLGenerator; use OCP\IUser; - use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Mail\IMailer; +use OCP\Security\Events\ValidatePasswordPolicyEvent; use OCP\Security\IHasher; use OCP\Security\ISecureRandom; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IProviderFactory; use OCP\Share\IShare; use OCP\Share\IShareProvider; +use PHPUnit\Framework\MockObject\MockBuilder; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -65,37 +68,37 @@ class ManagerTest extends \Test\TestCase { /** @var Manager */ protected $manager; - /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ILogger|MockObject */ protected $logger; - /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */ + /** @var ISecureRandom|MockObject */ protected $secureRandom; - /** @var IHasher|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IHasher|MockObject */ protected $hasher; - /** @var IShareProvider|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IShareProvider|MockObject */ protected $defaultProvider; - /** @var IMountManager|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IMountManager|MockObject */ protected $mountManager; - /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IGroupManager|MockObject */ protected $groupManager; - /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IL10N|MockObject */ protected $l; - /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IFactory|MockObject */ protected $l10nFactory; /** @var DummyFactory */ protected $factory; - /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IUserManager|MockObject */ protected $userManager; - /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ + /** @var IRootFolder | MockObject */ protected $rootFolder; - /** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */ + /** @var EventDispatcherInterface | MockObject */ protected $eventDispatcher; - /** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IMailer|MockObject */ protected $mailer; - /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IURLGenerator|MockObject */ protected $urlGenerator; - /** @var \OC_Defaults|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \OC_Defaults|MockObject */ protected $defaults; public function setUp() { @@ -146,7 +149,7 @@ class ManagerTest extends \Test\TestCase { } /** - * @return \PHPUnit_Framework_MockObject_MockBuilder + * @return MockBuilder */ private function createManagerMock() { return $this->getMockBuilder('\OC\Share20\Manager') @@ -496,11 +499,12 @@ class ManagerTest extends \Test\TestCase { ])); $this->eventDispatcher->expects($this->once())->method('dispatch') - ->willReturnCallback(function($eventName, GenericEvent $event) { - $this->assertSame('OCP\PasswordPolicy::validate', $eventName); - $this->assertSame('password', $event->getSubject()); + ->willReturnCallback(function(Event $event) { + $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); + /** @var ValidatePasswordPolicyEvent $event */ + $this->assertSame('password', $event->getPassword()); } - ); + ); $result = self::invokePrivate($this->manager, 'verifyPassword', ['password']); $this->assertNull($result); @@ -516,12 +520,13 @@ class ManagerTest extends \Test\TestCase { ])); $this->eventDispatcher->expects($this->once())->method('dispatch') - ->willReturnCallback(function($eventName, GenericEvent $event) { - $this->assertSame('OCP\PasswordPolicy::validate', $eventName); - $this->assertSame('password', $event->getSubject()); + ->willReturnCallback(function(Event $event) { + $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); + /** @var ValidatePasswordPolicyEvent $event */ + $this->assertSame('password', $event->getPassword()); throw new HintException('message', 'password not accepted'); } - ); + ); self::invokePrivate($this->manager, 'verifyPassword', ['password']); } diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php index feba7a6926d..8e52be50c75 100644 --- a/tests/lib/User/DatabaseTest.php +++ b/tests/lib/User/DatabaseTest.php @@ -21,10 +21,14 @@ */ namespace Test\User; + use OC\HintException; use OC\User\User; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Security\Events\ValidatePasswordPolicyEvent; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; /** * Class DatabaseTest @@ -34,7 +38,7 @@ use Symfony\Component\EventDispatcher\GenericEvent; class DatabaseTest extends Backend { /** @var array */ private $users; - /** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** @var IEventDispatcher|MockObject */ private $eventDispatcher; public function getUser() { @@ -46,7 +50,7 @@ class DatabaseTest extends Backend { protected function setUp() { parent::setUp(); - $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->backend=new \OC\User\Database($this->eventDispatcher); } @@ -65,11 +69,12 @@ class DatabaseTest extends Backend { $user = $this->getUser(); $this->backend->createUser($user, 'pass1'); - $this->eventDispatcher->expects($this->once())->method('dispatch') + $this->eventDispatcher->expects($this->once())->method('dispatchTyped') ->willReturnCallback( - function ($eventName, GenericEvent $event) { - $this->assertSame('OCP\PasswordPolicy::validate', $eventName); - $this->assertSame('newpass', $event->getSubject()); + function (Event $event) { + $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); + /** @var ValidatePasswordPolicyEvent $event */ + $this->assertSame('newpass', $event->getPassword()); } ); @@ -85,11 +90,12 @@ class DatabaseTest extends Backend { $user = $this->getUser(); $this->backend->createUser($user, 'pass1'); - $this->eventDispatcher->expects($this->once())->method('dispatch') + $this->eventDispatcher->expects($this->once())->method('dispatchTyped') ->willReturnCallback( - function ($eventName, GenericEvent $event) { - $this->assertSame('OCP\PasswordPolicy::validate', $eventName); - $this->assertSame('newpass', $event->getSubject()); + function (Event $event) { + $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event); + /** @var ValidatePasswordPolicyEvent $event */ + $this->assertSame('newpass', $event->getPassword()); throw new HintException('password change failed', 'password change failed'); } ); @@ -124,8 +130,8 @@ class DatabaseTest extends Backend { $user2 = $this->getUser(); $this->backend->createUser($user2, 'pass1'); - $user1Obj = new User($user1, $this->backend, $this->eventDispatcher); - $user2Obj = new User($user2, $this->backend, $this->eventDispatcher); + $user1Obj = new User($user1, $this->backend, $this->createMock(EventDispatcherInterface::class)); + $user2Obj = new User($user2, $this->backend, $this->createMock(EventDispatcherInterface::class)); $emailAddr1 = "$user1@nextcloud.com"; $emailAddr2 = "$user2@nextcloud.com"; |