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\Authentication\AccessToken; |
27
|
|
|
|
28
|
|
|
class AccessTokenTest extends \PHPUnit_Framework_TestCase |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
public function testAnAccessTokenCanBeReturnedAsAString() |
32
|
|
|
{ |
33
|
|
|
$accessToken = new AccessToken('foo_token'); |
34
|
|
|
|
35
|
|
|
$this->assertEquals('foo_token', $accessToken->getValue()); |
36
|
|
|
$this->assertEquals('foo_token', (string)$accessToken); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testAnAppSecretProofWillBeProperlyGenerated() |
40
|
|
|
{ |
41
|
|
|
$accessToken = new AccessToken('foo_token'); |
42
|
|
|
|
43
|
|
|
$appSecretProof = $accessToken->getAppSecretProof('shhhhh!is.my.secret'); |
44
|
|
|
|
45
|
|
|
$this->assertEquals('796ba0d8a6b339e476a7b166a9e8ac0a395f7de736dc37de5f2f4397f5854eb8', $appSecretProof); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testAnAppAccessTokenCanBeDetected() |
49
|
|
|
{ |
50
|
|
|
$normalToken = new AccessToken('foo_token'); |
51
|
|
|
$isNormalToken = $normalToken->isAppAccessToken(); |
52
|
|
|
|
53
|
|
|
$this->assertFalse($isNormalToken, 'Normal access token not expected to look like an app access token.'); |
54
|
|
|
|
55
|
|
|
$appToken = new AccessToken('123|secret'); |
56
|
|
|
$isAppToken = $appToken->isAppAccessToken(); |
57
|
|
|
|
58
|
|
|
$this->assertTrue($isAppToken, 'App access token expected to look like an app access token.'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testShortLivedAccessTokensCanBeDetected() |
62
|
|
|
{ |
63
|
|
|
$anHourAndAHalf = time() + (1.5 * 60); |
64
|
|
|
$accessToken = new AccessToken('foo_token', $anHourAndAHalf); |
65
|
|
|
|
66
|
|
|
$isLongLived = $accessToken->isLongLived(); |
67
|
|
|
|
68
|
|
|
$this->assertFalse($isLongLived, 'Expected access token to be short lived.'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testLongLivedAccessTokensCanBeDetected() |
72
|
|
|
{ |
73
|
|
|
$accessToken = new AccessToken('foo_token', $this->aWeekFromNow()); |
74
|
|
|
|
75
|
|
|
$isLongLived = $accessToken->isLongLived(); |
76
|
|
|
|
77
|
|
|
$this->assertTrue($isLongLived, 'Expected access token to be long lived.'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testAnAppAccessTokenDoesNotExpire() |
81
|
|
|
{ |
82
|
|
|
$appToken = new AccessToken('123|secret'); |
83
|
|
|
$hasExpired = $appToken->isExpired(); |
84
|
|
|
|
85
|
|
|
$this->assertFalse($hasExpired, 'App access token not expected to expire.'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testAnAccessTokenCanExpire() |
89
|
|
|
{ |
90
|
|
|
$expireTime = time() - 100; |
91
|
|
|
$appToken = new AccessToken('foo_token', $expireTime); |
92
|
|
|
$hasExpired = $appToken->isExpired(); |
93
|
|
|
|
94
|
|
|
$this->assertTrue($hasExpired, 'Expected 100 second old access token to be expired.'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testAccessTokenCanBeSerialized() |
98
|
|
|
{ |
99
|
|
|
$accessToken = new AccessToken('foo', time(), 'bar'); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$newAccessToken = unserialize(serialize($accessToken)); |
102
|
|
|
|
103
|
|
|
$this->assertEquals((string)$accessToken, (string)$newAccessToken); |
104
|
|
|
$this->assertEquals($accessToken->getExpiresAt(), $newAccessToken->getExpiresAt()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
private function aWeekFromNow() |
108
|
|
|
{ |
109
|
|
|
return time() + (60 * 60 * 24 * 7);//a week from now |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.