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\Authentication; |
||
25 | |||
26 | use Facebook\Facebook; |
||
27 | use Facebook\FacebookApp; |
||
28 | use Facebook\Authentication\OAuth2Client; |
||
29 | |||
30 | class OAuth2ClientTest extends \PHPUnit_Framework_TestCase |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * @const The foo Graph version |
||
35 | */ |
||
36 | const TESTING_GRAPH_VERSION = 'v1337'; |
||
37 | |||
38 | /** |
||
39 | * @var FooFacebookClientForOAuth2Test |
||
40 | */ |
||
41 | protected $client; |
||
42 | |||
43 | /** |
||
44 | * @var OAuth2Client |
||
45 | */ |
||
46 | protected $oauth; |
||
47 | |||
48 | protected function setUp() |
||
49 | { |
||
50 | $app = new FacebookApp('123', 'foo_secret'); |
||
51 | $this->client = new FooFacebookClientForOAuth2Test(); |
||
52 | $this->oauth = new OAuth2Client($app, $this->client, static::TESTING_GRAPH_VERSION); |
||
53 | } |
||
54 | |||
55 | public function testCanGetMetadataFromAnAccessToken() |
||
56 | { |
||
57 | $this->client->setMetadataResponse(); |
||
58 | |||
59 | $metadata = $this->oauth->debugToken('baz_token'); |
||
60 | |||
61 | $this->assertInstanceOf('Facebook\Authentication\AccessTokenMetadata', $metadata); |
||
62 | $this->assertEquals('444', $metadata->getUserId()); |
||
63 | |||
64 | $expectedParams = [ |
||
65 | 'input_token' => 'baz_token', |
||
66 | 'access_token' => '123|foo_secret', |
||
67 | 'appsecret_proof' => 'de753c58fd58b03afca2340bbaeb4ecf987b5de4c09e39a63c944dd25efbc234', |
||
68 | ]; |
||
69 | |||
70 | $request = $this->oauth->getLastRequest(); |
||
71 | $this->assertEquals('GET', $request->getMethod()); |
||
72 | $this->assertEquals('/debug_token', $request->getEndpoint()); |
||
73 | $this->assertEquals($expectedParams, $request->getParams()); |
||
74 | $this->assertEquals(static::TESTING_GRAPH_VERSION, $request->getGraphVersion()); |
||
75 | } |
||
76 | |||
77 | public function testCanBuildAuthorizationUrl() |
||
78 | { |
||
79 | $scope = ['email', 'base_foo']; |
||
80 | $authUrl = $this->oauth->getAuthorizationUrl('https://foo.bar', 'foo_state', $scope, ['foo' => 'bar'], '*'); |
||
81 | |||
82 | $this->assertContains('*', $authUrl); |
||
83 | |||
84 | $expectedUrl = 'https://www.facebook.com/' . static::TESTING_GRAPH_VERSION . '/dialog/oauth?'; |
||
85 | $this->assertTrue(strpos($authUrl, $expectedUrl) === 0, 'Unexpected base authorization URL returned from getAuthorizationUrl().'); |
||
86 | |||
87 | $params = [ |
||
88 | 'client_id' => '123', |
||
89 | 'redirect_uri' => 'https://foo.bar', |
||
90 | 'state' => 'foo_state', |
||
91 | 'sdk' => 'php-sdk-' . Facebook::VERSION, |
||
92 | 'scope' => implode(',', $scope), |
||
93 | 'foo' => 'bar', |
||
94 | ]; |
||
95 | foreach ($params as $key => $value) { |
||
96 | $this->assertContains($key . '=' . urlencode($value), $authUrl); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | public function testCanGetAccessTokenFromCode() |
||
101 | { |
||
102 | $this->client->setAccessTokenResponse(); |
||
103 | |||
104 | $accessToken = $this->oauth->getAccessTokenFromCode('bar_code', 'foo_uri'); |
||
105 | |||
106 | $this->assertInstanceOf('Facebook\Authentication\AccessToken', $accessToken); |
||
107 | $this->assertEquals('my_access_token', $accessToken->getValue()); |
||
108 | |||
109 | $expectedParams = [ |
||
110 | 'code' => 'bar_code', |
||
111 | 'redirect_uri' => 'foo_uri', |
||
112 | 'client_id' => '123', |
||
113 | 'client_secret' => 'foo_secret', |
||
114 | 'access_token' => '123|foo_secret', |
||
115 | 'appsecret_proof' => 'de753c58fd58b03afca2340bbaeb4ecf987b5de4c09e39a63c944dd25efbc234', |
||
116 | ]; |
||
117 | |||
118 | $request = $this->oauth->getLastRequest(); |
||
119 | $this->assertEquals('GET', $request->getMethod()); |
||
120 | $this->assertEquals('/oauth/access_token', $request->getEndpoint()); |
||
121 | $this->assertEquals($expectedParams, $request->getParams()); |
||
122 | $this->assertEquals(static::TESTING_GRAPH_VERSION, $request->getGraphVersion()); |
||
123 | } |
||
124 | |||
125 | View Code Duplication | public function testCanGetLongLivedAccessToken() |
|
0 ignored issues
–
show
|
|||
126 | { |
||
127 | $this->client->setAccessTokenResponse(); |
||
128 | |||
129 | $accessToken = $this->oauth->getLongLivedAccessToken('short_token'); |
||
130 | |||
131 | $this->assertEquals('my_access_token', $accessToken->getValue()); |
||
132 | |||
133 | $expectedParams = [ |
||
134 | 'grant_type' => 'fb_exchange_token', |
||
135 | 'fb_exchange_token' => 'short_token', |
||
136 | 'client_id' => '123', |
||
137 | 'client_secret' => 'foo_secret', |
||
138 | 'access_token' => '123|foo_secret', |
||
139 | 'appsecret_proof' => 'de753c58fd58b03afca2340bbaeb4ecf987b5de4c09e39a63c944dd25efbc234', |
||
140 | ]; |
||
141 | |||
142 | $request = $this->oauth->getLastRequest(); |
||
143 | $this->assertEquals($expectedParams, $request->getParams()); |
||
144 | } |
||
145 | |||
146 | View Code Duplication | public function testCanGetCodeFromLongLivedAccessToken() |
|
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. ![]() |
|||
147 | { |
||
148 | $this->client->setCodeResponse(); |
||
149 | |||
150 | $code = $this->oauth->getCodeFromLongLivedAccessToken('long_token', 'foo_uri'); |
||
151 | |||
152 | $this->assertEquals('my_neat_code', $code); |
||
153 | |||
154 | $expectedParams = [ |
||
155 | 'access_token' => 'long_token', |
||
156 | 'redirect_uri' => 'foo_uri', |
||
157 | 'client_id' => '123', |
||
158 | 'client_secret' => 'foo_secret', |
||
159 | 'appsecret_proof' => '7e91300ea91be4166282611d4fc700b473466f3ea2981dafbf492fc096995bf1', |
||
160 | ]; |
||
161 | |||
162 | $request = $this->oauth->getLastRequest(); |
||
163 | $this->assertEquals($expectedParams, $request->getParams()); |
||
164 | $this->assertEquals('/oauth/client_code', $request->getEndpoint()); |
||
165 | } |
||
166 | } |
||
167 |
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.