This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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\FacebookGuzzleHttpClient; |
||
28 | use GuzzleHttp\Message\Request; |
||
29 | use GuzzleHttp\Message\Response; |
||
30 | use GuzzleHttp\Stream\Stream; |
||
31 | use GuzzleHttp\Exception\RequestException; |
||
32 | |||
33 | class FacebookGuzzleHttpClientTest extends AbstractTestHttpClient |
||
34 | { |
||
35 | /** |
||
36 | * @var \GuzzleHttp\Client |
||
37 | */ |
||
38 | protected $guzzleMock; |
||
39 | |||
40 | /** |
||
41 | * @var FacebookGuzzleHttpClient |
||
42 | */ |
||
43 | protected $guzzleClient; |
||
44 | |||
45 | protected function setUp() |
||
46 | { |
||
47 | $this->guzzleMock = m::mock('GuzzleHttp\Client'); |
||
48 | $this->guzzleClient = new FacebookGuzzleHttpClient($this->guzzleMock); |
||
49 | } |
||
50 | |||
51 | public function testCanSendNormalRequest() |
||
52 | { |
||
53 | $request = new Request('GET', 'http://foo.com'); |
||
54 | |||
55 | $body = Stream::factory($this->fakeRawBody); |
||
56 | $response = new Response(200, $this->fakeHeadersAsArray, $body); |
||
57 | |||
58 | $this->guzzleMock |
||
0 ignored issues
–
show
|
|||
59 | ->shouldReceive('createRequest') |
||
60 | ->once() |
||
61 | View Code Duplication | ->with('GET', 'http://foo.com/', m::on(function ($arg) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
62 | |||
63 | // array_diff_assoc() will sometimes trigger error on child-arrays |
||
64 | if (['X-foo' => 'bar'] !== $arg['headers']) { |
||
65 | return false; |
||
66 | } |
||
67 | unset($arg['headers']); |
||
68 | |||
69 | $caInfo = array_diff_assoc($arg, [ |
||
70 | 'body' => 'foo_body', |
||
71 | 'timeout' => 123, |
||
72 | 'connect_timeout' => 10, |
||
73 | ]); |
||
74 | |||
75 | if (count($caInfo) !== 1) { |
||
76 | return false; |
||
77 | } |
||
78 | |||
79 | if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo['verify'])) { |
||
80 | return false; |
||
81 | } |
||
82 | |||
83 | return true; |
||
84 | })) |
||
85 | ->andReturn($request); |
||
86 | $this->guzzleMock |
||
0 ignored issues
–
show
The method
shouldReceive() does not seem to exist on object<GuzzleHttp\Client> .
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. ![]() |
|||
87 | ->shouldReceive('send') |
||
88 | ->once() |
||
89 | ->with($request) |
||
90 | ->andReturn($response); |
||
91 | |||
92 | $response = $this->guzzleClient->send('http://foo.com/', 'GET', 'foo_body', ['X-foo' => 'bar'], 123); |
||
93 | |||
94 | $this->assertInstanceOf('Facebook\Http\GraphRawResponse', $response); |
||
95 | $this->assertEquals($this->fakeRawBody, $response->getBody()); |
||
96 | $this->assertEquals($this->fakeHeadersAsArray, $response->getHeaders()); |
||
97 | $this->assertEquals(200, $response->getHttpResponseCode()); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
102 | */ |
||
103 | public function testThrowsExceptionOnClientError() |
||
104 | { |
||
105 | $request = new Request('GET', 'http://foo.com'); |
||
106 | |||
107 | $this->guzzleMock |
||
0 ignored issues
–
show
The method
shouldReceive() does not seem to exist on object<GuzzleHttp\Client> .
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. ![]() |
|||
108 | ->shouldReceive('createRequest') |
||
109 | ->once() |
||
110 | View Code Duplication | ->with('GET', 'http://foo.com/', m::on(function ($arg) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
111 | |||
112 | // array_diff_assoc() will sometimes trigger error on child-arrays |
||
113 | if ([] !== $arg['headers']) { |
||
114 | return false; |
||
115 | } |
||
116 | unset($arg['headers']); |
||
117 | |||
118 | $caInfo = array_diff_assoc($arg, [ |
||
119 | 'body' => 'foo_body', |
||
120 | 'timeout' => 60, |
||
121 | 'connect_timeout' => 10, |
||
122 | ]); |
||
123 | |||
124 | if (count($caInfo) !== 1) { |
||
125 | return false; |
||
126 | } |
||
127 | |||
128 | if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo['verify'])) { |
||
129 | return false; |
||
130 | } |
||
131 | |||
132 | return true; |
||
133 | })) |
||
134 | ->andReturn($request); |
||
135 | $this->guzzleMock |
||
0 ignored issues
–
show
The method
shouldReceive() does not seem to exist on object<GuzzleHttp\Client> .
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. ![]() |
|||
136 | ->shouldReceive('send') |
||
137 | ->once() |
||
138 | ->with($request) |
||
139 | ->andThrow(new RequestException('Foo', $request)); |
||
140 | |||
141 | $this->guzzleClient->send('http://foo.com/', 'GET', 'foo_body', [], 60); |
||
142 | } |
||
143 | } |
||
144 |
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.