1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Bouncer package. |
5
|
|
|
* |
6
|
|
|
* (c) François Hodierne <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bouncer; |
13
|
|
|
|
14
|
|
|
class IdentityTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
public function getRequest() |
18
|
|
|
{ |
19
|
|
|
$ip = '92.78.176.182'; |
20
|
|
|
$ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36'; |
21
|
|
|
|
22
|
|
|
$server = array(); |
23
|
|
|
$server['REMOTE_ADDR'] = $ip; |
24
|
|
|
$server['HTTP_USER_AGENT'] = $ua; |
25
|
|
|
$server['HTTP_HOST'] = 'bouncer.h6e.net'; |
26
|
|
|
$server['REQUEST_URI'] = '/test'; |
27
|
|
|
$server['SERVER_PROTOCOL'] = 'HTTP/1.1'; |
28
|
|
|
$server['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'; |
29
|
|
|
$server['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.8'; |
30
|
|
|
$server['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, sdch'; |
31
|
|
|
|
32
|
|
|
$request = new \Bouncer\Request; |
33
|
|
|
$request->initialize(array(), array(), array(), array(), array(), $server); |
34
|
|
|
|
35
|
|
|
return $request; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getBouncer($request) |
39
|
|
|
{ |
40
|
|
|
$memcache = new \Memcache(); |
41
|
|
|
$memcache->addServer('localhost'); |
42
|
|
|
|
43
|
|
|
$bouncer = new Bouncer(array( |
44
|
|
|
'request' => $request, |
45
|
|
|
'cache' => new \Bouncer\Cache\Memcache(array( |
46
|
|
|
'client' => $memcache |
47
|
|
|
)), |
48
|
|
|
'profile' => new \Bouncer\Profile\AccessWatch(array( |
49
|
|
|
'apiKey' => '9b89020149ff37e69fbec4634ae57b46' |
50
|
|
|
)) |
51
|
|
|
)); |
52
|
|
|
|
53
|
|
|
return $bouncer; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetIdentity() |
57
|
|
|
{ |
58
|
|
|
$request = $this->getRequest(); |
59
|
|
|
|
60
|
|
|
$bouncer = $this->getBouncer($request); |
61
|
|
|
|
62
|
|
|
$identity = $bouncer->getIdentity(); |
63
|
|
|
|
64
|
|
|
$this->assertEquals('688926c9994666d5d5d4cf7e2429aabd', $identity->getId()); |
65
|
|
|
// $this->assertEquals('e90d9f20cce9c203f439129b0943a8bb', $identity->getAddress()->getId()); |
66
|
|
|
$this->assertEquals('5a8433a81c1290cc5399eb60f26172d4', $identity->getSignature()->getId()); |
67
|
|
|
// $this->assertEquals('b516786e573a426eb842ec2132ed35e2', $identity->getUserAgent()->getId()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testGetIdentityAddress() |
71
|
|
|
{ |
72
|
|
|
$request = $this->getRequest(); |
73
|
|
|
|
74
|
|
|
$bouncer = $this->getBouncer($request); |
75
|
|
|
|
76
|
|
|
$identity = $bouncer->getIdentity(); |
77
|
|
|
|
78
|
|
|
$address = $identity->getAddress(); |
79
|
|
|
|
80
|
|
|
$this->assertEquals('e90d9f20cce9c203f439129b0943a8bb', $address->getId()); |
81
|
|
|
$this->assertEquals('DE', $address->getCountryCode()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testGetIdentityUserAgent() |
85
|
|
|
{ |
86
|
|
|
$request = $this->getRequest(); |
87
|
|
|
|
88
|
|
|
$bouncer = $this->getBouncer($request); |
89
|
|
|
|
90
|
|
|
$identity = $bouncer->getIdentity(); |
91
|
|
|
|
92
|
|
|
$userAgent = $identity->getUserAgent(); |
93
|
|
|
|
94
|
|
|
$this->assertEquals('b516786e573a426eb842ec2132ed35e2', $userAgent->getId()); |
95
|
|
|
$this->assertEquals('browser', $userAgent->getType()); |
96
|
|
|
$this->assertEquals('chrome', $userAgent->getAgent()->getName()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|