|
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
|
|
|
use Bouncer\Resource\Identity; |
|
15
|
|
|
|
|
16
|
|
|
class IdentityTest extends \PHPUnit_Framework_TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
public function getRequest() |
|
20
|
|
|
{ |
|
21
|
|
|
$ip = '92.78.176.182'; |
|
22
|
|
|
$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'; |
|
23
|
|
|
|
|
24
|
|
|
$server = array(); |
|
25
|
|
|
$server['REMOTE_ADDR'] = $ip; |
|
26
|
|
|
$server['HTTP_USER_AGENT'] = $ua; |
|
27
|
|
|
$server['HTTP_HOST'] = 'bouncer.h6e.net'; |
|
28
|
|
|
$server['REQUEST_URI'] = '/test'; |
|
29
|
|
|
$server['SERVER_PROTOCOL'] = 'HTTP/1.1'; |
|
30
|
|
|
$server['HTTP_ACCEPT'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'; |
|
31
|
|
|
$server['HTTP_ACCEPT_LANGUAGE'] = 'en-US,en;q=0.8'; |
|
32
|
|
|
$server['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate, sdch'; |
|
33
|
|
|
|
|
34
|
|
|
$request = new \Bouncer\Request; |
|
35
|
|
|
$request->initialize(array(), array(), array(), array(), array(), $server); |
|
36
|
|
|
|
|
37
|
|
|
return $request; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getBouncer($request) |
|
41
|
|
|
{ |
|
42
|
|
|
$bouncer = new Bouncer(array( |
|
43
|
|
|
'request' => $request, |
|
44
|
|
|
)); |
|
45
|
|
|
|
|
46
|
|
|
return $bouncer; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testGetIdentity() |
|
50
|
|
|
{ |
|
51
|
|
|
$request = $this->getRequest(); |
|
52
|
|
|
|
|
53
|
|
|
$bouncer = $this->getBouncer($request); |
|
54
|
|
|
|
|
55
|
|
|
$identity = $bouncer->getIdentity(); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals('688926c9994666d5d5d4cf7e2429aabd', $identity->getId()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testGetIdentityAddress() |
|
61
|
|
|
{ |
|
62
|
|
|
$request = $this->getRequest(); |
|
63
|
|
|
|
|
64
|
|
|
$bouncer = $this->getBouncer($request); |
|
65
|
|
|
|
|
66
|
|
|
$identity = $bouncer->getIdentity(); |
|
67
|
|
|
|
|
68
|
|
|
$address = $identity->getAddress(); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertEquals('e90d9f20cce9c203f439129b0943a8bb', $address->getId()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
public function testGetIdentitySignature() |
|
75
|
|
|
{ |
|
76
|
|
|
$request = $this->getRequest(); |
|
77
|
|
|
|
|
78
|
|
|
$bouncer = $this->getBouncer($request); |
|
79
|
|
|
|
|
80
|
|
|
$identity = $bouncer->getIdentity(); |
|
81
|
|
|
|
|
82
|
|
|
$signature = $identity->getSignature(); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertEquals('5a8433a81c1290cc5399eb60f26172d4', $signature->getId()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testIdentityStatus() |
|
88
|
|
|
{ |
|
89
|
|
|
$identity = new Identity(array( |
|
90
|
|
|
'reputation' => array( |
|
91
|
|
|
'threats' => array(), |
|
92
|
|
|
'status' => 'bad', |
|
93
|
|
|
) |
|
94
|
|
|
)); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertEquals('bad', $identity->getStatus()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|