forked from CIDRAM/CIDRAM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.php
More file actions
229 lines (218 loc) · 4.52 KB
/
tests.php
File metadata and controls
229 lines (218 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* This file is a part of the CIDRAM package.
* Homepage: https://cidram.github.io/
*
* CIDRAM COPYRIGHT 2016 and beyond by Caleb Mazalevskis (Maikuolan).
*/
/**
* If this file remains intact after deploying the package to production,
* preventing it from running outside of Composer may be useful as a means of
* prevent potential attackers from hammering the file and needlessly wasting
* cycles at the server.
*/
if (!isset($_SERVER['COMPOSER_BINARY'])) {
die;
}
// Suppress unexpected errors from output and exit early as a failure when encountered.
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
echo 'Error triggered: ' . $errstr . PHP_EOL;
exit(1);
});
// "CIDRAM" constant needed as sanity check for some required files.
define('CIDRAM', true);
// Global variable for all our closures, plus vault path declaration.
$CIDRAM = ['Vault' => __DIR__ . DIRECTORY_SEPARATOR . 'vault' . DIRECTORY_SEPARATOR];
// Fetch CIDRAM configuration.
$CIDRAM_Config = parse_ini_file($CIDRAM['Vault'] . 'config.ini.RenameMe', true);
$CIDRAM_Config['supplementary_cache_options']['enable_apcu'] = true;
// Load each required file or exit immediately if any of them don't exist.
foreach (['functions.php', 'config.php', 'lang.php', 'frontend_functions.php'] as $File) {
if (!is_readable($CIDRAM['Vault'] . $File)) {
echo $File . '.php is not readable.' . PHP_EOL;
exit(2);
}
require $CIDRAM['Vault'] . $File;
}
// Exit immediately if the loader of the configuration file doesn't exist.
if (!is_readable(__DIR__ . DIRECTORY_SEPARATOR . 'loader.php') || !is_readable($CIDRAM['Vault'] . 'config.ini.RenameMe')) {
echo 'Loader or configuration is not readable.' . PHP_EOL;
exit(3);
}
// Test expand IPv4 factors.
$Expected = [
'0.0.0.0/1',
'64.0.0.0/2',
'96.0.0.0/3',
'112.0.0.0/4',
'120.0.0.0/5',
'124.0.0.0/6',
'126.0.0.0/7',
'127.0.0.0/8',
'127.0.0.0/9',
'127.0.0.0/10',
'127.0.0.0/11',
'127.0.0.0/12',
'127.0.0.0/13',
'127.0.0.0/14',
'127.0.0.0/15',
'127.0.0.0/16',
'127.0.0.0/17',
'127.0.0.0/18',
'127.0.0.0/19',
'127.0.0.0/20',
'127.0.0.0/21',
'127.0.0.0/22',
'127.0.0.0/23',
'127.0.0.0/24',
'127.0.0.0/25',
'127.0.0.0/26',
'127.0.0.0/27',
'127.0.0.0/28',
'127.0.0.0/29',
'127.0.0.0/30',
'127.0.0.0/31',
'127.0.0.1/32'
];
if (serialize($Expected) !== serialize($CIDRAM['ExpandIPv4']('127.0.0.1'))) {
echo 'ExpandIPv4 failed.' . PHP_EOL;
exit(4);
}
// Test expand IPv6 factors.
$Expected = [
'0::/1',
'0::/2',
'0::/3',
'0::/4',
'0::/5',
'0::/6',
'0::/7',
'0::/8',
'0::/9',
'0::/10',
'0::/11',
'0::/12',
'0::/13',
'0::/14',
'0::/15',
'0::/16',
'0::/17',
'0::/18',
'0::/19',
'0::/20',
'0::/21',
'0::/22',
'0::/23',
'0::/24',
'0::/25',
'0::/26',
'0::/27',
'0::/28',
'0::/29',
'0::/30',
'0::/31',
'0::/32',
'0::/33',
'0::/34',
'0::/35',
'0::/36',
'0::/37',
'0::/38',
'0::/39',
'0::/40',
'0::/41',
'0::/42',
'0::/43',
'0::/44',
'0::/45',
'0::/46',
'0::/47',
'0::/48',
'0::/49',
'0::/50',
'0::/51',
'0::/52',
'0::/53',
'0::/54',
'0::/55',
'0::/56',
'0::/57',
'0::/58',
'0::/59',
'0::/60',
'0::/61',
'0::/62',
'0::/63',
'0::/64',
'0::/65',
'0::/66',
'0::/67',
'0::/68',
'0::/69',
'0::/70',
'0::/71',
'0::/72',
'0::/73',
'0::/74',
'0::/75',
'0::/76',
'0::/77',
'0::/78',
'0::/79',
'0::/80',
'0::/81',
'0::/82',
'0::/83',
'0::/84',
'0::/85',
'0::/86',
'0::/87',
'0::/88',
'0::/89',
'0::/90',
'0::/91',
'0::/92',
'0::/93',
'0::/94',
'0::/95',
'0::/96',
'0::/97',
'0::/98',
'0::/99',
'0::/100',
'0::/101',
'0::/102',
'0::/103',
'0::/104',
'0::/105',
'0::/106',
'0::/107',
'0::/108',
'0::/109',
'0::/110',
'0::/111',
'0::/112',
'0::/113',
'0::/114',
'0::/115',
'0::/116',
'0::/117',
'0::/118',
'0::/119',
'0::/120',
'0::/121',
'0::/122',
'0::/123',
'0::/124',
'0::/125',
'0::/126',
'0::/127',
'0::1/128'
];
if (serialize($Expected) !== serialize($CIDRAM['ExpandIPv6']('::1'))) {
echo 'ExpandIPv6 failed.' . PHP_EOL;
exit(5);
}
restore_error_handler();
echo 'All tests passed.' . PHP_EOL;
exit(0);