Skip to content

Commit a6ac8e5

Browse files
committed
BadFunctions/EasyRFI: add unit tests
1 parent 0dacd0d commit a6ac8e5

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* Paranoia mode = 0.
5+
*/
6+
7+
// Base.
8+
include ( 'path/to/' . $_GET['filename'] ); // Error.
9+
include_once 'path/to/' . "$filename" . '.' . $extension;
10+
require getenv('PATHTOFILE'); // Error.
11+
12+
// Drupal 7.
13+
require_once ( 'path/to/' . $form['filename'] );
14+
include arg(2) . drupal_get_query_parameters()['param'];
15+
16+
// Prevent false positives on safe $_SERVER variables.
17+
include $_SERVER['DOCUMENT_ROOT'] . '/filename.php';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* Paranoia mode = 1.
5+
*/
6+
7+
// Base.
8+
include ( 'path/to/' . $_GET['filename'] ); // Error.
9+
include 'path/to/' . "$filename" . '.' . $extension; // Warning x 2.
10+
include getenv('PATHTOFILE'); // Error.
11+
12+
// Drupal 7.
13+
include ( 'path/to/' . $form['filename'] ); // Warning.
14+
include arg(2) . drupal_get_query_parameters()['param']; // Warning x 2.
15+
16+
// Prevent false positives on safe $_SERVER variables.
17+
include $_SERVER['DOCUMENT_ROOT'] . '/filename.php'; // Error.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/*
4+
* Paranoia mode = 1, CmsFramework = Drupal7.
5+
*/
6+
7+
// Base.
8+
include ( 'path/to/' . $_GET['filename'] ); // Error.
9+
include 'path/to/' . "$filename" . '.' . $extension; // Warning x 2.
10+
include getenv('PATHTOFILE'); // Error.
11+
12+
// Drupal 7.
13+
include ( 'path/to/' . $form['filename'] ); // Error.
14+
include arg(2) . drupal_get_query_parameters()['param']; // Error x 2.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace PHPCS_SecurityAudit\Security\Tests\BadFunctions;
4+
5+
use PHPCS_SecurityAudit\Security\Tests\AbstractSecurityTestCase;
6+
7+
/**
8+
* Unit test class for the EasyRFI sniff.
9+
*
10+
* @covers \PHPCS_SecurityAudit\Security\Sniffs\BadFunctions\EasyRFISniff
11+
*/
12+
class EasyRFIUnitTest extends AbstractSecurityTestCase
13+
{
14+
15+
/**
16+
* Returns the lines where errors should occur.
17+
*
18+
* The key of the array should represent the line number and the value
19+
* should represent the number of errors that should occur on that line.
20+
*
21+
* @param string $testFile The name of the file being tested.
22+
*
23+
* @return array<int, int>
24+
*/
25+
public function getErrorList($testFile = '')
26+
{
27+
switch ($testFile) {
28+
case 'EasyRFIUnitTest.0.inc':
29+
return [
30+
8 => 1,
31+
10 => 1,
32+
];
33+
34+
case 'EasyRFIUnitTest.1.inc':
35+
return [
36+
8 => 1,
37+
10 => 1,
38+
17 => 1,
39+
];
40+
41+
case 'EasyRFIUnitTest.Drupal7.1.inc':
42+
return [
43+
8 => 1,
44+
10 => 1,
45+
13 => 1,
46+
14 => 2,
47+
];
48+
49+
default:
50+
return [];
51+
}
52+
}
53+
54+
/**
55+
* Returns the lines where warnings should occur.
56+
*
57+
* The key of the array should represent the line number and the value
58+
* should represent the number of warnings that should occur on that line.
59+
*
60+
* @param string $testFile The name of the file being tested.
61+
*
62+
* @return array<int, int>
63+
*/
64+
public function getWarningList($testFile = '')
65+
{
66+
switch ($testFile) {
67+
case 'EasyRFIUnitTest.1.inc':
68+
return [
69+
9 => 2,
70+
13 => 1,
71+
14 => 2,
72+
];
73+
74+
case 'EasyRFIUnitTest.Drupal7.1.inc':
75+
return [
76+
9 => 2,
77+
];
78+
79+
default:
80+
return [];
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)