Issues (21)

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/phpunit/CodeReviewPhpFileParserTest.php (1 issue)

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
namespace CodeReview\Tests;
3
4
class CodeReviewPhpFileParserTest extends \PHPUnit_Framework_TestCase {
5
6
	public function testNotExistingFile() {
7
		$fileName = '/not/existing/file/path/to/php/file.php';
8
		$this->setExpectedException('\CodeReview\IOException', "File $fileName does not exists");
9
		new \CodeReview\PhpFileParser($fileName);
10
	}
11
12
	public function testNotAFile() {
13
		$fileName = dirname(__FILE__);//just a path to directory
14
		$this->setExpectedException('\CodeReview\IOException', "$fileName must be a file");
15
		new \CodeReview\PhpFileParser($fileName);
16
	}
17
18
	/**
19
	 * @requires PHP 5.3
20
	 */
21
	public function testUnserializeInternalErrorNoFileName() {
22
		$fileName = dirname(__FILE__) . '/test_files/php/input/sample1.php';
23
		$tokens = new \CodeReview\PhpFileParser($fileName);
24
25
		$reflection = new \ReflectionClass($tokens);
26
		$reflection_property = $reflection->getProperty('fileName');
27
		$reflection_property->setAccessible(true);
28
		$reflection_property->setValue($tokens, null);
29
30
		$this->setExpectedException('LogicException', "Missing file's path. Looks like severe internal error.");
31
32
		$serializedTokens = serialize($tokens);
33
		unserialize($serializedTokens);
34
	}
35
36
	/**
37
	 * @requires PHP 5.3
38
	 */
39
	public function testUnserializeInternalErrorBadFileName() {
40
		$fileName = dirname(__FILE__) . '/test_files/php/input/sample1.php';
41
		$badPath = dirname(__FILE__) . '/test_files/php/input/not_existing_file.php';
42
		$tokens = new \CodeReview\PhpFileParser($fileName);
43
44
		$reflection = new \ReflectionClass($tokens);
45
		$reflection_property = $reflection->getProperty('fileName');
46
		$reflection_property->setAccessible(true);
47
		$reflection_property->setValue($tokens, $badPath);
48
49
		$this->setExpectedException('\CodeReview\IOException', "File $badPath does not exists");
50
51
		$serializedTokens = serialize($tokens);
52
		unserialize($serializedTokens);
53
	}
54
55
	/**
56
	 * @requires PHP 5.3
57
	 */
58
	public function testUnserializeInternalErrorNoSha1() {
59
		$fileName = dirname(__FILE__) . '/test_files/php/input/sample1.php';
60
		$tokens = new \CodeReview\PhpFileParser($fileName);
61
62
		$reflection = new \ReflectionClass($tokens);
63
		$reflection_property = $reflection->getProperty('sha1hash');
64
		$reflection_property->setAccessible(true);
65
		$reflection_property->setValue($tokens, null);
66
67
		$this->setExpectedException('LogicException', "Missing file's SHA1 hash. Looks like severe internal error.");
68
69
		$serializedTokens = serialize($tokens);
70
		unserialize($serializedTokens);
71
	}
72
73
	public function testSerializationDataPreserve() {
74
		$tokens = new \CodeReview\PhpFileParser(__FILE__);
75
		$serializedTokens = serialize($tokens);
76
		$unserializedTokens = unserialize($serializedTokens);
77
		$this->assertEquals($tokens, $unserializedTokens);
78
	}
79
80
	/**
81
	 * @return array
82
	 */
83
	private function getTestsPhpFiles() {
84
		$tests = array(
85
			'sample1',
86
			'sample1',
87
		);
88
		$result = array();
89
		$dir = dirname(__FILE__) . '/test_files/php/';
90
		foreach ($tests as $test) {
91
			$result[$test] = array(
92
				$dir . 'input/' . $test . '.php',
93
				$dir . 'output/' . $test . '.php',
94
			);
95
		}
96
		return $result;
97
	}
98
99
	public function testSerializationOutput() {
100
		$tests = $this->getTestsPhpFiles();
101
		foreach ($tests as $test) {
102
			list($inPath, ) = $test;
103
			$tokens = new \CodeReview\PhpFileParser($inPath);
104
105
			$serializedClass = serialize($tokens);
106
			$this->assertTrue(is_string($serializedClass));
107
			$this->assertTrue(strlen($serializedClass) > 0);
108
109
			$actual = unserialize($serializedClass);
110
			$expected = new \CodeReview\PhpFileParser($inPath);
111
112
			$this->assertEquals($expected, $actual);
113
		}
114
	}
115
116
	public function testSourcePreserve() {
117
		$tests = $this->getTestsPhpFiles();
118
		foreach ($tests as $test) {
119
			list($inPath, ) = $test;
120
			$tokens = new \CodeReview\PhpFileParser($inPath);
121
122
			$actual = $tokens->exportPhp();
123
124
			$this->assertTrue(is_string($actual));
125
			$this->assertTrue(strlen($actual) > 0);
126
127
			$expected = file_get_contents($inPath);
128
129
			$this->assertEquals($expected, $actual);
130
		}
131
	}
132
133
	public function testArrayAndIteratorInterfaces() {
134
		$tests = $this->getTestsPhpFiles();
135
		foreach ($tests as $test) {
136
			list($inPath, ) = $test;
137
138
			$tokens = new \CodeReview\PhpFileParser($inPath);
139
140
			//testing repeated iteration and isset
141
			foreach (array(1,2) as $i) {
142
				$result = array();
143
				foreach ($tokens as $key => $token) {
144
					$result[] = array(isset($tokens[$key - 1]), isset($tokens[$key]), isset($tokens[$key + 1]));
145
				}
146
147
				$this->assertTrue(count($result) > 2);
148
				$first = array_shift($result);
149
				$this->assertEquals(array(false, true, true), $first);
150
				$last = array_pop($result);
151
				$this->assertEquals(array(true, true, false), $last);
152
153
				foreach ($result as $row) {
154
					$this->assertEquals(array(true, true, true), $row);
155
				}
156
			}
157
158
		}
159
	}
160
161
	public function testSerializationFileModifiedDetection() {
162
		$tests = $this->getTestsPhpFiles();
163
		foreach ($tests as $test) {
164
			list($inPath, ) = $test;
165
166
			$content = file_get_contents($inPath);
167
			$this->assertNotEmpty($content);
168
169
			$tmpPath = tempnam(sys_get_temp_dir(), 'phpfileparsertest');
170
171
			$this->assertNotEquals(file_put_contents($tmpPath, $content), false);
172
173
			$tokens = new \CodeReview\PhpFileParser($tmpPath);
174
			$serializedTokens = serialize($tokens);
175
176
			//modify file
177
			$this->assertNotEquals(file_put_contents($tmpPath, 'modified' . $content), false);
178
179
//			$this->setExpectedException('\CodeReview\IOException');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
180
			try {
181
				//this shall fail
182
				unserialize($serializedTokens);
183
			} catch (\CodeReview\IOException $e) {
184
				$this->assertEquals("The file on disk has changed and this CodeReview\\PhpFileParser class instance is no longer valid for use. Please create fresh instance.", $e->getMessage());
185
				continue;
186
			}
187
			$this->fail('Expected \CodeReview\IOException to be thrown!');
188
		}
189
	}
190
}