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.

tests/phpunit/Unit/MultiCurlRequestTest.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 Onoi\HttpRequest\Tests;
4
5
use Onoi\HttpRequest\MultiCurlRequest;
6
use Onoi\HttpRequest\CurlRequest;
7
8
/**
9
 * @covers \Onoi\HttpRequest\MultiCurlRequest
10
 * @group onoi-http-request
11
 *
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class MultiCurlRequestTest extends \PHPUnit_Framework_TestCase {
18
19
	public function testCanConstruct() {
20
21
		$instance = new MultiCurlRequest( curl_multi_init() );
22
23
		$this->assertInstanceOf(
24
			'\Onoi\HttpRequest\HttpRequest',
25
			$instance
26
		);
27
28
		$this->assertInstanceOf(
29
			'\Onoi\HttpRequest\MultiCurlRequest',
30
			$instance
31
		);
32
	}
33
34
	public function testWrongResourceTypeThrowsException() {
35
		$this->setExpectedException( 'InvalidArgumentException' );
36
		new MultiCurlRequest( curl_init() );
37
	}
38
39
	public function testPingForEmptyHttpRequest() {
40
41
		$instance = new MultiCurlRequest( curl_multi_init() );
42
43
		$this->assertFalse(
44
			$instance->ping()
45
		);
46
	}
47
48
	/**
49
	 * @dataProvider pingConnectionStateProvider
50
	 */
51
	public function testPingConnectionState( $connectionState ) {
52
53
		$instance = new MultiCurlRequest( curl_multi_init() );
54
55
		$httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\CurlRequest' )
56
			->disableOriginalConstructor()
57
			->getMock();
58
59
		$httpRequest->expects( $this->once() )
60
			->method( 'ping' )
61
			->will( $this->returnValue( $connectionState ) );
62
63
		$instance->addHttpRequest(
64
			$httpRequest
65
		);
66
67
		$this->assertEquals(
68
			$connectionState,
69
			$instance->ping()
70
		);
71
	}
72
73
	public function testSetGetOption() {
74
75
		// https://github.com/facebook/hhvm/issues/5761
76
		if ( !defined( 'CURLMOPT_MAXCONNECTS' ) ) {
77
			$this->markTestSkipped( "Option is not supported for current PHP version" );
78
		}
79
80
		$instance = new MultiCurlRequest( curl_multi_init() );
81
82
		$instance->setOption(
83
			CURLMOPT_MAXCONNECTS,
84
			5
85
		);
86
87
		$this->assertSame(
88
			5,
89
			$instance->getOption( CURLMOPT_MAXCONNECTS )
90
		);
91
	}
92
93
	public function testExecuteForResponse() {
94
95
		$instance = new MultiCurlRequest( curl_multi_init() );
96
97
		$instance->addHttpRequest(
98
			new CurlRequest( curl_init() )
99
		);
100
101
		$this->assertInternalType(
102
			'array',
103
			$instance->execute()
104
		);
105
106
		$this->assertInternalType(
107
			'string',
108
			$instance->getLastError()
109
		);
110
111
		// http://php.net/manual/en/function.curl-multi-info-read.php
112
		$this->assertFalse(
113
			$instance->getLastTransferInfo()
114
		);
115
	}
116
117
	public function testDeprecatedSetCallback() {
118
119
		$instance = new MultiCurlRequest( curl_multi_init() );
120
121
		$instance->addHttpRequest(
122
			new CurlRequest( curl_init() )
123
		);
124
125
		$requestResponse = null;
126
127
		$instance->setCallback( function( $requestResponseCompleted ) use ( &$requestResponse ) {
0 ignored issues
show
Deprecated Code introduced by
The method Onoi\HttpRequest\MultiCurlRequest::setCallback() has been deprecated with message: since 1.1, use ONOI_HTTP_REQUEST_ON_COMPLETED_CALLBACK instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
128
			$requestResponse = $requestResponseCompleted;
129
		} );
130
131
		$instance->execute();
132
133
		$this->assertRequestResponse( $requestResponse );
134
	}
135
136
	public function testOnCompletedCallback() {
137
138
		$instance = new MultiCurlRequest( curl_multi_init() );
139
140
		$instance->addHttpRequest(
141
			new CurlRequest( curl_init() )
142
		);
143
144
		$requestResponse = null;
145
146
		$instance->setOption( ONOI_HTTP_REQUEST_ON_COMPLETED_CALLBACK, function( $requestResponseCompleted ) use ( &$requestResponse ) {
147
			$requestResponse = $requestResponseCompleted;
148
		} );
149
150
		$instance->execute();
151
152
		$this->assertSame(
153
			0,
154
			$instance->getLastErrorCode()
155
		);
156
157
		$this->assertRequestResponse( $requestResponse );
158
	}
159
160
	private function assertRequestResponse( $requestResponse ) {
161
162
		$this->assertInstanceOf(
163
			'\Onoi\HttpRequest\RequestResponse',
164
			$requestResponse
165
		);
166
167
		$expectedRequestResponseFields = array(
168
			'contents',
169
			'info'
170
		);
171
172
		foreach ( $expectedRequestResponseFields as $field ) {
173
			$this->assertTrue( $requestResponse->has( $field ) );
174
		}
175
	}
176
177
	public function pingConnectionStateProvider() {
178
179
		$provider[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$provider was never initialized. Although not strictly required by PHP, it is generally a good practice to add $provider = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
180
			true
181
		);
182
183
		$provider[] = array(
184
			false
185
		);
186
187
		return $provider;
188
	}
189
190
}
191