From 98f34ddd4288a1615e1fb13bcadc5fbb6255e4e6 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 21 Dec 2022 05:13:55 -0500 Subject: [PATCH] Added DB_FILTER --- UnitTestFiles/Test/SQL_Injection_Test.php | 30 ++++++++++++++++++----- src/mockup/inputs/app/home_in.php | 4 ++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/UnitTestFiles/Test/SQL_Injection_Test.php b/UnitTestFiles/Test/SQL_Injection_Test.php index ffbf3a3..d716635 100644 --- a/UnitTestFiles/Test/SQL_Injection_Test.php +++ b/UnitTestFiles/Test/SQL_Injection_Test.php @@ -10,17 +10,25 @@ class SQL_Injection_Test extends TestCase { /** * @dataProvider dataProviderForTest */ - public function testException($a) { - $this->expectException(\Exception::class); - \tts\safer_sql::get_safer_sql_text($a); + public function testDangerious($a) { + $ret = \tts\safer_sql::get_safer_sql_text($a); + $this->assertTrue($ret['status'] == \tts\SQL_SAFETY_FLAG::dangerious); + } + + /** + * @dataProvider filterDataProviderForTest + */ + public function testSQLFiltering($a, $b) { + $ret = \tts\safer_sql::get_safer_sql_text($a); + $this->assertEquals($ret["text"], $b); } /** * @dataProvider safeDataProviderForTest */ public function testSafeSQL($a) { - $this->expectNotToPerformAssertions(); - \tts\safer_sql::get_safer_sql_text($a); + $ret = \tts\safer_sql::get_safer_sql_text($a); + $this->assertTrue($ret['status'] == \tts\SQL_SAFETY_FLAG::good); } public function dataProviderForTest() { @@ -32,11 +40,21 @@ class SQL_Injection_Test extends TestCase { ]; } + public function filterDataProviderForTest() { + return [ + ["/etc/password Hello", "etcpassword Hello"], + ["--; Bob", " Bob"], + ["&& Safe", " Safe"], + ["Hello /var/log/apache", "Hello varlogapache"] + ]; + } + public function safeDataProviderForTest() { return [ ["John walks (down the road)."], ["Hey, Boy - Good Work!"], - ["I think; I'm good!"] + ["I think; I'm good!"], + ["Go dancing by the river or play ball and see it."] ]; } diff --git a/src/mockup/inputs/app/home_in.php b/src/mockup/inputs/app/home_in.php index 8147bfa..e602eeb 100644 --- a/src/mockup/inputs/app/home_in.php +++ b/src/mockup/inputs/app/home_in.php @@ -8,6 +8,7 @@ use \tts\safer_io as SafeIO; use \tts\INPUTS; use \tts\FIELD_FILTER; use \tts\HTML_FLAG; +use \tts\DB_FILTER; class home_in { @@ -18,8 +19,9 @@ class home_in { 'input' => INPUTS::post, // Others: post, json (REQUIRED param) 'field' => FIELD_FILTER::raw_string, // Others: raw, (DEFAULT: string), email, url, float, int 'html' => HTML_FLAG::purify, // Others: strip, encode, purify, (DEFAULT: escape) - 'rule' => 'required|max: 75' // Others: email, valid_email_domain, + 'rule' => 'required|max: 75', // Others: email, valid_email_domain, // min, max, between, same, secure (password), alphanumeric + 'db' => DB_FILTER::OFF // Should be used on Login Data only ], 'last_name' => [