diff --git a/server/controllers/article/add-topic.php b/server/controllers/article/add-topic.php index a81bdd97..c0446d32 100755 --- a/server/controllers/article/add-topic.php +++ b/server/controllers/article/add-topic.php @@ -36,8 +36,8 @@ class AddTopicController extends Controller { 'permission' => 'staff_2', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(1, 200), - 'error' => ERRORS::INVALID_TITLE + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), + 'error' => ERRORS::INVALID_NAME ], ] ]; diff --git a/server/controllers/article/add.php b/server/controllers/article/add.php index 452d6463..cfd980a8 100755 --- a/server/controllers/article/add.php +++ b/server/controllers/article/add.php @@ -14,7 +14,7 @@ DataValidator::with('CustomValidations', true); * * @apiPermission staff2 * - * @apiParam {String} title Title of the new article. + * @apiParam {String} name Name of the new article. * @apiParam {String} content Content of the new article. * @apiParam {Number} position Position of the new article. * @apiParam {Number} topicId Id of the articles's topic. @@ -39,8 +39,8 @@ class AddArticleController extends Controller { return [ 'permission' => 'staff_2', 'requestData' => [ - 'title' => [ - 'validation' => DataValidator::notBlank()->length(1, 100), + 'name' => [ + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'content' => [ @@ -64,7 +64,7 @@ class AddArticleController extends Controller { $article = new Article(); $article->setProperties([ - 'title' => Controller::request('title', true), + 'title' => Controller::request('name', true), 'content' => $this->replaceWithImagePaths($imagePaths, $content), 'lastEdited' => Date::getCurrentDate(), 'position' => Controller::request('position') || 1 diff --git a/server/controllers/article/edit-topic.php b/server/controllers/article/edit-topic.php index 085e9fcb..bae3b865 100755 --- a/server/controllers/article/edit-topic.php +++ b/server/controllers/article/edit-topic.php @@ -40,7 +40,7 @@ class EditTopicController extends Controller { 'error' => ERRORS::INVALID_TOPIC ], 'name' => [ - 'validation' => DataValidator::notBlank()->length(1, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], diff --git a/server/controllers/article/edit.php b/server/controllers/article/edit.php index c5a4b569..11be69ec 100755 --- a/server/controllers/article/edit.php +++ b/server/controllers/article/edit.php @@ -17,7 +17,7 @@ DataValidator::with('CustomValidations', true); * @apiParam {Number} articleId Id of the article. * @apiParam {Number} topicId Id of the topic of the article. Optional. * @apiParam {String} content The new content of the article. Optional. - * @apiParam {String} title The new title of the article. Optional. + * @apiParam {String} name The new name of the article. Optional. * @apiParam {Number} position The new position of the article. Optional. * @apiParam {Number} images The number of images in the content * @apiParam image_i The image file of index `i` (mutiple params accepted) @@ -42,9 +42,12 @@ class EditArticleController extends Controller { 'validation' => DataValidator::dataStoreId('article'), 'error' => ERRORS::INVALID_TOPIC ], - 'title' => [ - 'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(1, 200),DataValidator::nullType()), - 'error' => ERRORS::INVALID_TITLE + 'name' => [ + 'validation' => DataValidator::oneOf( + DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), + DataValidator::nullType() + ), + 'error' => ERRORS::INVALID_NAME ], 'content' => [ 'validation' => DataValidator::oneOf(DataValidator::content(),DataValidator::nullType()), @@ -78,8 +81,8 @@ class EditArticleController extends Controller { $article->content = $this->replaceWithImagePaths($imagePaths, $content); } - if(Controller::request('title')) { - $article->title = Controller::request('title'); + if(Controller::request('name')) { + $article->title = Controller::request('name'); } if(Controller::request('position')) { diff --git a/server/controllers/staff/edit.php b/server/controllers/staff/edit.php index 732e761b..47d88f80 100755 --- a/server/controllers/staff/edit.php +++ b/server/controllers/staff/edit.php @@ -42,7 +42,10 @@ class EditStaffController extends Controller { 'error' => ERRORS::INVALID_EMAIL ], 'password' => [ - 'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(5, 200), DataValidator::falseVal()), + 'validation' => DataValidator::oneOf( + DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD), + DataValidator::falseVal() + ), 'error' => ERRORS::INVALID_PASSWORD ], 'level' => [ diff --git a/server/controllers/staff/invite.php b/server/controllers/staff/invite.php index b5f4b208..7d63700b 100755 --- a/server/controllers/staff/invite.php +++ b/server/controllers/staff/invite.php @@ -48,7 +48,7 @@ class InviteStaffController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 55), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'email' => [ diff --git a/server/controllers/staff/search-tickets.php b/server/controllers/staff/search-tickets.php index f9bd3492..24a74e0b 100755 --- a/server/controllers/staff/search-tickets.php +++ b/server/controllers/staff/search-tickets.php @@ -35,7 +35,7 @@ class SearchTicketStaffController extends Controller { 'permission' => 'staff_1', 'requestData' => [ 'query' => [ - 'validation' => DataValidator::notBlank()->length(1), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_QUERY), 'error' => ERRORS::INVALID_QUERY ], 'page' => [ diff --git a/server/controllers/system/add-api-key.php b/server/controllers/system/add-api-key.php index 315ed36c..40256180 100755 --- a/server/controllers/system/add-api-key.php +++ b/server/controllers/system/add-api-key.php @@ -35,7 +35,7 @@ class AddAPIKeyController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 55)->alnum(), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME)->alnum(), 'error' => ERRORS::INVALID_NAME ] ] diff --git a/server/controllers/system/add-custom-field.php b/server/controllers/system/add-custom-field.php index 677ae5ea..1e584d1f 100644 --- a/server/controllers/system/add-custom-field.php +++ b/server/controllers/system/add-custom-field.php @@ -37,11 +37,11 @@ class AddCustomFieldController extends Controller { 'permission' => 'staff_2', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 100), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'description' => [ - 'validation' => DataValidator::notBlank()->length(2, 100), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_DESCRIPTION, LengthConfig::MAX_LENGTH_DESCRIPTION), 'error' => ERRORS::INVALID_DESCRIPTION ], 'type' => [ diff --git a/server/controllers/system/add-department.php b/server/controllers/system/add-department.php index 46e56d5e..8debb8ef 100755 --- a/server/controllers/system/add-department.php +++ b/server/controllers/system/add-department.php @@ -31,7 +31,7 @@ class AddDepartmentController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 100), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ] ] diff --git a/server/controllers/system/delete-api-key.php b/server/controllers/system/delete-api-key.php index c7233763..d78efa9b 100755 --- a/server/controllers/system/delete-api-key.php +++ b/server/controllers/system/delete-api-key.php @@ -31,7 +31,7 @@ class DeleteAPIKeyController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 55), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ] ] diff --git a/server/controllers/system/edit-department.php b/server/controllers/system/edit-department.php index 72b3b93a..5d10bdef 100755 --- a/server/controllers/system/edit-department.php +++ b/server/controllers/system/edit-department.php @@ -39,7 +39,7 @@ class EditDepartmentController extends Controller { 'error' => ERRORS::INVALID_DEPARTMENT ], 'name' => [ - 'validation' => DataValidator::notBlank()->length(1, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], ] diff --git a/server/controllers/system/edit-mail-template.php b/server/controllers/system/edit-mail-template.php index 53727898..8fa708f3 100755 --- a/server/controllers/system/edit-mail-template.php +++ b/server/controllers/system/edit-mail-template.php @@ -46,15 +46,15 @@ class EditMailTemplateController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'template' => [ - 'validation' => DataValidator::notBlank()->length(4), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TEMPLATE), 'error' => ERRORS::INVALID_TEMPLATE ], 'language' => [ - 'validation' => DataValidator::notBlank()->length(2,2), + 'validation' => DataValidator::oneOf(DataValidator::in(Language::getSupportedLanguages()), DataValidator::nullType()), 'error' => ERRORS::INVALID_LANGUAGE ], 'subject' => [ - 'validation' => DataValidator::notBlank()->length(4), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_SUBJECT), 'error' => ERRORS::INVALID_SUBJECT ], ] diff --git a/server/controllers/system/email-polling.php b/server/controllers/system/email-polling.php index 614ceecd..7a7ed8d7 100755 --- a/server/controllers/system/email-polling.php +++ b/server/controllers/system/email-polling.php @@ -12,7 +12,7 @@ class EmailPollingController extends Controller { 'permission' => 'any', 'requestData' => [ 'token' => [ - 'validation' => DataValidator::notBlank()->length(1, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TOKEN, LengthConfig::MAX_LENGTH_TOKEN), 'error' => ERRORS::INVALID_TOKEN ] ] diff --git a/server/controllers/system/get-mail-template.php b/server/controllers/system/get-mail-template.php index 2da3cbca..07202ca8 100755 --- a/server/controllers/system/get-mail-template.php +++ b/server/controllers/system/get-mail-template.php @@ -31,11 +31,11 @@ class GetMailTemplateController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'template' => [ - 'validation' => DataValidator::notBlank()->length(4), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TEMPLATE), 'error' => ERRORS::INVALID_TEMPLATE ], 'language' => [ - 'validation' => DataValidator::notBlank()->length(2, 2), + 'validation' => DataValidator::oneOf(DataValidator::in(Language::getSupportedLanguages()), DataValidator::nullType()), 'error' => ERRORS::INVALID_LANGUAGE ], ] diff --git a/server/controllers/system/init-admin.php b/server/controllers/system/init-admin.php index 466928ad..c62cde6a 100755 --- a/server/controllers/system/init-admin.php +++ b/server/controllers/system/init-admin.php @@ -36,7 +36,7 @@ class InitAdminController extends Controller { 'permission' => 'any', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 55), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'email' => [ @@ -44,7 +44,7 @@ class InitAdminController extends Controller { 'error' => ERRORS::INVALID_EMAIL ], 'password' => [ - 'validation' => DataValidator::notBlank()->length(5, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD), 'error' => ERRORS::INVALID_PASSWORD ], ] diff --git a/server/controllers/system/recover-mail-template.php b/server/controllers/system/recover-mail-template.php index 1bf2a582..57aa4883 100755 --- a/server/controllers/system/recover-mail-template.php +++ b/server/controllers/system/recover-mail-template.php @@ -33,11 +33,11 @@ class RecoverMailTemplateController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'template' => [ - 'validation' => DataValidator::notBlank()->length(4), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TEMPLATE), 'error' => ERRORS::INVALID_TEMPLATE ], 'language' => [ - 'validation' => DataValidator::notBlank()->length(2, 2), + 'validation' => DataValidator::oneOf(DataValidator::in(Language::getSupportedLanguages()), DataValidator::nullType()), 'error' => ERRORS::INVALID_LANGUAGE ], ] diff --git a/server/controllers/ticket/add-custom-response.php b/server/controllers/ticket/add-custom-response.php index fe032ae4..22c5c1e2 100755 --- a/server/controllers/ticket/add-custom-response.php +++ b/server/controllers/ticket/add-custom-response.php @@ -36,7 +36,7 @@ class AddCustomResponseController extends Controller { 'permission' => 'staff_2', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(5, 100), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_TITLE ], 'content' => [ diff --git a/server/controllers/ticket/create-tag.php b/server/controllers/ticket/create-tag.php index c619dfa2..a2bf4a35 100644 --- a/server/controllers/ticket/create-tag.php +++ b/server/controllers/ticket/create-tag.php @@ -34,7 +34,7 @@ class CreateTagController extends Controller { 'permission' => 'staff_3', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 100), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'color' => [ diff --git a/server/controllers/ticket/create.php b/server/controllers/ticket/create.php index cb0833e4..3810baa9 100755 --- a/server/controllers/ticket/create.php +++ b/server/controllers/ticket/create.php @@ -56,7 +56,7 @@ class CreateController extends Controller { 'permission' => 'user', 'requestData' => [ 'title' => [ - 'validation' => DataValidator::notBlank()->length(1, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE), 'error' => ERRORS::INVALID_TITLE ], 'content' => [ @@ -84,7 +84,7 @@ class CreateController extends Controller { 'error' => ERRORS::INVALID_EMAIL ]; $validations['requestData']['name'] = [ - 'validation' => DataValidator::notBlank()->length(2, 55), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ]; } diff --git a/server/controllers/ticket/edit-custom-response.php b/server/controllers/ticket/edit-custom-response.php index 85233cb2..d73dafe3 100755 --- a/server/controllers/ticket/edit-custom-response.php +++ b/server/controllers/ticket/edit-custom-response.php @@ -36,14 +36,17 @@ class EditCustomResponseController extends Controller { 'requestData' => [ 'id' => [ 'validation' => DataValidator::dataStoreId('customresponse'), - 'error' => ERRORS::INVALID_NAME + 'error' => ERRORS::INVALID_CUSTOM_RESPONSE ], 'content' => [ 'validation' => DataValidator::content(), 'error' => ERRORS::INVALID_CONTENT ], 'name' => [ - 'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(1, 200),DataValidator::nullType()), + 'validation' => DataValidator::oneOf( + DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), + DataValidator::nullType() + ), 'error' => ERRORS::INVALID_NAME ], ] diff --git a/server/controllers/ticket/edit-tag.php b/server/controllers/ticket/edit-tag.php index ea7a4e96..3c068140 100644 --- a/server/controllers/ticket/edit-tag.php +++ b/server/controllers/ticket/edit-tag.php @@ -43,7 +43,7 @@ class EditTagController extends Controller { 'error' => ERRORS::INVALID_COLOR ], 'name' => [ - 'validation' => DataValidator::notBlank()->length(1, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ] ] diff --git a/server/controllers/ticket/edit-title.php b/server/controllers/ticket/edit-title.php index dfe9b49c..0ea4e9ba 100644 --- a/server/controllers/ticket/edit-title.php +++ b/server/controllers/ticket/edit-title.php @@ -34,7 +34,7 @@ class EditTitleController extends Controller { 'permission' => 'user', 'requestData' => [ 'title' => [ - 'validation' => DataValidator::notBlank()->length(1, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE), 'error' => ERRORS::INVALID_TITLE ], 'ticketNumber' => [ diff --git a/server/controllers/user/edit-password.php b/server/controllers/user/edit-password.php index 67a84fc0..130b7ffc 100755 --- a/server/controllers/user/edit-password.php +++ b/server/controllers/user/edit-password.php @@ -33,7 +33,7 @@ class EditPassword extends Controller { 'permission' => 'user', 'requestData' => [ 'newPassword' => [ - 'validation' => DataValidator::notBlank()->length(5, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD), 'error' => ERRORS::INVALID_PASSWORD ] ] diff --git a/server/controllers/user/invite.php b/server/controllers/user/invite.php index 9bc84d24..678133e6 100755 --- a/server/controllers/user/invite.php +++ b/server/controllers/user/invite.php @@ -45,7 +45,7 @@ class InviteUserController extends Controller { 'permission' => 'staff_1', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 55), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'email' => [ diff --git a/server/controllers/user/recover-password.php b/server/controllers/user/recover-password.php index eab3f188..34be6cf8 100755 --- a/server/controllers/user/recover-password.php +++ b/server/controllers/user/recover-password.php @@ -47,7 +47,7 @@ class RecoverPasswordController extends Controller { 'error' => ERRORS::INVALID_EMAIL ], 'password' => [ - 'validation' => DataValidator::notBlank()->length(5, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD), 'error' => ERRORS::INVALID_PASSWORD ] ] diff --git a/server/controllers/user/signup.php b/server/controllers/user/signup.php index da719f85..98b1f5c5 100755 --- a/server/controllers/user/signup.php +++ b/server/controllers/user/signup.php @@ -56,7 +56,7 @@ class SignUpController extends Controller { 'permission' => 'any', 'requestData' => [ 'name' => [ - 'validation' => DataValidator::notBlank()->length(2, 55), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME), 'error' => ERRORS::INVALID_NAME ], 'email' => [ @@ -64,7 +64,7 @@ class SignUpController extends Controller { 'error' => ERRORS::INVALID_EMAIL ], 'password' => [ - 'validation' => DataValidator::notBlank()->length(5, 200), + 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD), 'error' => ERRORS::INVALID_PASSWORD ] ] diff --git a/server/data/ERRORS.php b/server/data/ERRORS.php index af9503e9..8ca25033 100755 --- a/server/data/ERRORS.php +++ b/server/data/ERRORS.php @@ -405,6 +405,7 @@ class ERRORS { const UNAVAILABLE_STATS = 'UNAVAILABLE_STATS'; const INVALID_COLOR = 'INVALID_COLOR'; const INVALID_API_KEY_PERMISSION = 'INVALID_API_KEY_PERMISSION'; + const INVALID_CUSTOM_RESPONSE = 'INVALID_CUSTOM_RESPONSE'; const MANDATORY_LOGIN_IS_DESACTIVATED = 'MANDATORY_LOGIN_IS_DESACTIVATED'; const REGISTRATION_IS_DESACTIVATED = 'REGISTRATION_IS_DESACTIVATED'; const INVALID_SUPERVISED_USERS = 'INVALID_SUPERVISED_USERS'; diff --git a/server/data/length-config.php b/server/data/length-config.php new file mode 100644 index 00000000..0b54fc64 --- /dev/null +++ b/server/data/length-config.php @@ -0,0 +1,25 @@ + + 'staff@opensupports.com', - :password => 'staff' + :email => 'admin@opensupports.com', + :password => 'admin22' } diff --git a/tests/staff/get-all.rb b/tests/staff/get-all.rb index 1fdc643d..f58acecc 100644 --- a/tests/staff/get-all.rb +++ b/tests/staff/get-all.rb @@ -15,7 +15,7 @@ describe'/staff/get-all' do end (result['data'][0]['name']).should.equal('Emilia Clarke') - (result['data'][0]['email']).should.equal('staff@opensupports.com') + (result['data'][0]['email']).should.equal($staff[:email]) (result['data'][0]['profilePic']).should.equal('') (result['data'][0]['level']).should.equal('3') (result['data'][0]['departments'][0]['id']).should.equal('1') diff --git a/tests/staff/get.rb b/tests/staff/get.rb index 6f10d238..8368047b 100644 --- a/tests/staff/get.rb +++ b/tests/staff/get.rb @@ -11,7 +11,7 @@ describe '/staff/get/' do (result['status']).should.equal('success') (result['data']['name']).should.equal('Emilia Clarke') (result['data']['staff']).should.equal(true) - (result['data']['email']).should.equal('staff@opensupports.com') + (result['data']['email']).should.equal($staff[:email]) (result['data']['level']).should.equal('3') (result['data']['sendEmailOnNewTicket']).should.equal('1') end diff --git a/tests/staff/invite.rb b/tests/staff/invite.rb index 914e722e..0b5e525f 100644 --- a/tests/staff/invite.rb +++ b/tests/staff/invite.rb @@ -55,7 +55,7 @@ describe'/staff/invite' do result = request('/staff/invite', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'Tyrion LannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannister', + name: 'Tyrion LannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannister', email: 'tyrion@opensupports.com', level: 1, profilePic: '', @@ -67,7 +67,7 @@ describe'/staff/invite' do result = request('/staff/invite', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'T', + name: '', email: 'tyrion@opensupports.com', level: 1, profilePic: '', diff --git a/tests/system/add-api-key.rb b/tests/system/add-api-key.rb index 04b7f9ae..1b439254 100644 --- a/tests/system/add-api-key.rb +++ b/tests/system/add-api-key.rb @@ -34,7 +34,7 @@ describe'system/add-api-key' do result= request('/system/add-api-key', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'A', + name: '', }) (result['status']).should.equal('fail') @@ -43,7 +43,7 @@ describe'system/add-api-key' do result= request('/system/add-api-key', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'APIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAME', + name: 'APIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAME', }) (result['status']).should.equal('fail') diff --git a/tests/system/apikey-permissions.rb b/tests/system/apikey-permissions.rb index 9523aa84..018a2bc4 100644 --- a/tests/system/apikey-permissions.rb +++ b/tests/system/apikey-permissions.rb @@ -11,7 +11,7 @@ describe '/system/apikey-permissions' do request('/system/disable-mandatory-login', { "csrf_userid" => $csrf_userid, "csrf_token" => $csrf_token, - "password" => "staff" + "password" => $staff[:password] }) request('/system/edit-settings', { "csrf_userid" => $csrf_userid, diff --git a/tests/system/custom-fields.rb b/tests/system/custom-fields.rb index b5598c30..4785d871 100644 --- a/tests/system/custom-fields.rb +++ b/tests/system/custom-fields.rb @@ -8,7 +8,7 @@ describe 'Custom fields' do result = request('/system/add-custom-field', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'A', + name: '', type: 'text', description: 'custom field description', options: nil @@ -21,7 +21,7 @@ describe 'Custom fields' do it 'should fail if the name is to long' do long_text = '' - 101.times {long_text << 'A'} + 201.times {long_text << 'A'} result = request('/system/add-custom-field', { csrf_userid: $csrf_userid, diff --git a/tests/system/default-department.rb b/tests/system/default-department.rb index 4af70d88..be136326 100644 --- a/tests/system/default-department.rb +++ b/tests/system/default-department.rb @@ -1,10 +1,10 @@ describe '/system/default-department' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) it 'should fail if try to turn a private department default' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) privatedepartment = $database.getRow('department', 1, 'private') @@ -47,7 +47,7 @@ describe '/system/default-department' do it 'should set a new default deparment' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) publicdepartment = $database.getRow('department', 'Suggestions', 'name') @@ -62,7 +62,7 @@ describe '/system/default-department' do it 'should fail if try to delete the default department' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) defaultDepartment = $database.getRow('setting', 'default-department-id', 'name') transferDepartment = $database.getRow('department','new department','name') @@ -80,7 +80,8 @@ describe '/system/default-department' do it 'should fail if try to edit default department into private' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) + defaultDepartmentId = $database.getRow('setting', 'default-department-id', 'name') department = $database.getRow('department',defaultDepartmentId['value'],'id') @@ -98,7 +99,7 @@ describe '/system/default-department' do it 'should create ticket in default department if Staff does not give department with locked on' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) Scripts.updateLockedDepartmentSetting(1) result = request('/ticket/create', { @@ -117,7 +118,7 @@ describe '/system/default-department' do it 'should create ticket in default department if staff does not give department with locked off'do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) Scripts.updateLockedDepartmentSetting(0) result = request('/ticket/create', { @@ -136,7 +137,7 @@ describe '/system/default-department' do it 'should create ticket in selected department if staff give department and lockd is off'do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) Scripts.updateLockedDepartmentSetting(0) result = request('/ticket/create', { @@ -155,7 +156,7 @@ describe '/system/default-department' do it 'should create ticket in selected department if staff give department and locked is on' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) Scripts.updateLockedDepartmentSetting(1) result = request('/ticket/create', { @@ -173,9 +174,8 @@ describe '/system/default-department' do end it 'should create ticket on default department if user does not give department and locked is on' do - Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) Scripts.updateLockedDepartmentSetting(1) Scripts.logout() @@ -198,9 +198,8 @@ describe '/system/default-department' do end it 'should create ticket on default department if user does not give department and locked is off'do - Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) Scripts.updateLockedDepartmentSetting(0) Scripts.logout() @@ -221,9 +220,8 @@ describe '/system/default-department' do end it 'should create ticket on selected department if user give department and locked is off'do - Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) Scripts.updateLockedDepartmentSetting(0) Scripts.logout() diff --git a/tests/system/edit-settings.rb b/tests/system/edit-settings.rb index 204e4b74..3f9e498b 100755 --- a/tests/system/edit-settings.rb +++ b/tests/system/edit-settings.rb @@ -93,7 +93,7 @@ describe'system/edit-settings' do (lastLog['type']).should.equal('EDIT_SETTINGS') - Scripts.updateLockedDepartmentSetting(0); + Scripts.updateLockedDepartmentSetting(0) Scripts.logout() end @@ -102,7 +102,7 @@ describe'system/edit-settings' do Scripts.login($staff[:email], $staff[:password], true) Scripts.createTicket('TicketToDeleteWithoutUsersCreated') - ticket = $database.getRow('ticket', 'TicketToDeleteWithoutUsersCreated', 'title'); + ticket = $database.getRow('ticket', 'TicketToDeleteWithoutUsersCreated', 'title') result = request('/ticket/delete', { ticketNumber: ticket['ticket_number'], diff --git a/tests/system/file-upload-download.rb b/tests/system/file-upload-download.rb index ac52e7f3..598e898b 100644 --- a/tests/system/file-upload-download.rb +++ b/tests/system/file-upload-download.rb @@ -40,7 +40,7 @@ describe 'File Upload and Download' do it 'should download if department owner is logged' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) ticket = $database.getLastRow('ticket') file = File.open("../server/files/" + ticket['file']) diff --git a/tests/system/mandatory-login.rb b/tests/system/mandatory-login.rb index 087bcba5..00205d63 100644 --- a/tests/system/mandatory-login.rb +++ b/tests/system/mandatory-login.rb @@ -21,12 +21,12 @@ describe'system/mandatory-login' do request('/system/disable-registration', { "csrf_userid" => $csrf_userid, "csrf_token" => $csrf_token, - "password" => "staff" + "password" => $staff[:password] }) result = request('/system/disable-mandatory-login', { "csrf_userid" => $csrf_userid, "csrf_token" => $csrf_token, - "password" => "staff" + "password" => $staff[:password] }) (result['status']).should.equal('fail') @@ -38,7 +38,7 @@ describe'system/mandatory-login' do request('/system/enable-registration', { "csrf_userid" => $csrf_userid, "csrf_token" => $csrf_token, - "password" => "staff" + "password" => $staff[:password] }) end @@ -59,7 +59,7 @@ describe'system/mandatory-login' do result = request('/system/disable-mandatory-login', { "csrf_userid" => $csrf_userid, "csrf_token" => $csrf_token, - "password" => "staff" + "password" => $staff[:password] }) (result['status']).should.equal('success') @@ -73,7 +73,7 @@ describe'system/mandatory-login' do result = request('/system/disable-registration', { "csrf_userid" => $csrf_userid, "csrf_token" => $csrf_token, - "password" => "staff" + "password" => $staff[:password] }) (result['status']).should.equal('fail') @@ -358,7 +358,7 @@ describe'system/mandatory-login' do result = request('/system/enable-mandatory-login', { "csrf_userid" => $csrf_userid, "csrf_token" => $csrf_token, - "password" => "staff" + "password" => $staff[:password] }) (result['status']).should.equal('success') diff --git a/tests/ticket/create-tag.rb b/tests/ticket/create-tag.rb index d5a736c7..9bb861a4 100644 --- a/tests/ticket/create-tag.rb +++ b/tests/ticket/create-tag.rb @@ -41,7 +41,7 @@ describe '/ticket/create-tag' do result = request('/ticket/create-tag', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'T', + name: '', color: '#0000ff' }) @@ -49,7 +49,7 @@ describe '/ticket/create-tag' do (result['message']).should.equal('INVALID_NAME') long_text = '' - 200.times {long_text << 'a'} + 201.times {long_text << 'a'} result = request('/ticket/create-tag', { csrf_userid: $csrf_userid, diff --git a/tests/ticket/create.rb b/tests/ticket/create.rb index 16e03ed2..9639124a 100644 --- a/tests/ticket/create.rb +++ b/tests/ticket/create.rb @@ -79,7 +79,7 @@ describe '/ticket/create' do end it 'should fail if an user tries to create a ticket with a private department' do Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) result = request('/system/add-department', { csrf_userid: $csrf_userid, diff --git a/tests/ticket/custom-response.rb b/tests/ticket/custom-response.rb index c98659c8..e425dd60 100644 --- a/tests/ticket/custom-response.rb +++ b/tests/ticket/custom-response.rb @@ -1,6 +1,6 @@ describe 'CustomResponses' do - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) describe '/ticket/add-custom-responses/' do it 'should create custom response' do diff --git a/tests/ticket/delete.rb b/tests/ticket/delete.rb index c9ba7776..a0e60320 100644 --- a/tests/ticket/delete.rb +++ b/tests/ticket/delete.rb @@ -42,7 +42,7 @@ describe '/ticket/delete' do Scripts.login('deleter@opensupports.com', 'deleterpassword') Scripts.createTicket('ticket_to_delete_2') - ticket = $database.getRow('ticket', 'ticket_to_delete_2', 'title'); + ticket = $database.getRow('ticket', 'ticket_to_delete_2', 'title') result = request('/ticket/delete', { ticketNumber: ticket['ticket_number'], csrf_userid: $csrf_userid, @@ -56,7 +56,7 @@ describe '/ticket/delete' do Scripts.login('deleter@opensupports.com', 'deleterpassword') Scripts.createTicket('ticket_to_delete_3') - ticket = $database.getRow('ticket', 'ticket_to_delete_3', 'title'); + ticket = $database.getRow('ticket', 'ticket_to_delete_3', 'title') Scripts.logout() Scripts.login($staff[:email], $staff[:password], true) @@ -85,7 +85,7 @@ describe '/ticket/delete' do Scripts.login($staff[:email], $staff[:password], true) Scripts.createTicket('ticket_to_delete_4') - ticket = $database.getRow('ticket', 'ticket_to_delete_4', 'title'); + ticket = $database.getRow('ticket', 'ticket_to_delete_4', 'title') request('/staff/invite', { csrf_userid: $csrf_userid, diff --git a/tests/ticket/edit-comment.rb b/tests/ticket/edit-comment.rb index 28ef56fa..4e807f69 100644 --- a/tests/ticket/edit-comment.rb +++ b/tests/ticket/edit-comment.rb @@ -1,7 +1,7 @@ describe '/ticket/edit-comment' do Scripts.logout() - Scripts.login(); + Scripts.login() Scripts.createTicket('ticket made by an user','content of the ticket made by an user') ticket = $database.getRow('ticket', 'ticket made by an user', 'title') Scripts.commentTicket(ticket['ticket_number'],'com ment of a user') @@ -81,7 +81,7 @@ describe '/ticket/edit-comment' do ticketevent = $database.getRow('ticketevent', 'this is a new comment of a staff member', 'content') Scripts.logout() - Scripts.login(); + Scripts.login() result = request('/ticket/edit-comment', { csrf_userid: $csrf_userid, diff --git a/tests/ticket/edit-title.rb b/tests/ticket/edit-title.rb index 9cb024ff..b6aa9de1 100644 --- a/tests/ticket/edit-title.rb +++ b/tests/ticket/edit-title.rb @@ -1,7 +1,7 @@ describe '/ticket/edit-title' do Scripts.logout() - Scripts.login(); + Scripts.login() Scripts.createTicket('Valar Morghulis','content of the ticket made by an user') ticket = $database.getRow('ticket', 'Valar Morghulis', 'title') ticketNumber = ticket['ticket_number'] diff --git a/tests/ticket/get-authors.rb b/tests/ticket/get-authors.rb index b8671a2e..0a35a693 100644 --- a/tests/ticket/get-authors.rb +++ b/tests/ticket/get-authors.rb @@ -80,7 +80,7 @@ describe '/ticket/get-authors/' do end it 'should succed if you try to get a staff' do - staffauthor = $database.getRow('staff', 'staff@opensupports.com', 'email') + staffauthor = $database.getRow('staff', $staff[:email], 'email') authorsstring = '[{"isStaff":1,"id":' authorsstring.concat(staffauthor['id'].to_s) authorsstring.concat('}]') @@ -98,7 +98,7 @@ describe '/ticket/get-authors/' do end it 'should succed if you try to get a staff and a user' do userauthor = $database.getRow('user', 'userauthor@os4.com', 'email') - staffauthor = $database.getRow('staff', 'staff@opensupports.com', 'email') + staffauthor = $database.getRow('staff', $staff[:email], 'email') authorsstring = '[{"isStaff":1,"id":' authorsstring.concat(staffauthor['id'].to_s) authorsstring.concat('},{"isStaff":0,"id":') @@ -121,7 +121,7 @@ describe '/ticket/get-authors/' do end it 'should succed if you try to get a author without duplicate' do - staffauthor = $database.getRow('staff', 'staff@opensupports.com', 'email') + staffauthor = $database.getRow('staff', $staff[:email], 'email') authorsstring = '[{"isStaff":1,"id":' authorsstring.concat(staffauthor['id'].to_s) authorsstring.concat('},{"isStaff":1,"id":') diff --git a/tests/user/ban.rb b/tests/user/ban.rb index 65fb9726..4421bfbd 100644 --- a/tests/user/ban.rb +++ b/tests/user/ban.rb @@ -2,8 +2,8 @@ describe '/user/ban' do Scripts.logout() result = request('/user/login', { - email: 'staff@opensupports.com', - password: 'staff', + email: $staff[:email], + password: $staff[:password], staff: true }) (result['status']).should.equal('success') diff --git a/tests/user/delete.rb b/tests/user/delete.rb index a7aacbb2..eb6767ac 100644 --- a/tests/user/delete.rb +++ b/tests/user/delete.rb @@ -7,7 +7,7 @@ describe '/user/delete' do Scripts.createTicket('Ticket that will be deleted') Scripts.logout() - Scripts.login('staff@opensupports.com', 'staff', true) + Scripts.login($staff[:email], $staff[:password], true) ticket = $database.getLastRow('ticket') deletable_user = $database.getLastRow('user') diff --git a/tests/user/enable-disable.rb b/tests/user/enable-disable.rb index 74eb36e9..afb45237 100644 --- a/tests/user/enable-disable.rb +++ b/tests/user/enable-disable.rb @@ -1,9 +1,9 @@ describe 'Enable/disable user' do - user = $database.getRow('user', 'login@os4.com', 'email'); + user = $database.getRow('user', 'login@os4.com', 'email') describe '/user/disable' do - Scripts.logout(); - Scripts.login('staff@opensupports.com', 'staff', true); + Scripts.logout() + Scripts.login($staff[:email], $staff[:password], true) it 'should disable user' do result = request('/user/disable', { @@ -12,7 +12,7 @@ describe 'Enable/disable user' do csrf_userid: $csrf_userid, }) - (result['status']).should.equal('success'); + (result['status']).should.equal('success') end it 'should not disable user if already disabled' do @@ -22,12 +22,12 @@ describe 'Enable/disable user' do csrf_userid: $csrf_userid, }) - (result['status']).should.equal('fail'); + (result['status']).should.equal('fail') (result['message']).should.equal('ALREADY_DISABLED') end it 'should reject login' do - Scripts.logout(); + Scripts.logout() result = request('/user/login', { email: 'login@os4.com', password: 'loginpass' @@ -39,8 +39,8 @@ describe 'Enable/disable user' do end describe '/user/enable' do - Scripts.logout(); - Scripts.login('staff@opensupports.com', 'staff', true); + Scripts.logout() + Scripts.login($staff[:email], $staff[:password], true) it 'should enable user' do result = request('/user/enable', { @@ -49,7 +49,7 @@ describe 'Enable/disable user' do csrf_userid: $csrf_userid, }) - (result['status']).should.equal('success'); + (result['status']).should.equal('success') end it 'should not enable user if already enabled' do @@ -59,7 +59,7 @@ describe 'Enable/disable user' do csrf_userid: $csrf_userid, }) - (result['status']).should.equal('fail'); + (result['status']).should.equal('fail') (result['message']).should.equal('ALREADY_ENABLED') result = request('/user/enable', { @@ -68,7 +68,7 @@ describe 'Enable/disable user' do csrf_userid: $csrf_userid, }) - (result['status']).should.equal('fail'); + (result['status']).should.equal('fail') (result['message']).should.equal('ALREADY_ENABLED') end end diff --git a/tests/user/get-user.rb b/tests/user/get-user.rb index 252b04a6..c0361434 100644 --- a/tests/user/get-user.rb +++ b/tests/user/get-user.rb @@ -2,8 +2,8 @@ describe '/user/get-user' do Scripts.logout() result = request('/user/login', { - email: 'staff@opensupports.com', - password: 'staff', + email: $staff[:email], + password: $staff[:password], staff: true }) diff --git a/tests/user/get-users-test.rb b/tests/user/get-users-test.rb index ba84b932..2813e330 100644 --- a/tests/user/get-users-test.rb +++ b/tests/user/get-users-test.rb @@ -6,8 +6,8 @@ describe '/user/get-users' do Scripts.createUser('tests3@hotmail.com','passfasfasfws','laeczvwaf') result = request('/user/login', { - email: 'staff@opensupports.com', - password: 'staff', + email: $staff[:email], + password: $staff[:password], staff: true }) diff --git a/tests/user/invite.rb b/tests/user/invite.rb index 4726d69c..e9f38758 100644 --- a/tests/user/invite.rb +++ b/tests/user/invite.rb @@ -7,7 +7,7 @@ describe'/user/invite' do result = request('/user/invite', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'i', + name: '', email: 'inviteduser2@opensupports.com' }) (result['status']).should.equal('fail') @@ -16,7 +16,7 @@ describe'/user/invite' do result = request('/user/invite', { csrf_userid: $csrf_userid, csrf_token: $csrf_token, - name: 'invited userinvited userinvited userinvited userinvited userinvited userinvited userinvited userinvited userinvited user', + name: 'invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user', email: 'inviteduser2@opensupports.com' }) (result['status']).should.equal('fail') diff --git a/tests/user/signup.rb b/tests/user/signup.rb index b0589489..32a02dab 100644 --- a/tests/user/signup.rb +++ b/tests/user/signup.rb @@ -22,10 +22,10 @@ describe '/user/signup' do it 'should fail if name is invalid' do long_text = '' - 100.times {long_text << 'a'} + 201.times {long_text << 'a'} result = request('/user/signup', { - name: 't', + name: '', email: 'tyrion@outlook.com', password: 'Lannister' })