diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-10-08 09:58:11 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-10-08 09:58:11 -0400 |
commit | c2f1cc8f7419fe4eb5e9bd5e6ce05d90e719be17 (patch) | |
tree | 93900cc242574a346f14e2002f050b5f2c7dc55e | |
parent | 1466afb771f0291bc350441aede14c97459128e7 (diff) |
Restrict task complexity to a specific range to avoid integer overflow
37 files changed, 179 insertions, 132 deletions
diff --git a/app/Locale/bs_BA/translations.php b/app/Locale/bs_BA/translations.php index d91f8428..f4f457a1 100644 --- a/app/Locale/bs_BA/translations.php +++ b/app/Locale/bs_BA/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/cs_CZ/translations.php b/app/Locale/cs_CZ/translations.php index 35668d11..8dd5fb20 100644 --- a/app/Locale/cs_CZ/translations.php +++ b/app/Locale/cs_CZ/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index af011f95..fa756b7f 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index d22fc64e..fb6967c4 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/el_GR/translations.php b/app/Locale/el_GR/translations.php index 3e06c22f..44f5e0df 100644 --- a/app/Locale/el_GR/translations.php +++ b/app/Locale/el_GR/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index cef9030a..cdd6c278 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index cffaa0c3..4f74cbf8 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index b428ec10..89f46181 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -1277,4 +1277,5 @@ return array( 'Duplicate to multiple projects' => 'Dupliquer vers plusieurs projets', 'This field is required' => 'Ce champ est requis', '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', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index bd8714eb..7123d461 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/id_ID/translations.php b/app/Locale/id_ID/translations.php index 78b465ab..ce52d328 100644 --- a/app/Locale/id_ID/translations.php +++ b/app/Locale/id_ID/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 0cd91de1..e4f51b3a 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 015868d8..20d2a145 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/ko_KR/translations.php b/app/Locale/ko_KR/translations.php index 00407b41..5e9110ea 100644 --- a/app/Locale/ko_KR/translations.php +++ b/app/Locale/ko_KR/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/my_MY/translations.php b/app/Locale/my_MY/translations.php index 944bc800..e3c852ac 100644 --- a/app/Locale/my_MY/translations.php +++ b/app/Locale/my_MY/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/nb_NO/translations.php b/app/Locale/nb_NO/translations.php index c81dde89..ff819787 100644 --- a/app/Locale/nb_NO/translations.php +++ b/app/Locale/nb_NO/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php index 4a98592a..22c76713 100644 --- a/app/Locale/nl_NL/translations.php +++ b/app/Locale/nl_NL/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index 6ebd1683..be39d095 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index 461d661a..95cd1067 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/pt_PT/translations.php b/app/Locale/pt_PT/translations.php index 655285b9..073a68c5 100644 --- a/app/Locale/pt_PT/translations.php +++ b/app/Locale/pt_PT/translations.php @@ -1276,4 +1276,5 @@ return array( 'Duplicate to multiple projects' => 'Duplicar para vários projetos', 'This field is required' => 'Este campo é obrigatório', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 36096aed..8a8147cc 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php index ac7e581b..6b5bd784 100644 --- a/app/Locale/sr_Latn_RS/translations.php +++ b/app/Locale/sr_Latn_RS/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 3ed3d61f..d8275616 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 6e9cc690..3cf7e3e5 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php index 79d03822..de88c1d6 100644 --- a/app/Locale/tr_TR/translations.php +++ b/app/Locale/tr_TR/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 4a7e6c5b..6dccd6cc 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -1276,4 +1276,5 @@ return array( // 'Duplicate to multiple projects' => '', // 'This field is required' => '', // 'Moving a task is not permitted' => '', + // 'This value must be in the range %d to %d' => '', ); diff --git a/app/Validator/TaskValidator.php b/app/Validator/TaskValidator.php index 8aa5c440..e3b0eded 100644 --- a/app/Validator/TaskValidator.php +++ b/app/Validator/TaskValidator.php @@ -28,6 +28,7 @@ class TaskValidator extends BaseValidator 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('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('swimlane_id', t('This value must be an integer')), new Validators\Integer('recurrence_child', t('This value must be an integer')), @@ -96,27 +97,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 * * @access public diff --git a/tests/units/Validator/CommentValidatorTest.php b/tests/units/Validator/CommentValidatorTest.php index 378fe924..ce65e7a3 100644 --- a/tests/units/Validator/CommentValidatorTest.php +++ b/tests/units/Validator/CommentValidatorTest.php @@ -8,50 +8,50 @@ class CommentValidatorTest extends Base { 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]); - $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]); - $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]); - $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]); - $result = $validator->validateCreation(array('user_id' => 1, 'comment' => 'bla')); + $result = $commentValidator->validateCreation(array('user_id' => 1, 'comment' => 'bla')); $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]); - $result = $validator->validateCreation(array('comment' => 'bla')); + $result = $commentValidator->validateCreation(array('comment' => 'bla')); $this->assertFalse($result[0]); - $result = $validator->validateCreation(array()); + $result = $commentValidator->validateCreation(array()); $this->assertFalse($result[0]); } 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]); - $result = $validator->validateModification(array('id' => 1, 'comment' => '')); + $result = $commentValidator->validateModification(array('id' => 1, 'comment' => '')); $this->assertFalse($result[0]); - $result = $validator->validateModification(array('comment' => 'bla')); + $result = $commentValidator->validateModification(array('comment' => 'bla')); $this->assertFalse($result[0]); - $result = $validator->validateModification(array('id' => 'b', 'comment' => 'bla')); + $result = $commentValidator->validateModification(array('id' => 'b', 'comment' => 'bla')); $this->assertFalse($result[0]); - $result = $validator->validateModification(array()); + $result = $commentValidator->validateModification(array()); $this->assertFalse($result[0]); } } diff --git a/tests/units/Validator/CurrencyValidatorTest.php b/tests/units/Validator/CurrencyValidatorTest.php index 39c06d44..0b646732 100644 --- a/tests/units/Validator/CurrencyValidatorTest.php +++ b/tests/units/Validator/CurrencyValidatorTest.php @@ -8,20 +8,20 @@ class CurrencyValidatorTest extends Base { public function testValidation() { - $validator = new CurrencyValidator($this->container); - $result = $validator->validateCreation(array()); + $currencyValidator = new CurrencyValidator($this->container); + $result = $currencyValidator->validateCreation(array()); $this->assertFalse($result[0]); - $result = $validator->validateCreation(array('currency' => 'EUR')); + $result = $currencyValidator->validateCreation(array('currency' => 'EUR')); $this->assertFalse($result[0]); - $result = $validator->validateCreation(array('rate' => 1.9)); + $result = $currencyValidator->validateCreation(array('rate' => 1.9)); $this->assertFalse($result[0]); - $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar')); + $result = $currencyValidator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar')); $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]); } } diff --git a/tests/units/Validator/CustomFilterValidatorTest.php b/tests/units/Validator/CustomFilterValidatorTest.php index 3b70e42c..4e107f7f 100644 --- a/tests/units/Validator/CustomFilterValidatorTest.php +++ b/tests/units/Validator/CustomFilterValidatorTest.php @@ -8,16 +8,16 @@ class CustomFilterValidatorTest extends Base { public function testValidateCreation() { - $validator = new CustomFilterValidator($this->container); + $customFilterValidator = new CustomFilterValidator($this->container); // 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]); - $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]); - $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]); } diff --git a/tests/units/Validator/ExternalLinkValidatorTest.php b/tests/units/Validator/ExternalLinkValidatorTest.php index b41b779a..c94c31db 100644 --- a/tests/units/Validator/ExternalLinkValidatorTest.php +++ b/tests/units/Validator/ExternalLinkValidatorTest.php @@ -8,27 +8,27 @@ class ExternalLinkValidatorTest extends Base { 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]); - $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]); - $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]); - $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]); - $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]); - $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]); - $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]); } diff --git a/tests/units/Validator/GroupValidatorTest.php b/tests/units/Validator/GroupValidatorTest.php index 879f99ce..020a8bc6 100644 --- a/tests/units/Validator/GroupValidatorTest.php +++ b/tests/units/Validator/GroupValidatorTest.php @@ -8,12 +8,12 @@ class GroupValidatorTest extends Base { 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]); - $result = $validator->validateCreation(array('name' => '')); + $result = $groupValidator->validateCreation(array('name' => '')); $this->assertFalse($result[0]); } diff --git a/tests/units/Validator/LinkValidatorTest.php b/tests/units/Validator/LinkValidatorTest.php index 8b7b182c..a4ec170e 100644 --- a/tests/units/Validator/LinkValidatorTest.php +++ b/tests/units/Validator/LinkValidatorTest.php @@ -8,21 +8,21 @@ class LinkValidatorTest extends Base { 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]); - $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'b')); + $r = $linkValidator->validateCreation(array('label' => 'a', 'opposite_label' => 'b')); $this->assertTrue($r[0]); - $r = $validator->validateCreation(array('label' => 'relates to')); + $r = $linkValidator->validateCreation(array('label' => 'relates to')); $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]); - $r = $validator->validateCreation(array('label' => '')); + $r = $linkValidator->validateCreation(array('label' => '')); $this->assertFalse($r[0]); } diff --git a/tests/units/Validator/PasswordResetValidatorTest.php b/tests/units/Validator/PasswordResetValidatorTest.php index d26ad422..eed77e42 100644 --- a/tests/units/Validator/PasswordResetValidatorTest.php +++ b/tests/units/Validator/PasswordResetValidatorTest.php @@ -8,22 +8,22 @@ class PasswordResetValidatorTest extends Base { public function testValidateModification() { - $validator = new PasswordResetValidator($this->container); - list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test123')); + $passwordResetValidator = new PasswordResetValidator($this->container); + list($valid, ) = $passwordResetValidator->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')); + $passwordResetValidator = new PasswordResetValidator($this->container); + list($valid, ) = $passwordResetValidator->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')); + $passwordResetValidator = new PasswordResetValidator($this->container); + list($valid, ) = $passwordResetValidator->validateModification(array('password' => 'test', 'confirmation' => 'test')); $this->assertFalse($valid); } @@ -31,8 +31,8 @@ class PasswordResetValidatorTest extends Base { $this->container['sessionStorage']->captcha = 'test'; - $validator = new PasswordResetValidator($this->container); - list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); + $passwordResetValidator = new PasswordResetValidator($this->container); + list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); $this->assertTrue($valid); } @@ -40,8 +40,8 @@ class PasswordResetValidatorTest extends Base { $this->container['sessionStorage']->captcha = 'test'; - $validator = new PasswordResetValidator($this->container); - list($valid,) = $validator->validateCreation(array('captcha' => 'test')); + $passwordResetValidator = new PasswordResetValidator($this->container); + list($valid,) = $passwordResetValidator->validateCreation(array('captcha' => 'test')); $this->assertFalse($valid); } @@ -49,15 +49,15 @@ class PasswordResetValidatorTest extends Base { $this->container['sessionStorage']->captcha = 'test123'; - $validator = new PasswordResetValidator($this->container); - list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); + $passwordResetValidator = new PasswordResetValidator($this->container); + list($valid,) = $passwordResetValidator->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')); + $passwordResetValidator = new PasswordResetValidator($this->container); + list($valid,) = $passwordResetValidator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); $this->assertFalse($valid); } } diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php index e1e2f077..212c5317 100644 --- a/tests/units/Validator/ProjectValidatorTest.php +++ b/tests/units/Validator/ProjectValidatorTest.php @@ -9,65 +9,65 @@ class ProjectValidatorTest extends Base { public function testValidateCreation() { - $validator = new ProjectValidator($this->container); - $p = new ProjectModel($this->container); + $projectValidator = new ProjectValidator($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2'))); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals('TEST1', $project['identifier']); - $project = $p->getById(2); + $project = $projectModel->getById(2); $this->assertNotEmpty($project); $this->assertEquals('', $project['identifier']); - $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); + $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); $this->assertFalse($r[0]); - $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test1')); + $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test1')); $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]); - $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); + $r = $projectValidator->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); $this->assertFalse($r[0]); } public function testValidateModification() { - $validator = new ProjectValidator($this->container); - $p = new ProjectModel($this->container); + $projectValidator = new ProjectValidator($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2'))); - $project = $p->getById(1); + $project = $projectModel->getById(1); $this->assertNotEmpty($project); $this->assertEquals('TEST1', $project['identifier']); - $project = $p->getById(2); + $project = $projectModel->getById(2); $this->assertNotEmpty($project); $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]); - $r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3')); + $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'test3')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'identifier' => '')); + $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => '')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2')); + $r = $projectValidator->validateModification(array('id' => 1, 'identifier' => 'TEST2')); $this->assertFalse($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => '')); + $r = $projectValidator->validateModification(array('id' => 1, 'name' => '')); $this->assertFalse($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => null)); + $r = $projectValidator->validateModification(array('id' => 1, 'name' => null)); $this->assertFalse($r[0]); } } diff --git a/tests/units/Validator/TaskLinkValidatorTest.php b/tests/units/Validator/TaskLinkValidatorTest.php index 5fc50e3e..414cf696 100644 --- a/tests/units/Validator/TaskLinkValidatorTest.php +++ b/tests/units/Validator/TaskLinkValidatorTest.php @@ -11,62 +11,62 @@ class TaskLinkValidatorTest extends Base { public function testValidateCreation() { - $validator = new TaskLinkValidator($this->container); - $tl = new TaskLinkModel($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); + $taskLinkValidator = new TaskLinkValidator($this->container); + $taskLinkModel = new TaskLinkModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); - $links = $tl->getAll(1); + $links = $taskLinkModel->getAll(1); $this->assertEmpty($links); - $links = $tl->getAll(2); + $links = $taskLinkModel->getAll(2); $this->assertEmpty($links); // 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]); - $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1)); + $r = $taskLinkValidator->validateCreation(array('task_id' => 1, 'link_id' => 1)); $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]); - $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]); - $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]); } public function testValidateModification() { - $validator = new TaskLinkValidator($this->container); - $p = new ProjectModel($this->container); - $tc = new TaskCreationModel($this->container); + $taskLinkValidator = new TaskLinkValidator($this->container); + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B'))); // 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]); - $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]); - $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]); - $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]); - $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]); } } diff --git a/tests/units/Validator/TaskValidatorTest.php b/tests/units/Validator/TaskValidatorTest.php new file mode 100644 index 00000000..f6530027 --- /dev/null +++ b/tests/units/Validator/TaskValidatorTest.php @@ -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]); + } +} diff --git a/tests/units/Validator/UserValidatorTest.php b/tests/units/Validator/UserValidatorTest.php index 6d904ade..64c76175 100644 --- a/tests/units/Validator/UserValidatorTest.php +++ b/tests/units/Validator/UserValidatorTest.php @@ -9,7 +9,7 @@ class UserValidatorTest extends Base { public function testValidatePasswordModification() { - $validator = new UserValidator($this->container); + $userValidator = new UserValidator($this->container); $this->container['sessionStorage']->user = array( 'id' => 1, @@ -17,25 +17,25 @@ class UserValidatorTest extends Base 'username' => 'admin', ); - $result = $validator->validatePasswordModification(array()); + $result = $userValidator->validatePasswordModification(array()); $this->assertFalse($result[0]); - $result = $validator->validatePasswordModification(array('id' => 1)); + $result = $userValidator->validatePasswordModification(array('id' => 1)); $this->assertFalse($result[0]); - $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456')); + $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456')); $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]); - $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456')); + $result = $userValidator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456')); $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]); - $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]); } } |