Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/ScannerTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace KamranAhmed\Smasher;
4
5
use RecursiveDirectoryIterator;
6
use RecursiveIteratorIterator;
7
use ReflectionClass;
8
9
/**
10
 * Class ScannerTest
11
 *
12
 * Tests the Scanner class
13
 *
14
 * @package KamranAhmed\Smasher
15
 */
16
class ScannerTest extends \PHPUnit_Framework_TestCase
17
{
18
    private $sampleDirPath;
19
    private $invalidDirPath;
20
    private $outputJsonPath;
21
    private $basePathToPopulate;
22
23
    private $populatedDir;
24
    private $populatedFile;
25
26
    private $invalidScanSample;
27
    private $emptyScanSample;
28
    private $sampleJson;
29
30
    /**
31
     * Setup the class for testing
32
     */
33
    public function setUp()
34
    {
35
        $currentDir = __DIR__;
36
37
        $this->sampleDirPath      = $currentDir . '/data/sample-path';
38
        $this->invalidDirPath     = $currentDir . '/invalid/path/that/does/not/exist';
39
        $this->outputJsonPath     = $currentDir . '/data/output/sample-path.json';
40
        $this->basePathToPopulate = $currentDir . '/data/output/';
41
42
        $this->populatedDir  = $currentDir . '/data/output/sample-path';
43
        $this->populatedFile = $currentDir . '/data/output/sample-path/child-item/grand-child/child-file.md';
44
45
        $this->invalidScanSample = $currentDir . '/data/scanned-samples/invalid-scan.md';
46
        $this->emptyScanSample   = $currentDir . '/data/scanned-samples/empty-scan.json';
47
        $this->sampleJson        = $currentDir . '/data/scanned-samples/scanned-json.json';
48
    }
49
50
    public function testCanScanPathAndGetResult()
51
    {
52
        $scanner    = new Scanner(new JsonResponse());
53
        $scanResult = $scanner->scan($this->sampleDirPath);
54
55
        $this->assertTrue($this->isValidJson($scanResult));
56
    }
57
58
    private function isValidJson($json)
59
    {
60
        json_decode($json);
61
62
        return json_last_error() === JSON_ERROR_NONE;
63
    }
64
65
    public function testCanScanPathAndCreateValidResponseFile()
66
    {
67
        $scanner = new Scanner(new JsonResponse());
68
        $scanner->scan($this->sampleDirPath, $this->outputJsonPath);
69
70
        $this->assertTrue(file_exists($this->outputJsonPath));
71
72
        $result = file_get_contents($this->outputJsonPath);
73
        $this->assertTrue($this->isValidJson($result));
74
    }
75
76
    public function testCanPopulatePathUsingInputFile()
77
    {
78
        $scanner = new Scanner(new JsonResponse());
79
        $scanner->populate($this->basePathToPopulate, $this->sampleJson);
80
81
        $this->assertFileExists($this->populatedFile);
82
    }
83
84
    /**
85
     * @expectedException \KamranAhmed\Smasher\Exceptions\UnreadablePathException
86
     */
87
    public function testThrowsExceptionTryingToScanInvalidPath()
88
    {
89
        $scanner = new Scanner(new JsonResponse());
90
        $scanner->scan($this->invalidDirPath);
91
    }
92
93 View Code Duplication
    public function testCanProbePathAndGenerateArrayOfContent()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $scanner = new Scanner(new JsonResponse());
96
        $output  = [];
97
98
        $this->callProtectedMethod($scanner, 'probe', [
99
            $this->sampleDirPath,
100
            &$output,
101
        ]);
102
103
        // Verifying that a valid array is returned by checking
104
        // Orchestrate a better way to verify this array.
105
        $this->assertTrue(isset($output['sample-path']['child-item']['grand-child']['child-file.md']));
106
    }
107
108
    public static function callProtectedMethod($object, $method, array $args = [])
109
    {
110
        $class  = new ReflectionClass(get_class($object));
111
        $method = $class->getMethod($method);
112
        $method->setAccessible(true);
113
114
        return $method->invokeArgs($object, $args);
115
    }
116
117
    /**
118
     * @expectedException \KamranAhmed\Smasher\Exceptions\InvalidContentException
119
     */
120
    public function testGettingContentThrowsExceptionForInvalidFile()
121
    {
122
        $scanner = new Scanner(new JsonResponse());
123
        $this->callProtectedMethod($scanner, 'getScannedContent', [
124
            $this->invalidScanSample,
125
        ]);
126
    }
127
128
    /**
129
     * @expectedException \KamranAhmed\Smasher\Exceptions\NoContentException
130
     */
131
    public function testGettingContentThrowsExceptionForEmptyFile()
132
    {
133
        $scanner = new Scanner(new JsonResponse());
134
        $this->callProtectedMethod($scanner, 'getScannedContent', [
135
            $this->emptyScanSample,
136
        ]);
137
    }
138
139 View Code Duplication
    public function testCanGetScannedContentFromJsonFile()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        $scanner = new Scanner(new JsonResponse());
142
        $scannedArray = $this->callProtectedMethod($scanner, 'getScannedContent', [
143
            $this->sampleJson,
144
        ]);
145
146
        // Verifying that a valid array is returned by checking
147
        // Orchestrate a better way to verify this array.
148
        $this->assertTrue(isset($scannedArray['sample-path']['child-item']['grand-child']['child-file.md']));
149
    }
150
151
    /**
152
     * Remove unnecessary files/directories
153
     */
154
    protected function tearDown()
155
    {
156
        if (file_exists($this->populatedDir)) {
157
            $this->removeDirectory($this->populatedDir);
158
        }
159
160
        if (file_exists($this->outputJsonPath)) {
161
            unlink($this->outputJsonPath);
162
        }
163
    }
164
165
    private function removeDirectory($directory)
166
    {
167
        $iterator = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
168
        $files    = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST);
169
170
        foreach ($files as $file) {
171
            if ($file->isDir()) {
172
                rmdir($file->getRealPath());
173
            } else {
174
                unlink($file->getRealPath());
175
            }
176
        }
177
178
        rmdir($directory);
179
    }
180
}
181