Restrict task complexity to a specific range to avoid integer overflow

This commit is contained in:
Frederic Guillot
2016-10-08 09:58:11 -04:00
parent 1466afb771
commit c2f1cc8f74
37 changed files with 179 additions and 132 deletions

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1277,4 +1277,5 @@ return array(
'Duplicate to multiple projects' => 'Dupliquer vers plusieurs projets', 'Duplicate to multiple projects' => 'Dupliquer vers plusieurs projets',
'This field is required' => 'Ce champ est requis', 'This field is required' => 'Ce champ est requis',
'Moving a task is not permitted' => 'Déplaçer une tâche n\'est pas autorisé', 'Moving a task is not permitted' => 'Déplaçer une tâche n\'est pas autorisé',
'This value must be in the range %d to %d' => 'Cette valeur doit être définie entre %d et %d',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
'Duplicate to multiple projects' => 'Duplicar para vários projetos', 'Duplicate to multiple projects' => 'Duplicar para vários projetos',
'This field is required' => 'Este campo é obrigatório', 'This field is required' => 'Este campo é obrigatório',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -1276,4 +1276,5 @@ return array(
// 'Duplicate to multiple projects' => '', // 'Duplicate to multiple projects' => '',
// 'This field is required' => '', // 'This field is required' => '',
// 'Moving a task is not permitted' => '', // 'Moving a task is not permitted' => '',
// 'This value must be in the range %d to %d' => '',
); );

View File

@@ -28,6 +28,7 @@ class TaskValidator extends BaseValidator
new Validators\Integer('owner_id', t('This value must be an integer')), new Validators\Integer('owner_id', t('This value must be an integer')),
new Validators\Integer('creator_id', t('This value must be an integer')), new Validators\Integer('creator_id', t('This value must be an integer')),
new Validators\Integer('score', t('This value must be an integer')), new Validators\Integer('score', t('This value must be an integer')),
new Validators\Range('score', t('This value must be in the range %d to %d', -2147483647, 2147483647), -2147483647, 2147483647),
new Validators\Integer('category_id', t('This value must be an integer')), new Validators\Integer('category_id', t('This value must be an integer')),
new Validators\Integer('swimlane_id', t('This value must be an integer')), new Validators\Integer('swimlane_id', t('This value must be an integer')),
new Validators\Integer('recurrence_child', t('This value must be an integer')), new Validators\Integer('recurrence_child', t('This value must be an integer')),
@@ -95,27 +96,6 @@ class TaskValidator extends BaseValidator
); );
} }
/**
* Validate description creation
*
* @access public
* @param array $values Form values
* @return array $valid, $errors [0] = Success or not, [1] = List of errors
*/
public function validateDescriptionCreation(array $values)
{
$rules = array(
new Validators\Required('id', t('The id is required')),
);
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
return array(
$v->execute(),
$v->getErrors()
);
}
/** /**
* Validate edit recurrence * Validate edit recurrence
* *

View File

@@ -8,50 +8,50 @@ class CommentValidatorTest extends Base
{ {
public function testValidateCreation() public function testValidateCreation()
{ {
$validator = new CommentValidator($this->container); $commentValidator = new CommentValidator($this->container);
$result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla')); $result = $commentValidator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]); $this->assertTrue($result[0]);
$result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => '')); $result = $commentValidator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => ''));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla')); $result = $commentValidator->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla')); $result = $commentValidator->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('user_id' => 1, 'comment' => 'bla')); $result = $commentValidator->validateCreation(array('user_id' => 1, 'comment' => 'bla'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('task_id' => 1, 'comment' => 'bla')); $result = $commentValidator->validateCreation(array('task_id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]); $this->assertTrue($result[0]);
$result = $validator->validateCreation(array('comment' => 'bla')); $result = $commentValidator->validateCreation(array('comment' => 'bla'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array()); $result = $commentValidator->validateCreation(array());
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
} }
public function testValidateModification() public function testValidateModification()
{ {
$validator = new CommentValidator($this->container); $commentValidator = new CommentValidator($this->container);
$result = $validator->validateModification(array('id' => 1, 'comment' => 'bla')); $result = $commentValidator->validateModification(array('id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]); $this->assertTrue($result[0]);
$result = $validator->validateModification(array('id' => 1, 'comment' => '')); $result = $commentValidator->validateModification(array('id' => 1, 'comment' => ''));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateModification(array('comment' => 'bla')); $result = $commentValidator->validateModification(array('comment' => 'bla'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateModification(array('id' => 'b', 'comment' => 'bla')); $result = $commentValidator->validateModification(array('id' => 'b', 'comment' => 'bla'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateModification(array()); $result = $commentValidator->validateModification(array());
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
} }
} }

View File

@@ -8,20 +8,20 @@ class CurrencyValidatorTest extends Base
{ {
public function testValidation() public function testValidation()
{ {
$validator = new CurrencyValidator($this->container); $currencyValidator = new CurrencyValidator($this->container);
$result = $validator->validateCreation(array()); $result = $currencyValidator->validateCreation(array());
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('currency' => 'EUR')); $result = $currencyValidator->validateCreation(array('currency' => 'EUR'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('rate' => 1.9)); $result = $currencyValidator->validateCreation(array('rate' => 1.9));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar')); $result = $currencyValidator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25)); $result = $currencyValidator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25));
$this->assertTrue($result[0]); $this->assertTrue($result[0]);
} }
} }

View File

@@ -8,16 +8,16 @@ class CustomFilterValidatorTest extends Base
{ {
public function testValidateCreation() public function testValidateCreation()
{ {
$validator = new CustomFilterValidator($this->container); $customFilterValidator = new CustomFilterValidator($this->container);
// Validate creation // Validate creation
$r = $validator->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); $r = $customFilterValidator->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); $r = $customFilterValidator->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); $r = $customFilterValidator->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
} }

View File

@@ -8,27 +8,27 @@ class ExternalLinkValidatorTest extends Base
{ {
public function testValidateCreation() public function testValidateCreation()
{ {
$validator = new ExternalLinkValidator($this->container); $externalLinkValidator = new ExternalLinkValidator($this->container);
$result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertTrue($result[0]); $this->assertTrue($result[0]);
$result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink')); $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related')); $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related')); $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); $result = $externalLinkValidator->validateCreation(array('url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validateCreation(array('task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); $result = $externalLinkValidator->validateCreation(array('task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
} }

View File

@@ -8,12 +8,12 @@ class GroupValidatorTest extends Base
{ {
public function testValidateCreation() public function testValidateCreation()
{ {
$validator = new GroupValidator($this->container); $groupValidator = new GroupValidator($this->container);
$result = $validator->validateCreation(array('name' => 'Test')); $result = $groupValidator->validateCreation(array('name' => 'Test'));
$this->assertTrue($result[0]); $this->assertTrue($result[0]);
$result = $validator->validateCreation(array('name' => '')); $result = $groupValidator->validateCreation(array('name' => ''));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
} }

View File

@@ -8,21 +8,21 @@ class LinkValidatorTest extends Base
{ {
public function testValidateCreation() public function testValidateCreation()
{ {
$validator = new LinkValidator($this->container); $linkValidator = new LinkValidator($this->container);
$r = $validator->validateCreation(array('label' => 'a')); $r = $linkValidator->validateCreation(array('label' => 'a'));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'b')); $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateCreation(array('label' => 'relates to')); $r = $linkValidator->validateCreation(array('label' => 'relates to'));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'a')); $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('label' => '')); $r = $linkValidator->validateCreation(array('label' => ''));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
} }

View File

@@ -8,22 +8,22 @@ class PasswordResetValidatorTest extends Base
{ {
public function testValidateModification() public function testValidateModification()
{ {
$validator = new PasswordResetValidator($this->container); $passwordResetValidator = new PasswordResetValidator($this->container);
list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test123')); list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test123', 'confirmation' => 'test123'));
$this->assertTrue($valid); $this->assertTrue($valid);
} }
public function testValidateModificationWithWrongPasswords() public function testValidateModificationWithWrongPasswords()
{ {
$validator = new PasswordResetValidator($this->container); $passwordResetValidator = new PasswordResetValidator($this->container);
list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test456')); list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test123', 'confirmation' => 'test456'));
$this->assertFalse($valid); $this->assertFalse($valid);
} }
public function testValidateModificationWithPasswordTooShort() public function testValidateModificationWithPasswordTooShort()
{ {
$validator = new PasswordResetValidator($this->container); $passwordResetValidator = new PasswordResetValidator($this->container);
list($valid, ) = $validator->validateModification(array('password' => 'test', 'confirmation' => 'test')); list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test', 'confirmation' => 'test'));
$this->assertFalse($valid); $this->assertFalse($valid);
} }
@@ -31,8 +31,8 @@ class PasswordResetValidatorTest extends Base
{ {
$this->container['sessionStorage']->captcha = 'test'; $this->container['sessionStorage']->captcha = 'test';
$validator = new PasswordResetValidator($this->container); $passwordResetValidator = new PasswordResetValidator($this->container);
list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertTrue($valid); $this->assertTrue($valid);
} }
@@ -40,8 +40,8 @@ class PasswordResetValidatorTest extends Base
{ {
$this->container['sessionStorage']->captcha = 'test'; $this->container['sessionStorage']->captcha = 'test';
$validator = new PasswordResetValidator($this->container); $passwordResetValidator = new PasswordResetValidator($this->container);
list($valid,) = $validator->validateCreation(array('captcha' => 'test')); list($valid,) = $passwordResetValidator->validateCreation(array('captcha' => 'test'));
$this->assertFalse($valid); $this->assertFalse($valid);
} }
@@ -49,15 +49,15 @@ class PasswordResetValidatorTest extends Base
{ {
$this->container['sessionStorage']->captcha = 'test123'; $this->container['sessionStorage']->captcha = 'test123';
$validator = new PasswordResetValidator($this->container); $passwordResetValidator = new PasswordResetValidator($this->container);
list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertFalse($valid); $this->assertFalse($valid);
} }
public function testValidateCreationWithMissingCaptcha() public function testValidateCreationWithMissingCaptcha()
{ {
$validator = new PasswordResetValidator($this->container); $passwordResetValidator = new PasswordResetValidator($this->container);
list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test'));
$this->assertFalse($valid); $this->assertFalse($valid);
} }
} }

View File

@@ -9,65 +9,65 @@ class ProjectValidatorTest extends Base
{ {
public function testValidateCreation() public function testValidateCreation()
{ {
$validator = new ProjectValidator($this->container); $projectValidator = new ProjectValidator($this->container);
$p = new ProjectModel($this->container); $projectModel = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
$project = $p->getById(1); $project = $projectModel->getById(1);
$this->assertNotEmpty($project); $this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']); $this->assertEquals('TEST1', $project['identifier']);
$project = $p->getById(2); $project = $projectModel->getById(2);
$this->assertNotEmpty($project); $this->assertNotEmpty($project);
$this->assertEquals('', $project['identifier']); $this->assertEquals('', $project['identifier']);
$r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test1')); $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c')); $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
} }
public function testValidateModification() public function testValidateModification()
{ {
$validator = new ProjectValidator($this->container); $projectValidator = new ProjectValidator($this->container);
$p = new ProjectModel($this->container); $projectModel = new ProjectModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
$this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2'))); $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2')));
$project = $p->getById(1); $project = $projectModel->getById(1);
$this->assertNotEmpty($project); $this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']); $this->assertEquals('TEST1', $project['identifier']);
$project = $p->getById(2); $project = $projectModel->getById(2);
$this->assertNotEmpty($project); $this->assertNotEmpty($project);
$this->assertEquals('TEST2', $project['identifier']); $this->assertEquals('TEST2', $project['identifier']);
$r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); $r = $projectValidator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3')); $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'test3'));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateModification(array('id' => 1, 'identifier' => '')); $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => ''));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2')); $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'TEST2'));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateModification(array('id' => 1, 'name' => '')); $r = $projectValidator->validateModification(array('id' => 1, 'name' => ''));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateModification(array('id' => 1, 'name' => null)); $r = $projectValidator->validateModification(array('id' => 1, 'name' => null));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
} }
} }

View File

@@ -11,62 +11,62 @@ class TaskLinkValidatorTest extends Base
{ {
public function testValidateCreation() public function testValidateCreation()
{ {
$validator = new TaskLinkValidator($this->container); $taskLinkValidator = new TaskLinkValidator($this->container);
$tl = new TaskLinkModel($this->container); $taskLinkModel = new TaskLinkModel($this->container);
$p = new ProjectModel($this->container); $projectModel = new ProjectModel($this->container);
$tc = new TaskCreationModel($this->container); $taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
$links = $tl->getAll(1); $links = $taskLinkModel->getAll(1);
$this->assertEmpty($links); $this->assertEmpty($links);
$links = $tl->getAll(2); $links = $taskLinkModel->getAll(2);
$this->assertEmpty($links); $this->assertEmpty($links);
// Check creation // Check creation
$r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1)); $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
} }
public function testValidateModification() public function testValidateModification()
{ {
$validator = new TaskLinkValidator($this->container); $taskLinkValidator = new TaskLinkValidator($this->container);
$p = new ProjectModel($this->container); $projectModel = new ProjectModel($this->container);
$tc = new TaskCreationModel($this->container); $taskCreationModel = new TaskCreationModel($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
// Check modification // Check modification
$r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
$this->assertTrue($r[0]); $this->assertTrue($r[0]);
$r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1)); $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
$r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); $r = $taskLinkValidator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
$this->assertFalse($r[0]); $this->assertFalse($r[0]);
} }
} }

View File

@@ -0,0 +1,42 @@
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Validator\TaskValidator;
class TaskValidatorTest extends Base
{
public function testRequiredFields()
{
$taskValidator = new TaskValidator($this->container);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test'));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1));
$this->assertFalse($result[0]);
$result = $taskValidator->validateCreation(array('title' => 'test'));
$this->assertFalse($result[0]);
}
public function testRangeFields()
{
$taskValidator = new TaskValidator($this->container);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483647));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483647));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 0));
$this->assertTrue($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => 2147483648));
$this->assertFalse($result[0]);
$result = $taskValidator->validateCreation(array('project_id' => 1, 'title' => 'test', 'score' => -2147483648));
$this->assertFalse($result[0]);
}
}

View File

@@ -9,7 +9,7 @@ class UserValidatorTest extends Base
{ {
public function testValidatePasswordModification() public function testValidatePasswordModification()
{ {
$validator = new UserValidator($this->container); $userValidator = new UserValidator($this->container);
$this->container['sessionStorage']->user = array( $this->container['sessionStorage']->user = array(
'id' => 1, 'id' => 1,
@@ -17,25 +17,25 @@ class UserValidatorTest extends Base
'username' => 'admin', 'username' => 'admin',
); );
$result = $validator->validatePasswordModification(array()); $result = $userValidator->validatePasswordModification(array());
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validatePasswordModification(array('id' => 1)); $result = $userValidator->validatePasswordModification(array('id' => 1));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456')); $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong')); $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456')); $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong')); $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong'));
$this->assertFalse($result[0]); $this->assertFalse($result[0]);
$result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin')); $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin'));
$this->assertTrue($result[0]); $this->assertTrue($result[0]);
} }
} }