Issues (175)

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/HttpClients/FacebookCurlHttpClientTest.php (26 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
 * Copyright 2016 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
namespace Facebook\Tests\HttpClients;
25
26
use Mockery as m;
27
use Facebook\HttpClients\FacebookCurlHttpClient;
28
29
class FacebookCurlHttpClientTest extends AbstractTestHttpClient
30
{
31
    /**
32
     * @var \Facebook\HttpClients\FacebookCurl
33
     */
34
    protected $curlMock;
35
36
    /**
37
     * @var FacebookCurlHttpClient
38
     */
39
    protected $curlClient;
40
41
    const CURL_VERSION_STABLE = 0x072400;
42
    const CURL_VERSION_BUGGY = 0x071400;
43
44
    protected function setUp()
45
    {
46
        if (!extension_loaded('curl')) {
47
            $this->markTestSkipped('cURL must be installed to test cURL client handler.');
48
        }
49
        $this->curlMock = m::mock('Facebook\HttpClients\FacebookCurl');
50
        $this->curlClient = new FacebookCurlHttpClient($this->curlMock);
51
    }
52
53 View Code Duplication
    public function testCanOpenGetCurlConnection()
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...
54
    {
55
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
            ->shouldReceive('init')
57
            ->once()
58
            ->andReturn(null);
59
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
            ->shouldReceive('setoptArray')
61
            ->with(m::on(function ($arg) {
62
63
                // array_diff() will sometimes trigger error on child-arrays
64
                if (['X-Foo-Header: X-Bar'] !== $arg[CURLOPT_HTTPHEADER]) {
65
                    return false;
66
                }
67
                unset($arg[CURLOPT_HTTPHEADER]);
68
69
                $caInfo = array_diff($arg, [
70
                    CURLOPT_CUSTOMREQUEST => 'GET',
71
                    CURLOPT_URL => 'http://foo.com',
72
                    CURLOPT_CONNECTTIMEOUT => 10,
73
                    CURLOPT_TIMEOUT => 123,
74
                    CURLOPT_RETURNTRANSFER => true,
75
                    CURLOPT_HEADER => true,
76
                    CURLOPT_SSL_VERIFYHOST => 2,
77
                    CURLOPT_SSL_VERIFYPEER => true,
78
                ]);
79
80
                if (count($caInfo) !== 1) {
81
                    return false;
82
                }
83
84
                if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo[CURLOPT_CAINFO])) {
85
                    return false;
86
                }
87
88
                return true;
89
            }))
90
            ->once()
91
            ->andReturn(null);
92
93
        $this->curlClient->openConnection('http://foo.com', 'GET', 'foo_body', ['X-Foo-Header' => 'X-Bar'], 123);
94
    }
95
96 View Code Duplication
    public function testCanOpenCurlConnectionWithPostBody()
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...
97
    {
98
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
            ->shouldReceive('init')
100
            ->once()
101
            ->andReturn(null);
102
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
            ->shouldReceive('setoptArray')
104
            ->with(m::on(function ($arg) {
105
106
                // array_diff() will sometimes trigger error on child-arrays
107
                if ([] !== $arg[CURLOPT_HTTPHEADER]) {
108
                    return false;
109
                }
110
                unset($arg[CURLOPT_HTTPHEADER]);
111
112
                $caInfo = array_diff($arg, [
113
                    CURLOPT_CUSTOMREQUEST => 'POST',
114
                    CURLOPT_URL => 'http://bar.com',
115
                    CURLOPT_CONNECTTIMEOUT => 10,
116
                    CURLOPT_TIMEOUT => 60,
117
                    CURLOPT_RETURNTRANSFER => true,
118
                    CURLOPT_HEADER => true,
119
                    CURLOPT_SSL_VERIFYHOST => 2,
120
                    CURLOPT_SSL_VERIFYPEER => true,
121
                    CURLOPT_POSTFIELDS => 'baz=bar',
122
                ]);
123
124
                if (count($caInfo) !== 1) {
125
                    return false;
126
                }
127
128
                if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo[CURLOPT_CAINFO])) {
129
                    return false;
130
                }
131
132
                return true;
133
            }))
134
            ->once()
135
            ->andReturn(null);
136
137
        $this->curlClient->openConnection('http://bar.com', 'POST', 'baz=bar', [], 60);
138
    }
139
140
    public function testCanCloseConnection()
141
    {
142
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
143
            ->shouldReceive('close')
144
            ->once()
145
            ->andReturn(null);
146
147
        $this->curlClient->closeConnection();
148
    }
149
150
    public function testIsolatesTheHeaderAndBody()
151
    {
152
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
153
            ->shouldReceive('exec')
154
            ->once()
155
            ->andReturn($this->fakeRawHeader . $this->fakeRawBody);
156
157
        $this->curlClient->sendRequest();
158
        list($rawHeader, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
159
160
        $this->assertEquals($rawHeader, trim($this->fakeRawHeader));
161
        $this->assertEquals($rawBody, $this->fakeRawBody);
162
    }
163
164 View Code Duplication
    public function testProperlyHandlesProxyHeaders()
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...
165
    {
166
        $rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader;
167
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
168
            ->shouldReceive('exec')
169
            ->once()
170
            ->andReturn($rawHeader . $this->fakeRawBody);
171
172
        $this->curlClient->sendRequest();
173
        list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
174
175
        $this->assertEquals($rawHeaders, trim($rawHeader));
176
        $this->assertEquals($rawBody, $this->fakeRawBody);
177
    }
178
179 View Code Duplication
    public function testProperlyHandlesProxyHeadersWithCurlBug()
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...
180
    {
181
        $rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader;
182
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
183
            ->shouldReceive('exec')
184
            ->once()
185
            ->andReturn($rawHeader . $this->fakeRawBody);
186
187
        $this->curlClient->sendRequest();
188
        list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
189
190
        $this->assertEquals($rawHeaders, trim($rawHeader));
191
        $this->assertEquals($rawBody, $this->fakeRawBody);
192
    }
193
194 View Code Duplication
    public function testProperlyHandlesProxyHeadersWithCurlBug2()
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...
195
    {
196
        $rawHeader = $this->fakeRawProxyHeader2 . $this->fakeRawHeader;
197
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
198
            ->shouldReceive('exec')
199
            ->once()
200
            ->andReturn($rawHeader . $this->fakeRawBody);
201
202
        $this->curlClient->sendRequest();
203
        list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
204
205
        $this->assertEquals($rawHeaders, trim($rawHeader));
206
        $this->assertEquals($rawBody, $this->fakeRawBody);
207
    }
208
209 View Code Duplication
    public function testProperlyHandlesRedirectHeaders()
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...
210
    {
211
        $rawHeader = $this->fakeRawRedirectHeader . $this->fakeRawHeader;
212
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
213
            ->shouldReceive('exec')
214
            ->once()
215
            ->andReturn($rawHeader . $this->fakeRawBody);
216
217
        $this->curlClient->sendRequest();
218
        list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody();
219
220
        $this->assertEquals($rawHeaders, trim($rawHeader));
221
        $this->assertEquals($rawBody, $this->fakeRawBody);
222
    }
223
224
    public function testCanSendNormalRequest()
225
    {
226
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
227
            ->shouldReceive('init')
228
            ->once()
229
            ->andReturn(null);
230
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
231
            ->shouldReceive('setoptArray')
232
            ->once()
233
            ->andReturn(null);
234
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
235
            ->shouldReceive('exec')
236
            ->once()
237
            ->andReturn($this->fakeRawHeader . $this->fakeRawBody);
238
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
239
            ->shouldReceive('errno')
240
            ->once()
241
            ->andReturn(null);
242
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
243
            ->shouldReceive('close')
244
            ->once()
245
            ->andReturn(null);
246
247
        $response = $this->curlClient->send('http://foo.com/', 'GET', '', [], 60);
248
249
        $this->assertInstanceOf('Facebook\Http\GraphRawResponse', $response);
250
        $this->assertEquals($this->fakeRawBody, $response->getBody());
251
        $this->assertEquals($this->fakeHeadersAsArray, $response->getHeaders());
252
        $this->assertEquals(200, $response->getHttpResponseCode());
253
    }
254
255
    /**
256
     * @expectedException \Facebook\Exceptions\FacebookSDKException
257
     */
258
    public function testThrowsExceptionOnClientError()
259
    {
260
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
261
            ->shouldReceive('init')
262
            ->once()
263
            ->andReturn(null);
264
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
265
            ->shouldReceive('setoptArray')
266
            ->once()
267
            ->andReturn(null);
268
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
269
            ->shouldReceive('exec')
270
            ->once()
271
            ->andReturn(false);
272
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
273
            ->shouldReceive('errno')
274
            ->once()
275
            ->andReturn(123);
276
        $this->curlMock
0 ignored issues
show
The method shouldReceive() does not seem to exist on object<Facebook\HttpClients\FacebookCurl>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
277
            ->shouldReceive('error')
278
            ->once()
279
            ->andReturn('Foo error');
280
281
        $this->curlClient->send('http://foo.com/', 'GET', '', [], 60);
282
    }
283
}
284