Skip to content
Snippets Groups Projects
Verified Commit 085ac349 authored by Damien's avatar Damien
Browse files

FEAT #15 test where clause

parent e76a4fe1
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ use Core\Models\ValidatorModel; ...@@ -22,6 +22,7 @@ use Core\Models\ValidatorModel;
use Respect\Validation\Validator; use Respect\Validation\Validator;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use SrcCore\controllers\PreparedClauseController;
class BasketController class BasketController
{ {
...@@ -69,6 +70,10 @@ class BasketController ...@@ -69,6 +70,10 @@ class BasketController
return $response->withStatus(400)->withJson(['errors' => 'Basket already exists']); return $response->withStatus(400)->withJson(['errors' => 'Basket already exists']);
} }
if (!PreparedClauseController::isClauseValid(['clause' => $data['clause'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(400)->withJson(['errors' => 'Clause is not valid']);
}
$data['isVisible'] = empty($data['isSearchBasket']) ? 'Y' : 'N'; $data['isVisible'] = empty($data['isSearchBasket']) ? 'Y' : 'N';
$data['isFolderBasket'] = empty($data['isFolderBasket']) ? 'N' : 'Y'; $data['isFolderBasket'] = empty($data['isFolderBasket']) ? 'N' : 'Y';
$data['flagNotif'] = empty($data['flagNotif']) ? 'N' : 'Y'; $data['flagNotif'] = empty($data['flagNotif']) ? 'N' : 'Y';
...@@ -98,6 +103,10 @@ class BasketController ...@@ -98,6 +103,10 @@ class BasketController
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
} }
if (!PreparedClauseController::isClauseValid(['clause' => $data['clause'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(400)->withJson(['errors' => 'Clause is not valid']);
}
$data['isVisible'] = empty($data['isSearchBasket']) ? 'Y' : 'N'; $data['isVisible'] = empty($data['isSearchBasket']) ? 'Y' : 'N';
$data['isFolderBasket'] = empty($data['isFolderBasket']) ? 'N' : 'Y'; $data['isFolderBasket'] = empty($data['isFolderBasket']) ? 'N' : 'Y';
$data['flagNotif'] = empty($data['flagNotif']) ? 'N' : 'Y'; $data['flagNotif'] = empty($data['flagNotif']) ? 'N' : 'Y';
......
...@@ -18,6 +18,7 @@ namespace SrcCore\controllers; ...@@ -18,6 +18,7 @@ namespace SrcCore\controllers;
use Core\Models\UserModel; use Core\Models\UserModel;
use Core\Models\ValidatorModel; use Core\Models\ValidatorModel;
use Entities\Models\EntityModel; use Entities\Models\EntityModel;
use Resource\models\ResModel;
class PreparedClauseController class PreparedClauseController
{ {
...@@ -207,4 +208,25 @@ class PreparedClauseController ...@@ -207,4 +208,25 @@ class PreparedClauseController
return $clause; return $clause;
} }
public static function isClauseValid(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['clause', 'userId']);
ValidatorModel::stringType($aArgs, ['clause', 'userId']);
$clause = PreparedClauseController::getPreparedClause(['clause' => $aArgs['clause'], 'userId' => $aArgs['userId']]);
$preg = preg_match('#\b(?:abort|alter|copy|create|delete|disgard|drop|execute|grant|insert|load|lock|move|reset|truncate|update)\b#i', $clause);
if ($preg === 1) {
return false;
}
try {
ResModel::getOnView(['select' => [1], 'where' => [$clause]]);
} catch (\Exception $e) {
return false;
}
return true;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment