From 040bd939b267f170c71239193d4d3ab489b5a4ca Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Fri, 9 Sep 2011 16:29:09 +0200 Subject: [PATCH] MDL-29033 add tests for the sql injection hack --- lib/simpletest/testdmllib.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/simpletest/testdmllib.php b/lib/simpletest/testdmllib.php index 9934e88adfc..dde13a8dac2 100644 --- a/lib/simpletest/testdmllib.php +++ b/lib/simpletest/testdmllib.php @@ -356,6 +356,23 @@ class dmllib_test extends prefix_changing_test_case { } + + function test_magic_hack() { + // test hacky sql injection protection - the resulting DB data is not really important, + // we only want to prevent SQL injections/DB errors + + $obj = new stdClass(); + $obj->textfield = 'lala\''; + $obj->id = insert_record($this->table, $obj); + $this->assertFalse(empty($obj->id)); + + $obj->textfield = 'lala\\'; + $res = update_record($this->table, $obj); + $this->assertTrue($res); + + $obj = get_record($this->table, 'textfield', 'lala\\'); + $this->assertFalse(empty($obj)); + } } ?>