[DEV-26] Update length validations (#1075)

* Update length validations

* Fix language validations

* Remove unnecessary import

* Delete some semicolons
This commit is contained in:
LautaroCesso 2021-11-11 17:17:39 -03:00 committed by GitHub
parent c5f1aa2b92
commit d7ccff1a5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 151 additions and 118 deletions

View File

@ -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
],
]
];

View File

@ -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

View File

@ -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
],

View File

@ -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')) {

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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
]
]

View File

@ -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' => [

View File

@ -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
]
]

View File

@ -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
]
]

View File

@ -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
],
]

View File

@ -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
],
]

View File

@ -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
]
]

View File

@ -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
],
]

View File

@ -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
],
]

View File

@ -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
],
]

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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
];
}

View File

@ -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
],
]

View File

@ -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
]
]

View File

@ -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' => [

View File

@ -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
]
]

View File

@ -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' => [

View File

@ -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
]
]

View File

@ -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
]
]

View File

@ -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';

View File

@ -0,0 +1,25 @@
<?php
class LengthConfig {
const MIN_LENGTH_NAME = 1;
const MAX_LENGTH_NAME = 200;
const MIN_LENGTH_TITLE = 1;
const MAX_LENGTH_TITLE = 200;
const MIN_LENGTH_PASSWORD = 6;
const MAX_LENGTH_PASSWORD = 200;
const MIN_LENGTH_DESCRIPTION = 2;
const MAX_LENGTH_DESCRIPTION = 100;
const MIN_LENGTH_TOKEN = 1;
const MAX_LENGTH_TOKEN = 200;
const MIN_LENGTH_QUERY = 1;
const MIN_LENGTH_SUBJECT = 4;
const MIN_LENGTH_TEMPLATE = 4;
}

View File

@ -28,7 +28,7 @@ describe 'Article path' do
it 'should create article' do
result = request('/article/add', {
title: 'Some article',
name: 'Some article',
content: 'This is an article about server management.',
topicId: @topic_id,
position: 1,
@ -108,7 +108,7 @@ describe 'Article path' do
it 'should retrieve all articles' do
request('/article/add', {
title: 'Some article',
name: 'Some article',
content: 'This is an article about server management.',
topicId: @topic_id,
position: 1,

View File

@ -53,7 +53,7 @@ class Database
end
def query(query_string)
return @connection.query(query_string);
return @connection.query(query_string)
end
end
@ -153,6 +153,6 @@ $database = Database.new
# $mail_server.check
$staff = {
:email => 'staff@opensupports.com',
:password => 'staff'
:email => 'admin@opensupports.com',
:password => 'admin22'
}

View File

@ -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')

View File

@ -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

View File

@ -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: '',

View File

@ -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')

View File

@ -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,

View File

@ -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,

View File

@ -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','<b>new department</b>','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()

View File

@ -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'],

View File

@ -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'])

View File

@ -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')

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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,

View File

@ -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']

View File

@ -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":')

View File

@ -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')

View File

@ -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')

View File

@ -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

View File

@ -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
})

View File

@ -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
})

View File

@ -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')

View File

@ -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'
})