summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-09 17:28:31 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-09 17:28:31 -0500
commit26e3996014936268f4acbfa214fa881af9320ddd (patch)
tree5f7fa2c1b73e4443ce75e8919383bdf775492304 /tests/units
parent03032c3190a27408d60e27f486a4ca472448e9dc (diff)
Add forgot password feature
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Model/PasswordResetTest.php85
-rw-r--r--tests/units/Validator/PasswordResetValidatorTest.php64
2 files changed, 149 insertions, 0 deletions
diff --git a/tests/units/Model/PasswordResetTest.php b/tests/units/Model/PasswordResetTest.php
new file mode 100644
index 00000000..f88d24fb
--- /dev/null
+++ b/tests/units/Model/PasswordResetTest.php
@@ -0,0 +1,85 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\User;
+use Kanboard\Model\PasswordReset;
+
+class PasswordResetTest extends Base
+{
+ public function testCreate()
+ {
+ $userModel = new User($this->container);
+ $passwordResetModel = new PasswordReset($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
+
+ $this->assertFalse($passwordResetModel->create('user0'));
+ $this->assertFalse($passwordResetModel->create('user1'));
+ $this->assertNotFalse($passwordResetModel->create('user2'));
+ }
+
+ public function testGetUserIdByToken()
+ {
+ $userModel = new User($this->container);
+ $passwordResetModel = new PasswordReset($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
+
+ $token = $passwordResetModel->create('user2');
+ $this->assertEquals(2, $passwordResetModel->getUserIdByToken($token));
+ }
+
+ public function testGetUserIdByTokenWhenExpired()
+ {
+ $userModel = new User($this->container);
+ $passwordResetModel = new PasswordReset($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
+
+ $token = $passwordResetModel->create('user2', strtotime('-1 year'));
+ $this->assertFalse($passwordResetModel->getUserIdByToken($token));
+ }
+
+ public function testDisableTokens()
+ {
+ $userModel = new User($this->container);
+ $passwordResetModel = new PasswordReset($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
+
+ $token1 = $passwordResetModel->create('user2');
+ $token2 = $passwordResetModel->create('user2');
+
+ $this->assertEquals(2, $passwordResetModel->getUserIdByToken($token1));
+ $this->assertEquals(2, $passwordResetModel->getUserIdByToken($token2));
+
+ $this->assertTrue($passwordResetModel->disable(2));
+
+ $this->assertFalse($passwordResetModel->getUserIdByToken($token1));
+ $this->assertFalse($passwordResetModel->getUserIdByToken($token2));
+ }
+
+ public function testGetAll()
+ {
+ $userModel = new User($this->container);
+ $passwordResetModel = new PasswordReset($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
+ $this->assertNotFalse($passwordResetModel->create('user2'));
+ $this->assertNotFalse($passwordResetModel->create('user2'));
+
+ $tokens = $passwordResetModel->getAll(1);
+ $this->assertCount(0, $tokens);
+
+ $tokens = $passwordResetModel->getAll(2);
+ $this->assertCount(2, $tokens);
+ $this->assertNotEmpty($tokens[0]['token']);
+ $this->assertNotEmpty($tokens[0]['date_creation']);
+ $this->assertNotEmpty($tokens[0]['date_expiration']);
+ $this->assertEquals(2, $tokens[0]['user_id']);
+ $this->assertArrayHasKey('user_agent', $tokens[0]);
+ $this->assertArrayHasKey('ip', $tokens[0]);
+ }
+}
diff --git a/tests/units/Validator/PasswordResetValidatorTest.php b/tests/units/Validator/PasswordResetValidatorTest.php
new file mode 100644
index 00000000..4af6c75e
--- /dev/null
+++ b/tests/units/Validator/PasswordResetValidatorTest.php
@@ -0,0 +1,64 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\User;
+use Kanboard\Validator\PasswordResetValidator;
+
+class PasswordResetValidatorTest extends Base
+{
+ public function testValidateModification()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test123'));
+ $this->assertTrue($valid);
+ }
+
+ public function testValidateModificationWithWrongPasswords()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test456'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateModificationWithPasswordTooShort()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid, ) = $validator->validateModification(array('password' => 'test', 'confirmation' => 'test'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateCreation()
+ {
+ $this->container['sessionStorage']->captcha = 'test';
+
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $this->assertTrue($valid);
+ }
+
+ public function testValidateCreationWithNoUsername()
+ {
+ $this->container['sessionStorage']->captcha = 'test';
+
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('captcha' => 'test'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateCreationWithWrongCaptcha()
+ {
+ $this->container['sessionStorage']->captcha = 'test123';
+
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $this->assertFalse($valid);
+ }
+
+ public function testValidateCreationWithMissingCaptcha()
+ {
+ $validator = new PasswordResetValidator($this->container);
+ list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
+ $this->assertFalse($valid);
+ }
+}