Skip to content

Commit 8169e50

Browse files
committed
Merge branch 'next' into estimation_correction
# Conflicts: # plugins/reports/api/reports.js
2 parents 63e26b3 + aa7f574 commit 8169e50

File tree

23 files changed

+564
-461
lines changed

23 files changed

+564
-461
lines changed

.github/issue_template.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!---
2+
If you discover any issue regarding security, please disclose the information responsibly
3+
by sending an email to [email protected] and not by creating a GitHub issue.
4+
-->
5+
16
<!--- Provide a general summary of the issue in the Title above -->
27

38
### Expected Behavior

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# Countly Analytics [![Build Status](https://api.travis-ci.org/Countly/countly-server.png?branch=master)](https://travis-ci.org/Countly/countly-server) [![Install Countly on DigitalOcean](https://do.count.ly/button.svg?v2)](http://do.count.ly)
2+
# Countly Analytics [![Build Status](https://api.travis-ci.org/Countly/countly-server.png?branch=master)](https://travis-ci.org/Countly/countly-server) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/98c2726f2d734697a5f1ac0d453f0a06)](https://app.codacy.com/app/ar2rsawseen/countly-server?utm_source=github.com&utm_medium=referral&utm_content=Countly/countly-server&utm_campaign=Badge_Grade_Dashboard) [![Install Countly on DigitalOcean](https://do.count.ly/button.svg?v2)](http://do.count.ly)
33

44
<br/>
55

api/parts/mgmt/apps.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ appsApi.createApp = function(params) {
185185
},
186186
newApp = {};
187187

188-
if (!(newApp = common.validateArgs(params.qstring.args, argProps))) {
189-
common.returnMessage(params, 400, 'Not enough args');
188+
var createAppValidation = common.validateArgs(params.qstring.args, argProps, true);
189+
if (!(newApp = createAppValidation.obj)) {
190+
common.returnMessage(params, 400, 'Error: ' + createAppValidation.errors);
190191
return false;
191192
}
192193

@@ -280,8 +281,9 @@ appsApi.updateApp = function(params) {
280281
},
281282
updatedApp = {};
282283

283-
if (!(updatedApp = common.validateArgs(params.qstring.args, argProps))) {
284-
common.returnMessage(params, 400, 'Not enough args');
284+
var updateAppValidation = common.validateArgs(params.qstring.args, argProps, true);
285+
if (!(updatedApp = updateAppValidation.obj)) {
286+
common.returnMessage(params, 400, 'Error: ' + updateAppValidation.errors);
285287
return false;
286288
}
287289

@@ -362,8 +364,9 @@ appsApi.updateAppPlugins = function(params) {
362364

363365
log.d('Updating plugin config for app %s: %j', params.qstring.app_id, params.qstring.args);
364366

365-
if (!common.validateArgs(params.qstring, props)) {
366-
common.returnMessage(params, 400, 'Not enough args');
367+
var updateAppPluginsValidation = common.validateArgs(params.qstring, props, true);
368+
if (!updateAppPluginsValidation.result) {
369+
common.returnMessage(params, 400, 'Error: ' + updateAppPluginsValidation.errors);
367370
return false;
368371
}
369372

@@ -479,8 +482,9 @@ appsApi.deleteApp = function(params) {
479482
},
480483
appId = '';
481484

482-
if (!(appId = common.validateArgs(params.qstring.args, argProps).app_id)) {
483-
common.returnMessage(params, 400, 'Not enough args');
485+
var deleteAppValidation = common.validateArgs(params.qstring.args, argProps, true);
486+
if (!(deleteAppValidation.obj && (appId = deleteAppValidation.obj.app_id))) {
487+
common.returnMessage(params, 400, 'Error: ' + deleteAppValidation.errors);
484488
return false;
485489
}
486490
common.db.collection('apps').findOne({'_id': common.db.ObjectID(appId)}, function(err, app) {
@@ -550,9 +554,9 @@ appsApi.resetApp = function(params) {
550554
}
551555
},
552556
appId = '';
553-
554-
if (!(appId = common.validateArgs(params.qstring.args, argProps).app_id)) {
555-
common.returnMessage(params, 400, 'Not enough args');
557+
var resetAppValidation = common.validateArgs(params.qstring.args, argProps, true);
558+
if (!(resetAppValidation.obj && (appId = resetAppValidation.obj.app_id))) {
559+
common.returnMessage(params, 400, 'Error: ' + resetAppValidation.errors);
556560
return false;
557561
}
558562
common.db.collection('apps').findOne({'_id': common.db.ObjectID(appId)}, function(err, app) {

api/parts/mgmt/users.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ usersApi.createUser = function(params) {
214214
},
215215
newMember = {};
216216

217-
if (!(newMember = common.validateArgs(params.qstring.args, argProps))) {
218-
common.returnMessage(params, 400, 'Not enough args');
217+
var createUserValidation = common.validateArgs(params.qstring.args, argProps, true);
218+
if (!(newMember = createUserValidation.obj)) {
219+
common.returnMessage(params, 400, 'Error: ' + createUserValidation.errors);
219220
return false;
220221
}
221222

@@ -332,8 +333,9 @@ usersApi.updateUser = function(params) {
332333
updatedMember = {},
333334
passwordNoHash = "";
334335

335-
if (!(updatedMember = common.validateArgs(params.qstring.args, argProps))) {
336-
common.returnMessage(params, 400, 'Not enough args');
336+
var updateUserValidation = common.validateArgs(params.qstring.args, argProps, true);
337+
if (!(updatedMember = updateUserValidation.obj)) {
338+
common.returnMessage(params, 400, 'Error: ' + updateUserValidation.errors);
337339
return false;
338340
}
339341

@@ -435,8 +437,9 @@ usersApi.deleteUser = function(params) {
435437
return false;
436438
}
437439

438-
if (!(userIds = common.validateArgs(params.qstring.args, argProps).user_ids)) {
439-
common.returnMessage(params, 400, 'Not enough args');
440+
var deleteUserValidation = common.validateArgs(params.qstring.args, argProps, true);
441+
if (!(deleteUserValidation.obj && (userIds = deleteUserValidation.obj.user_ids))) {
442+
common.returnMessage(params, 400, 'Error: ' + deleteUserValidation.errors);
440443
return false;
441444
}
442445

api/utils/common.js

+158-28
Original file line numberDiff line numberDiff line change
@@ -677,112 +677,242 @@ common.getISOWeeksInYear = function(year) {
677677
* @param {string} argProperties.has-char - should string property has any latin character in it
678678
* @param {string} argProperties.has-upchar - should string property has any upper cased latin character in it
679679
* @param {string} argProperties.has-special - should string property has any none latin character in it
680-
* @returns {object|false} validated args or false if args do not pass validation
680+
* @param {boolean} returnErrors - return error details as array or only boolean result
681+
* @returns {object} validated args in obj property, or false as result property if args do not pass validation and errors array
681682
*/
682-
common.validateArgs = function(args, argProperties) {
683+
common.validateArgs = function(args, argProperties, returnErrors) {
683684

684-
var returnObj = {};
685+
if (arguments.length === 2) {
686+
returnErrors = false;
687+
}
688+
689+
var returnObj;
690+
691+
if (returnErrors) {
692+
returnObj = {
693+
result: true,
694+
errors: [],
695+
obj: {}
696+
};
697+
}
698+
else {
699+
returnObj = {};
700+
}
685701

686702
if (!args) {
687-
return false;
703+
if (returnErrors) {
704+
returnObj.result = false;
705+
returnObj.errors.push("Missing 'args' parameter");
706+
delete returnObj.obj;
707+
return returnObj;
708+
}
709+
else {
710+
return false;
711+
}
688712
}
689713

690714
for (var arg in argProperties) {
715+
var argState = true;
691716
if (argProperties[arg].required) {
692717
if (args[arg] === void 0) {
693-
return false;
718+
if (returnErrors) {
719+
returnObj.errors.push("Missing " + arg + " argument");
720+
returnObj.result = false;
721+
argState = false;
722+
}
723+
else {
724+
return false;
725+
}
694726
}
695727
}
696-
697728
if (args[arg] !== void 0) {
729+
698730
if (argProperties[arg].type) {
699731
if (argProperties[arg].type === 'Number' || argProperties[arg].type === 'String') {
700732
if (toString.call(args[arg]) !== '[object ' + argProperties[arg].type + ']') {
701-
return false;
733+
if (returnErrors) {
734+
returnObj.errors.push("Invalid type for " + arg);
735+
returnObj.result = false;
736+
argState = false;
737+
}
738+
else {
739+
return false;
740+
}
702741
}
703742
}
704743
else if (argProperties[arg].type === 'URL') {
705744
if (toString.call(args[arg]) !== '[object String]') {
706-
return false;
745+
if (returnErrors) {
746+
returnObj.errors.push("Invalid type for " + arg);
747+
returnObj.result = false;
748+
argState = false;
749+
}
750+
else {
751+
return false;
752+
}
707753
}
708754
else if (args[arg] && !/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!$&'()*+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!$&'()*+,;=]|:|@)|\/|\?)*)?$/i.test(args[arg])) {
709-
return false;
755+
if (returnErrors) {
756+
returnObj.errors.push("Invalid url string " + arg);
757+
returnObj.result = false;
758+
argState = false;
759+
}
760+
else {
761+
return false;
762+
}
710763
}
711764
}
712765
else if (argProperties[arg].type === 'Boolean') {
713766
if (!(args[arg] !== true || args[arg] !== false || toString.call(args[arg]) !== '[object Boolean]')) {
714-
return false;
767+
if (returnErrors) {
768+
returnObj.errors.push("Invalid type for " + arg);
769+
returnObj.result = false;
770+
argState = false;
771+
}
715772
}
716773
}
717774
else if (argProperties[arg].type === 'Array') {
718775
if (!Array.isArray(args[arg])) {
719-
return false;
776+
if (returnErrors) {
777+
returnObj.errors.push("Invalid type for " + arg);
778+
returnObj.result = false;
779+
argState = false;
780+
}
781+
else {
782+
return false;
783+
}
720784
}
721785
}
722786
else if (argProperties[arg].type === 'Object') {
723787
if (toString.call(args[arg]) !== '[object ' + argProperties[arg].type + ']' && !(!argProperties[arg].required && args[arg] === null)) {
724-
return false;
788+
if (returnErrors) {
789+
returnObj.errors.push("Invalid type for " + arg);
790+
returnObj.result = false;
791+
argState = false;
792+
}
793+
else {
794+
return false;
795+
}
725796
}
726797
}
727798
else {
728-
return false;
799+
if (returnErrors) {
800+
returnObj.errors.push("Invalid type declaration for " + arg);
801+
returnObj.result = false;
802+
argState = false;
803+
}
804+
else {
805+
return false;
806+
}
729807
}
730808
}
731809
else {
732810
if (toString.call(args[arg]) !== '[object String]') {
733-
return false;
811+
if (returnErrors) {
812+
returnObj.errors.push(arg + " should be string");
813+
returnObj.result = false;
814+
argState = false;
815+
}
816+
else {
817+
return false;
818+
}
734819
}
735820
}
736821

737-
/*
738-
if (toString.call(args[arg]) === '[object String]') {
739-
args[arg] = args[arg].replace(/([.$])/mg, '');
740-
}
741-
*/
742-
743822
if (argProperties[arg]['max-length']) {
744823
if (args[arg].length > argProperties[arg]['max-length']) {
745-
return false;
824+
if (returnErrors) {
825+
returnObj.errors.push("Length of " + arg + " is greater than max length value");
826+
returnObj.result = false;
827+
argState = false;
828+
}
829+
else {
830+
return false;
831+
}
746832
}
747833
}
748834

749835
if (argProperties[arg]['min-length']) {
750836
if (args[arg].length < argProperties[arg]['min-length']) {
751-
return false;
837+
if (returnErrors) {
838+
returnObj.errors.push("Length of " + arg + " is lower than min length value");
839+
returnObj.result = false;
840+
argState = false;
841+
}
842+
else {
843+
return false;
844+
}
752845
}
753846
}
754847

755848
if (argProperties[arg]['has-number']) {
756849
if (!/\d/.test(args[arg])) {
757-
return false;
850+
if (returnErrors) {
851+
returnObj.errors.push(arg + " should has number");
852+
returnObj.result = false;
853+
argState = false;
854+
}
855+
else {
856+
return false;
857+
}
758858
}
759859
}
760860

761861
if (argProperties[arg]['has-char']) {
762862
if (!/[A-Za-z]/.test(args[arg])) {
763-
return false;
863+
if (returnErrors) {
864+
returnObj.errors.push(arg + " should has char");
865+
returnObj.result = false;
866+
argState = false;
867+
}
868+
else {
869+
return false;
870+
}
764871
}
765872
}
766873

767874
if (argProperties[arg]['has-upchar']) {
768875
if (!/[A-Z]/.test(args[arg])) {
769-
return false;
876+
if (returnErrors) {
877+
returnObj.errors.push(arg + " should has upchar");
878+
returnObj.result = false;
879+
argState = false;
880+
}
881+
else {
882+
return false;
883+
}
770884
}
771885
}
772886

773887
if (argProperties[arg]['has-special']) {
774888
if (!/[^A-Za-z\d]/.test(args[arg])) {
775-
return false;
889+
if (returnErrors) {
890+
returnObj.errors.push(arg + " should has special character");
891+
returnObj.result = false;
892+
argState = false;
893+
}
894+
else {
895+
return false;
896+
}
776897
}
777898
}
778899

779-
if (!argProperties[arg]['exclude-from-ret-obj']) {
900+
if (argState && returnErrors && !argProperties[arg]['exclude-from-ret-obj']) {
901+
returnObj.obj[arg] = args[arg];
902+
}
903+
else if (!returnErrors && !argProperties[arg]['exclude-from-ret-obj']) {
780904
returnObj[arg] = args[arg];
781905
}
782906
}
783907
}
784908

785-
return returnObj;
909+
if (returnErrors && !returnObj.result) {
910+
delete returnObj.obj;
911+
return returnObj;
912+
}
913+
else {
914+
return returnObj;
915+
}
786916
};
787917

788918
/**

bin/countly.install_rhel.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if grep -q -i "release 6" /etc/redhat-release ; then
8787
fi
8888

8989
#install grunt & npm modules
90-
( cd $DIR/.. ; npm install -g grunt-cli --unsafe-perm ; npm install --unsafe-perm )
90+
( cd $DIR/.. ; sudo npm install -g grunt-cli --unsafe-perm ; sudo npm install --unsafe-perm )
9191

9292
#install mongodb
9393
bash $DIR/scripts/mongodb.install.sh

0 commit comments

Comments
 (0)