summaryrefslogtreecommitdiffstats
path: root/tests/lib/User
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2016-06-27 11:30:13 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2016-06-27 14:08:11 +0200
commit2a990a0db5199ac842b50b580300bbeb2d2e794c (patch)
treead76ae23635def5b724005ae6b13b25d6b3d4def /tests/lib/User
parentd4989c80379d4cac71ae76ec8df79090f2e4c25f (diff)
downloadnextcloud-server-2a990a0db5199ac842b50b580300bbeb2d2e794c.tar.gz
nextcloud-server-2a990a0db5199ac842b50b580300bbeb2d2e794c.zip
verify user password on change
Diffstat (limited to 'tests/lib/User')
-rw-r--r--tests/lib/User/DatabaseTest.php47
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/lib/User/DatabaseTest.php b/tests/lib/User/DatabaseTest.php
index 270d90b35bc..16275f3b6c5 100644
--- a/tests/lib/User/DatabaseTest.php
+++ b/tests/lib/User/DatabaseTest.php
@@ -21,6 +21,9 @@
*/
namespace Test\User;
+use OC\HintException;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class DatabaseTest
@@ -30,6 +33,8 @@ namespace Test\User;
class DatabaseTest extends Backend {
/** @var array */
private $users;
+ /** @var EventDispatcher | \PHPUnit_Framework_MockObject_MockObject */
+ private $eventDispatcher;
public function getUser() {
$user = parent::getUser();
@@ -39,7 +44,10 @@ class DatabaseTest extends Backend {
protected function setUp() {
parent::setUp();
- $this->backend=new \OC\User\Database();
+
+ $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher');
+
+ $this->backend=new \OC\User\Database($this->eventDispatcher);
}
protected function tearDown() {
@@ -51,4 +59,41 @@ class DatabaseTest extends Backend {
}
parent::tearDown();
}
+
+ public function testVerifyPasswordEvent() {
+ $user = $this->getUser();
+ $this->backend->createUser($user, 'pass1');
+
+ $this->eventDispatcher->expects($this->once())->method('dispatch')
+ ->willReturnCallback(
+ function ($eventName, GenericEvent $event) {
+ $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
+ $this->assertSame('newpass', $event->getSubject());
+ }
+ );
+
+ $this->backend->setPassword($user, 'newpass');
+ $this->assertSame($user, $this->backend->checkPassword($user, 'newpass'));
+ }
+
+ /**
+ * @expectedException \OC\HintException
+ * @expectedExceptionMessage password change failed
+ */
+ public function testVerifyPasswordEventFail() {
+ $user = $this->getUser();
+ $this->backend->createUser($user, 'pass1');
+
+ $this->eventDispatcher->expects($this->once())->method('dispatch')
+ ->willReturnCallback(
+ function ($eventName, GenericEvent $event) {
+ $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
+ $this->assertSame('newpass', $event->getSubject());
+ throw new HintException('password change failed', 'password change failed');
+ }
+ );
+
+ $this->backend->setPassword($user, 'newpass');
+ $this->assertSame($user, $this->backend->checkPassword($user, 'newpass'));
+ }
}