File tree Expand file tree Collapse file tree 5 files changed +119
-0
lines changed
Security/Tests/BadFunctions Expand file tree Collapse file tree 5 files changed +119
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ output = `$ form ['field']`; // Error (user input).
4+ $ output = `$ request ['field']`; // Warning.
5+ `$ _GET `; // Error (user input).
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ output = `$ form ['field']`; // Error (user input).
4+ $ output = `$ request ['field']`; // Error (user input).
5+ `$ _GET `; // Error (user input).
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ output = `$ form ['field']`; // Warning.
4+ $ output = `$ request ['field']`; // Error (user input).
5+ `$ _GET `; // Error (user input).
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // Not using variable input.
4+ $ output = `ls -al `;
5+
6+ // These should all give an error/warning.
7+ $ output = `$ form ['field']`; // Warning.
8+ $ output = `$ request ['field']`; // Warning.
9+ `$ _GET `; // Error (user input).
10+
11+ $ output = `git blame --date=short " $ filename" `; // Warning.
12+
13+ // Incomplete command. Ignore.
14+ // Intentional parse error. This should be the last test in the file.
15+ $ output = `ls
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Unit test class for the Backticks sniff.
4+ */
5+
6+ namespace PHPCS_SecurityAudit \Security \Tests \BadFunctions ;
7+
8+ use PHPCS_SecurityAudit \Security \Tests \AbstractSecurityTestCase ;
9+
10+ class BackticksUnitTest extends AbstractSecurityTestCase
11+ {
12+
13+ /**
14+ * Returns the lines where errors should occur.
15+ *
16+ * The key of the array should represent the line number and the value
17+ * should represent the number of errors that should occur on that line.
18+ *
19+ * @param string $testFile The name of the file being tested.
20+ *
21+ * @return array<int, int>
22+ */
23+ public function getErrorList ($ testFile = '' )
24+ {
25+ switch ($ testFile ) {
26+ case 'BackticksUnitTest.inc ' :
27+ return [
28+ 9 => 1 ,
29+ ];
30+
31+ case 'BackticksUnitTest.Drupal7.inc ' :
32+ return [
33+ 3 => 1 ,
34+ 5 => 1 ,
35+ ];
36+
37+ case 'BackticksUnitTest.Drupal8.inc ' :
38+ return [
39+ 3 => 1 ,
40+ 4 => 1 ,
41+ 5 => 1 ,
42+ ];
43+
44+ case 'BackticksUnitTest.Symfony2.inc ' :
45+ return [
46+ 4 => 1 ,
47+ 5 => 1 ,
48+ ];
49+
50+ default :
51+ return [];
52+ }
53+ }
54+
55+ /**
56+ * Returns the lines where warnings should occur.
57+ *
58+ * The key of the array should represent the line number and the value
59+ * should represent the number of warnings that should occur on that line.
60+ *
61+ * @param string $testFile The name of the file being tested.
62+ *
63+ * @return array<int, int>
64+ */
65+ public function getWarningList ($ testFile = '' )
66+ {
67+ switch ($ testFile ) {
68+ case 'BackticksUnitTest.inc ' :
69+ return [
70+ 7 => 1 ,
71+ 8 => 1 ,
72+ 11 => 1 ,
73+ ];
74+
75+ case 'BackticksUnitTest.Drupal7.inc ' :
76+ return [
77+ 4 => 1 ,
78+ ];
79+
80+ case 'BackticksUnitTest.Symfony2.inc ' :
81+ return [
82+ 3 => 1 ,
83+ ];
84+
85+ default :
86+ return [];
87+ }
88+ }
89+ }
You can’t perform that action at this time.
0 commit comments