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; |
||
25 | |||
26 | use Facebook\Facebook; |
||
27 | use Facebook\FacebookApp; |
||
28 | use Facebook\FacebookRequest; |
||
29 | use Facebook\FileUpload\FacebookFile; |
||
30 | use Facebook\FileUpload\FacebookVideo; |
||
31 | |||
32 | class FacebookRequestTest extends \PHPUnit_Framework_TestCase |
||
33 | { |
||
34 | public function testAnEmptyRequestEntityCanInstantiate() |
||
35 | { |
||
36 | $app = new FacebookApp('123', 'foo_secret'); |
||
37 | $request = new FacebookRequest($app); |
||
38 | |||
39 | $this->assertInstanceOf('Facebook\FacebookRequest', $request); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
44 | */ |
||
45 | public function testAMissingAccessTokenWillThrow() |
||
46 | { |
||
47 | $app = new FacebookApp('123', 'foo_secret'); |
||
48 | $request = new FacebookRequest($app); |
||
49 | |||
50 | $request->validateAccessToken(); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
55 | */ |
||
56 | public function testAMissingMethodWillThrow() |
||
57 | { |
||
58 | $app = new FacebookApp('123', 'foo_secret'); |
||
59 | $request = new FacebookRequest($app); |
||
60 | |||
61 | $request->validateMethod(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
66 | */ |
||
67 | public function testAnInvalidMethodWillThrow() |
||
68 | { |
||
69 | $app = new FacebookApp('123', 'foo_secret'); |
||
70 | $request = new FacebookRequest($app, 'foo_token', 'FOO'); |
||
71 | |||
72 | $request->validateMethod(); |
||
73 | } |
||
74 | |||
75 | public function testGetHeadersWillAutoAppendETag() |
||
76 | { |
||
77 | $app = new FacebookApp('123', 'foo_secret'); |
||
78 | $request = new FacebookRequest($app, null, 'GET', '/foo', [], 'fooETag'); |
||
79 | |||
80 | $headers = $request->getHeaders(); |
||
81 | |||
82 | $expectedHeaders = FacebookRequest::getDefaultHeaders(); |
||
83 | $expectedHeaders['If-None-Match'] = 'fooETag'; |
||
84 | |||
85 | $this->assertEquals($expectedHeaders, $headers); |
||
86 | } |
||
87 | |||
88 | public function testGetParamsWillAutoAppendAccessTokenAndAppSecretProof() |
||
89 | { |
||
90 | $app = new FacebookApp('123', 'foo_secret'); |
||
91 | $request = new FacebookRequest($app, 'foo_token', 'POST', '/foo', ['foo' => 'bar']); |
||
92 | |||
93 | $params = $request->getParams(); |
||
94 | |||
95 | $this->assertEquals([ |
||
96 | 'foo' => 'bar', |
||
97 | 'access_token' => 'foo_token', |
||
98 | 'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
||
99 | ], $params); |
||
100 | } |
||
101 | |||
102 | public function testAnAccessTokenCanBeSetFromTheParams() |
||
103 | { |
||
104 | $app = new FacebookApp('123', 'foo_secret'); |
||
105 | $request = new FacebookRequest($app, null, 'POST', '/me', ['access_token' => 'bar_token']); |
||
106 | |||
107 | $accessToken = $request->getAccessToken(); |
||
108 | |||
109 | $this->assertEquals('bar_token', $accessToken); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @expectedException \Facebook\Exceptions\FacebookSDKException |
||
114 | */ |
||
115 | public function testAccessTokenConflictsWillThrow() |
||
116 | { |
||
117 | $app = new FacebookApp('123', 'foo_secret'); |
||
118 | new FacebookRequest($app, 'foo_token', 'POST', '/me', ['access_token' => 'bar_token']); |
||
119 | } |
||
120 | |||
121 | public function testAProperUrlWillBeGenerated() |
||
122 | { |
||
123 | $app = new FacebookApp('123', 'foo_secret'); |
||
124 | $getRequest = new FacebookRequest($app, 'foo_token', 'GET', '/foo', ['foo' => 'bar']); |
||
125 | |||
126 | $getUrl = $getRequest->getUrl(); |
||
127 | $expectedParams = 'foo=bar&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9'; |
||
128 | $expectedUrl = '/' . Facebook::DEFAULT_GRAPH_VERSION . '/foo?' . $expectedParams; |
||
129 | |||
130 | $this->assertEquals($expectedUrl, $getUrl); |
||
131 | |||
132 | $postRequest = new FacebookRequest($app, 'foo_token', 'POST', '/bar', ['foo' => 'bar']); |
||
133 | |||
134 | $postUrl = $postRequest->getUrl(); |
||
135 | $expectedUrl = '/' . Facebook::DEFAULT_GRAPH_VERSION . '/bar'; |
||
136 | |||
137 | $this->assertEquals($expectedUrl, $postUrl); |
||
138 | } |
||
139 | |||
140 | public function testAuthenticationParamsAreStrippedAndReapplied() |
||
141 | { |
||
142 | $app = new FacebookApp('123', 'foo_secret'); |
||
143 | |||
144 | $request = new FacebookRequest( |
||
145 | $app, |
||
146 | $accessToken = 'foo_token', |
||
147 | $method = 'GET', |
||
148 | $endpoint = '/foo', |
||
149 | $params = [ |
||
150 | 'access_token' => 'foo_token', |
||
151 | 'appsecret_proof' => 'bar_app_secret', |
||
152 | 'bar' => 'baz', |
||
153 | ] |
||
154 | ); |
||
155 | |||
156 | $url = $request->getUrl(); |
||
157 | |||
158 | $expectedParams = 'bar=baz&access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9'; |
||
159 | $expectedUrl = '/' . Facebook::DEFAULT_GRAPH_VERSION . '/foo?' . $expectedParams; |
||
160 | $this->assertEquals($expectedUrl, $url); |
||
161 | |||
162 | $params = $request->getParams(); |
||
163 | |||
164 | $expectedParams = [ |
||
165 | 'access_token' => 'foo_token', |
||
166 | 'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', |
||
167 | 'bar' => 'baz', |
||
168 | ]; |
||
169 | $this->assertEquals($expectedParams, $params); |
||
170 | } |
||
171 | |||
172 | View Code Duplication | public function testAFileCanBeAddedToParams() |
|
0 ignored issues
–
show
|
|||
173 | { |
||
174 | $myFile = new FacebookFile(__DIR__ . '/foo.txt'); |
||
175 | $params = [ |
||
176 | 'name' => 'Foo Bar', |
||
177 | 'source' => $myFile, |
||
178 | ]; |
||
179 | $app = new FacebookApp('123', 'foo_secret'); |
||
180 | $request = new FacebookRequest($app, 'foo_token', 'POST', '/foo/photos', $params); |
||
181 | |||
182 | $actualParams = $request->getParams(); |
||
183 | |||
184 | $this->assertTrue($request->containsFileUploads()); |
||
185 | $this->assertFalse($request->containsVideoUploads()); |
||
186 | $this->assertTrue(!isset($actualParams['source'])); |
||
187 | $this->assertEquals('Foo Bar', $actualParams['name']); |
||
188 | } |
||
189 | |||
190 | View Code Duplication | public function testAVideoCanBeAddedToParams() |
|
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. ![]() |
|||
191 | { |
||
192 | $myFile = new FacebookVideo(__DIR__ . '/foo.txt'); |
||
193 | $params = [ |
||
194 | 'name' => 'Foo Bar', |
||
195 | 'source' => $myFile, |
||
196 | ]; |
||
197 | $app = new FacebookApp('123', 'foo_secret'); |
||
198 | $request = new FacebookRequest($app, 'foo_token', 'POST', '/foo/videos', $params); |
||
199 | |||
200 | $actualParams = $request->getParams(); |
||
201 | |||
202 | $this->assertTrue($request->containsFileUploads()); |
||
203 | $this->assertTrue($request->containsVideoUploads()); |
||
204 | $this->assertTrue(!isset($actualParams['source'])); |
||
205 | $this->assertEquals('Foo Bar', $actualParams['name']); |
||
206 | } |
||
207 | } |
||
208 |
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.