|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once 'include/utils/security_utils.php'; |
|
4
|
|
|
class security_utilsTest extends PHPUnit_Framework_TestCase |
|
5
|
|
|
{ |
|
6
|
|
|
public function testquery_module_access_list() |
|
7
|
|
|
{ |
|
8
|
|
|
|
|
9
|
|
|
//execute the method and test it it returns expected contents |
|
10
|
|
|
|
|
11
|
|
|
$user = new User('1'); |
|
12
|
|
|
$expected = array( |
|
13
|
|
|
'Home' => 'Home', |
|
14
|
|
|
'Accounts' => 'Accounts', |
|
15
|
|
|
'Contacts' => 'Contacts', |
|
16
|
|
|
'Opportunities' => 'Opportunities', |
|
17
|
|
|
'Leads' => 'Leads', |
|
18
|
|
|
'AOS_Quotes' => 'AOS_Quotes', |
|
19
|
|
|
'Calendar' => 'Calendar', |
|
20
|
|
|
'Documents' => 'Documents', |
|
21
|
|
|
'Emails' => 'Emails', |
|
22
|
|
|
'Campaigns' => 'Campaigns', |
|
23
|
|
|
'Calls' => 'Calls', |
|
24
|
|
|
'Meetings' => 'Meetings', |
|
25
|
|
|
'Tasks' => 'Tasks', |
|
26
|
|
|
'Notes' => 'Notes', |
|
27
|
|
|
'AOS_Invoices' => 'AOS_Invoices', |
|
28
|
|
|
'AOS_Contracts' => 'AOS_Contracts', |
|
29
|
|
|
'Cases' => 'Cases', |
|
30
|
|
|
'Prospects' => 'Prospects', |
|
31
|
|
|
'ProspectLists' => 'ProspectLists', |
|
32
|
|
|
'Project' => 'Project', |
|
33
|
|
|
'AM_ProjectTemplates' => 'AM_ProjectTemplates', |
|
34
|
|
|
'FP_events' => 'FP_events', |
|
35
|
|
|
'FP_Event_Locations' => 'FP_Event_Locations', |
|
36
|
|
|
'AOS_Products' => 'AOS_Products', |
|
37
|
|
|
'AOS_Product_Categories' => 'AOS_Product_Categories', |
|
38
|
|
|
'AOS_PDF_Templates' => 'AOS_PDF_Templates', |
|
39
|
|
|
'jjwg_Maps' => 'jjwg_Maps', |
|
40
|
|
|
'jjwg_Markers' => 'jjwg_Markers', |
|
41
|
|
|
'jjwg_Areas' => 'jjwg_Areas', |
|
42
|
|
|
'jjwg_Address_Cache' => 'jjwg_Address_Cache', |
|
43
|
|
|
'AOR_Reports' => 'AOR_Reports', |
|
44
|
|
|
'AOW_WorkFlow' => 'AOW_WorkFlow', |
|
45
|
|
|
'AOK_KnowledgeBase' => 'AOK_KnowledgeBase', |
|
46
|
|
|
'AOK_Knowledge_Base_Categories' => 'AOK_Knowledge_Base_Categories', |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$actual = query_module_access_list($user); |
|
50
|
|
|
$this->assertSame($expected, $actual); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testquery_user_has_roles() |
|
54
|
|
|
{ |
|
55
|
|
|
error_reporting(E_ERROR | E_PARSE); |
|
56
|
|
|
|
|
57
|
|
|
//execute the method and test it it returns expected contents |
|
58
|
|
|
|
|
59
|
|
|
$expected = '0'; |
|
60
|
|
|
$actual = query_user_has_roles('1'); |
|
61
|
|
|
$this->assertSame($expected, $actual); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testget_user_allowed_modules() |
|
65
|
|
|
{ |
|
66
|
|
|
//execute the method and test it it returns expected contents |
|
67
|
|
|
|
|
68
|
|
|
$expected = array(); |
|
69
|
|
|
$actual = get_user_allowed_modules('1'); |
|
70
|
|
|
$this->assertSame($expected, $actual); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testget_user_disallowed_modules() |
|
74
|
|
|
{ |
|
75
|
|
|
//execute the method and test it it returns expected contents |
|
76
|
|
|
|
|
77
|
|
|
$expected = array( |
|
78
|
|
|
'Bugs' => 'Bugs', |
|
79
|
|
|
'Reminders' => 'Reminders', |
|
80
|
|
|
'Reminders_Invitees' => 'Reminders_Invitees', |
|
81
|
|
|
'AOR_Scheduled_Reports' => 'AOR_Scheduled_Reports', |
|
82
|
|
|
'SecurityGroups' => 'SecurityGroups', |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$allowed = query_module_access_list(new User('1')); |
|
86
|
|
|
$actual = get_user_disallowed_modules('1', $allowed); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertSame($expected, $actual); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testquery_client_ip() |
|
92
|
|
|
{ |
|
93
|
|
|
//test without setting any server parameters |
|
94
|
|
|
$this->assertSame(null, query_client_ip()); |
|
95
|
|
|
|
|
96
|
|
|
//test with server params set |
|
97
|
|
|
$_SERVER['REMOTE_ADDR'] = '1.1.1.3'; |
|
98
|
|
|
$this->assertSame('1.1.1.3', query_client_ip()); |
|
99
|
|
|
|
|
100
|
|
|
$_SERVER['HTTP_FROM'] = '1.1.1.2'; |
|
101
|
|
|
$this->assertSame('1.1.1.2', query_client_ip()); |
|
102
|
|
|
|
|
103
|
|
|
$_SERVER['HTTP_CLIENT_IP'] = '1.1.1.1'; |
|
104
|
|
|
$this->assertSame('1.1.1.1', query_client_ip()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function testget_val_array() |
|
108
|
|
|
{ |
|
109
|
|
|
//execute the method and test it it returns expected contents |
|
110
|
|
|
$tempArray = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'); |
|
111
|
|
|
$expected = array('key1' => 'key1', 'key2' => 'key2', 'key3' => 'key3'); |
|
112
|
|
|
$actual = get_val_array($tempArray); |
|
113
|
|
|
$this->assertSame($expected, $actual); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|