Skip to content

Commit 269ea47

Browse files
committed
Add tests to ensure that injections fail #56
1 parent 7147214 commit 269ea47

3 files changed

Lines changed: 27 additions & 20 deletions

File tree

phpunit.xml.dist

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.2/phpunit.xsd"
4-
bootstrap="vendor/autoload.php"
5-
backupGlobals="false"
6-
verbose="true">
7-
<testsuites>
8-
<testsuite name="MySQL">
9-
<directory suffix="Test.php">tests</directory>
10-
</testsuite>
11-
12-
<testsuite name="MongoDB">
13-
<directory suffix="MongoDB.php">tests/mongodb</directory>
14-
</testsuite>
15-
</testsuites>
16-
17-
<filter>
18-
<whitelist processUncoveredFilesFromWhitelist="true">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" verbose="true">
3+
<coverage processUncoveredFiles="true">
4+
<include>
195
<directory suffix=".php">src</directory>
20-
</whitelist>
21-
</filter>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="MySQL">
10+
<directory suffix="Test.php">tests</directory>
11+
</testsuite>
12+
<testsuite name="MongoDB">
13+
<directory suffix="MongoDB.php">tests/mongodb</directory>
14+
</testsuite>
15+
</testsuites>
2216
</phpunit>
23-

tests/CommonQueryBuilderTests.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class CommonQueryBuilderTests extends TestCase
1313
{
1414
protected $simpleQuery = '{"condition":"AND","rules":[{"id":"price","field":"price","type":"double","operator":"less","value":"10.25"}]}';
15+
protected $simpleQueryInjection = '{"condition":"ALSO","rules":[{"id":"price","field":"price","type":"double","operator":"less","value":"10.25"},{"id":"price","field":"price","type":"double","operator":"greater","value":"9.25"}]}';
1516
protected $json1 = '{
1617
"condition":"AND",
1718
"rules":[

tests/QueryBuilderParserTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ public function testSimpleQuery()
2525
$this->assertEquals('select * where `price` < ?', $builder->toSql());
2626
}
2727

28+
public function testSimpleQueryNoInjection()
29+
{
30+
$builder = $this->createQueryBuilder();
31+
$qb = $this->getParserUnderTest();
32+
33+
$this->expectException('timgws\QBParseException');
34+
$this->expectExceptionMessage("Condition can only be one of");
35+
36+
$test = $qb->parse($this->simpleQueryInjection, $builder);
37+
38+
$this->assertEquals('select * where `price` < ?', $builder->toSql());
39+
}
40+
2841
public function testMoreComplexQuery()
2942
{
3043
$builder = $this->createQueryBuilder();

0 commit comments

Comments
 (0)