Issues (18)

Security Analysis    not enabled

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.

phpunit/Integration/RequestToPhpHttpdTest.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
3
namespace Onoi\HttpRequest\Tests\Integration;
4
5
use Onoi\HttpRequest\HttpRequestFactory;
6
use Onoi\Cache\CacheFactory;
7
use RuntimeException;
8
9
/**
10
 * @group onoi-http-request
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class RequestToPhpHttpdTest extends \PHPUnit_Framework_TestCase {
18
19
	private static $pid;
20
21
	/**
22
	 * @note Using the PHP in-build webserver to serve a slow/fast page response for
23
	 * validation of the async response
24
	 *
25
	 * Options defined in phpunit.xml.dist
26
	 * @see https://github.com/vgno/tech.vg.no-1812/blob/master/features/bootstrap/FeatureContext.php
27
	 */
28
	public static function setUpBeforeClass() {
29
30
		$command = sprintf( 'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!',
31
			WEB_SERVER_HOST,
32
			WEB_SERVER_PORT,
33
			WEB_SERVER_DOCROOT
34
		);
35
36
		$output = array();
37
		exec( $command, $output );
38
39
		self::$pid = (int) $output[0];
40
	}
41
42
	public static function tearDownAfterClass() {
43
	//	exec( 'kill ' . (int) self::$pid );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
44
	}
45
46
	public function testQueuedResponse() {
47
48
		$this->connectToHttpd();
49
		$expectedToCount = 5;
50
51
		$httpRequestFactory = new HttpRequestFactory();
52
		$multiCurlRequest = $httpRequestFactory->newMultiCurlRequest();
53
54
		for ( $i = 0; $i < $expectedToCount; $i++ ) {
55
			$multiCurlRequest->addHttpRequest(
56
				$httpRequestFactory->newCurlRequest( $this->getHttpdRequestUrl( $i ) )
57
			);
58
		}
59
60
		$this->assertCount(
61
			$expectedToCount,
62
			$multiCurlRequest->execute()
63
		);
64
	}
65
66
	public function testCachedMultiCurlQueuedResponse() {
67
68
		$this->connectToHttpd();
69
		$expectedToCount = 5;
70
71
		$cacheFactory = new CacheFactory();
72
73
		$httpRequestFactory = new HttpRequestFactory(
74
			$cacheFactory->newFixedInMemoryLruCache()
75
		);
76
77
		$multiCurlRequest = $httpRequestFactory->newMultiCurlRequest();
78
79
		for ( $i = 0; $i < $expectedToCount; $i++ ) {
80
			$multiCurlRequest->addHttpRequest(
81
				$httpRequestFactory->newCachedCurlRequest( $this->getHttpdRequestUrl( $i ) )
82
			);
83
		}
84
85
		$this->assertCount(
86
			$expectedToCount,
87
			$multiCurlRequest->execute()
88
		);
89
	}
90
91
	public function testMultiCurlForCallbackResponse() {
92
93
		$this->connectToHttpd();
94
		$expectedToCount = 5;
95
96
		$asyncCallbackResponseMock = $this->getMockBuilder( '\stdClass' )
97
			->setMethods( array( 'run' ) )
98
			->getMock();
99
100
		$asyncCallbackResponseMock->expects( $this->exactly( $expectedToCount ) )
101
			->method( 'run' );
102
103
		$httpRequestFactory = new HttpRequestFactory();
104
		$multiCurlRequest = $httpRequestFactory->newMultiCurlRequest();
105
106
		$multiCurlRequest->setOption( ONOI_HTTP_REQUEST_ON_COMPLETED_CALLBACK, function( $requestResponse ) use ( $asyncCallbackResponseMock ) {
107
			$asyncCallbackResponseMock->run( $requestResponse );
108
		} );
109
110
		for ( $i = 0; $i < $expectedToCount; $i++ ) {
111
			$multiCurlRequest->addHttpRequest(
112
				$httpRequestFactory->newCurlRequest( $this->getHttpdRequestUrl( $i ) )
113
			);
114
		}
115
116
		$multiCurlRequest->execute();
117
	}
118
119
	public function testSocketResponse() {
120
121
		$this->connectToHttpd();
122
		$expectedToCount = 1;
123
124
		$asyncCallbackResponseMock = $this->getMockBuilder( '\stdClass' )
125
			->setMethods( array( 'run' ) )
126
			->getMock();
127
128
		$asyncCallbackResponseMock->expects( $this->exactly( $expectedToCount ) )
129
			->method( 'run' );
130
131
		$httpRequestFactory = new HttpRequestFactory();
132
		$socketRequest = $httpRequestFactory->newSocketRequest();
133
134
		$socketRequest->setOption( ONOI_HTTP_REQUEST_CONNECTION_TIMEOUT, 5 );
135
		$socketRequest->setOption( ONOI_HTTP_REQUEST_CONNECTION_FAILURE_REPEAT, 2 );
136
137
		$socketRequest->setOption( ONOI_HTTP_REQUEST_METHOD, 'GET' );
138
		$socketRequest->setOption( ONOI_HTTP_REQUEST_URL, WEB_SERVER_HOST . ':' .  WEB_SERVER_PORT . '/plain.php' );
139
140
		$socketRequest->ping();
141
142
		$socketRequest->setOption( ONOI_HTTP_REQUEST_ON_FAILED_CALLBACK, function( $requestResponse ) use ( $asyncCallbackResponseMock ) {
143
			$asyncCallbackResponseMock->run( $requestResponse );
144
		} );
145
146
		$socketRequest->execute();
147
	}
148
149
	private function getHttpdRequestUrl( $id ) {
150
151
		// slow/fast example used from https://gist.github.com/Xeoncross/2362936
152
153
		if ( $id % 2 ) {
154
			return WEB_SERVER_HOST . ':' .  WEB_SERVER_PORT . '/slow.php?id=' . $id;
155
		}
156
157
		return WEB_SERVER_HOST . ':' .  WEB_SERVER_PORT . '/fast.php?id=' . $id;
158
	}
159
160
	private function connectToHttpd() {
161
162
		$start = microtime(true);
163
164
		// Try to connect
165
		while ( microtime( true ) - $start <= 10 ) {
166
			if ( $this->canConnectToHttpd() ) {
167
				break;
168
			}
169
		}
170
	}
171
172
	private function canConnectToHttpd() {
173
174
		$sp = @fsockopen( WEB_SERVER_HOST, WEB_SERVER_PORT );
175
176
		if ( $sp === false ) {
177
			return false;
178
		}
179
180
		fclose( $sp );
181
182
		return true;
183
	}
184
185
}
186