Use conditionals in sync_functions instead of section blocks
[hiphop-php.git] / hphp / test / ext / test_cpp_base.cpp
blobe8860e9f1932ee80e1ddeec41788b74818818d28
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/test/ext/test_cpp_base.h"
18 #include "hphp/runtime/ext/extension.h"
19 #include "hphp/util/logger.h"
20 #include "hphp/runtime/base/memory-manager.h"
21 #include "hphp/runtime/base/builtin-functions.h"
22 #include "hphp/runtime/ext/apc/ext_apc.h"
23 #include "hphp/runtime/ext/string/ext_string.h"
24 #include "hphp/runtime/ext/std/ext_std_variable.h"
25 #include "hphp/runtime/base/runtime-option.h"
26 #include "hphp/runtime/server/ip-block-map.h"
27 #include "hphp/runtime/server/virtual-host.h"
28 #include "hphp/runtime/server/satellite-server.h"
29 #include "hphp/system/systemlib.h"
31 using namespace HPHP;
33 ///////////////////////////////////////////////////////////////////////////////
35 TestCppBase::TestCppBase() {
38 ///////////////////////////////////////////////////////////////////////////////
40 bool TestCppBase::RunTests(const std::string &which) {
41 bool ret = true;
42 RUN_TEST(TestIpBlockMap);
43 RUN_TEST(TestIpBlockMapIni);
44 RUN_TEST(TestVirtualHost);
45 RUN_TEST(TestVirtualHostIni);
46 RUN_TEST(TestCollectionHdf);
47 RUN_TEST(TestCollectionIni);
48 return ret;
51 ///////////////////////////////////////////////////////////////////////////////
52 // building blocks
54 /* Pull 32bit Big Endian words from an in6_addr */
55 static inline long in6addrWord(struct in6_addr addr, char wordNo) {
56 return ((addr.s6_addr[(wordNo*4)+0] << 24) |
57 (addr.s6_addr[(wordNo*4)+1] << 16) |
58 (addr.s6_addr[(wordNo*4)+2] << 8) |
59 (addr.s6_addr[(wordNo*4)+3] << 0)) & 0xFFFFFFFF;
62 bool TestCppBase::TestIpBlockMap() {
63 struct in6_addr addr;
64 int bits;
66 VERIFY(HPHP::IpBlockMap::ReadIPv6Address("204.15.21.0/22", &addr, bits));
67 VS(bits, 118);
68 VS(in6addrWord(addr, 0), 0x00000000L);
69 VS(in6addrWord(addr, 1), 0x00000000L);
70 VS(in6addrWord(addr, 2), 0x0000FFFFL);
71 VS(in6addrWord(addr, 3), 0xCC0F1500L);
73 VERIFY(HPHP::IpBlockMap::ReadIPv6Address("127.0.0.1", &addr, bits));
74 VS(bits, 128);
75 VS(in6addrWord(addr, 0), 0x00000000L);
76 VS(in6addrWord(addr, 1), 0x00000000L);
77 VS(in6addrWord(addr, 2), 0x0000FFFFL);
78 VS(in6addrWord(addr, 3), 0x7F000001L);
80 VERIFY(IpBlockMap::ReadIPv6Address(
81 "1111:2222:3333:4444:5555:6666:789a:bcde", &addr, bits));
82 VS(bits, 128);
83 VS(in6addrWord(addr, 0), 0x11112222L);
84 VS(in6addrWord(addr, 1), 0x33334444L);
85 VS(in6addrWord(addr, 2), 0x55556666L);
86 VS(in6addrWord(addr, 3), 0x789abcdeL);
88 VERIFY(IpBlockMap::ReadIPv6Address(
89 "1111:2222:3333:4444:5555:6666:789a:bcde/68", &addr, bits));
90 VS(bits, 68);
91 VS(in6addrWord(addr, 0), 0x11112222L);
92 VS(in6addrWord(addr, 1), 0x33334444L);
93 VS(in6addrWord(addr, 2), 0x55556666L);
94 VS(in6addrWord(addr, 3), 0x789abcdeL);
96 IpBlockMap::BinaryPrefixTrie root(true);
97 unsigned char value[16];
99 // Default value with no additional nodes
100 memset(value, 0, 16);
101 VERIFY(root.isAllowed(value, 1));
102 value[0] = 0x80;
103 VERIFY(root.isAllowed(value));
105 // Inheritance of parent allow value through multiple levels of new nodes
106 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 1, false);
107 value[0] = 0xf0;
108 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 4, true);
109 VERIFY(root.isAllowed(value));
110 value[0] = 0xe0;
111 VERIFY(!root.isAllowed(value));
112 value[0] = 0xc0;
113 VERIFY(!root.isAllowed(value));
114 value[0] = 0x80;
115 VERIFY(!root.isAllowed(value));
116 value[0] = 0;
117 VERIFY(root.isAllowed(value));
119 // > 1 byte in address
120 value[2] = 0xff;
121 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 24, false);
122 VERIFY(!root.isAllowed(value));
123 value[3] = 0xff;
124 VERIFY(!root.isAllowed(value));
125 value[2] = 0xfe;
126 VERIFY(root.isAllowed(value));
128 // Exact address match
129 value[2] = 0xff;
130 value[15] = 1;
131 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 128, true);
132 VERIFY(root.isAllowed(value));
134 IniSetting::Map ini = IniSetting::Map::object;
135 Hdf hdf;
136 hdf.fromString(
137 "IpBlockMap {\n"
138 " 0 {\n"
139 " Location = /test\n"
140 " AllowFirst = true\n"
141 " Ip {\n"
142 " Allow {\n"
143 " * = 127.0.0.1\n"
144 " }\n"
145 " Deny {\n"
146 " * = 8.32.0.0/24\n"
147 " * = aaaa:bbbb:cccc:dddd:eeee:ffff:1111::/80\n"
148 " }\n"
149 " }\n"
150 " }\n"
151 "}\n"
154 IpBlockMap ibm(ini, hdf);
155 VERIFY(!ibm.isBlocking("test/blah.php", "127.0.0.1"));
156 VERIFY(ibm.isBlocking("test/blah.php", "8.32.0.104"));
157 VERIFY(ibm.isBlocking("test/blah.php",
158 "aaaa:bbbb:cccc:dddd:eeee:9999:8888:7777"));
159 VERIFY(!ibm.isBlocking("test/blah.php",
160 "aaaa:bbbb:cccc:dddd:eee3:4444:3333:2222"));
162 return Count(true);
165 bool TestCppBase::TestIpBlockMapIni() {
166 struct in6_addr addr;
167 int bits;
169 VERIFY(IpBlockMap::ReadIPv6Address("204.15.21.0/22", &addr, bits));
170 VS(bits, 118);
171 VS(in6addrWord(addr, 0), 0x00000000L);
172 VS(in6addrWord(addr, 1), 0x00000000L);
173 VS(in6addrWord(addr, 2), 0x0000FFFFL);
174 VS(in6addrWord(addr, 3), 0xCC0F1500L);
176 VERIFY(IpBlockMap::ReadIPv6Address("127.0.0.1", &addr, bits));
177 VS(bits, 128);
178 VS(in6addrWord(addr, 0), 0x00000000L);
179 VS(in6addrWord(addr, 1), 0x00000000L);
180 VS(in6addrWord(addr, 2), 0x0000FFFFL);
181 VS(in6addrWord(addr, 3), 0x7F000001L);
183 VERIFY(IpBlockMap::ReadIPv6Address(
184 "1111:2222:3333:4444:5555:6666:789a:bcde", &addr, bits));
185 VS(bits, 128);
186 VS(in6addrWord(addr, 0), 0x11112222L);
187 VS(in6addrWord(addr, 1), 0x33334444L);
188 VS(in6addrWord(addr, 2), 0x55556666L);
189 VS(in6addrWord(addr, 3), 0x789abcdeL);
191 VERIFY(IpBlockMap::ReadIPv6Address(
192 "1111:2222:3333:4444:5555:6666:789a:bcde/68", &addr, bits));
193 VS(bits, 68);
194 VS(in6addrWord(addr, 0), 0x11112222L);
195 VS(in6addrWord(addr, 1), 0x33334444L);
196 VS(in6addrWord(addr, 2), 0x55556666L);
197 VS(in6addrWord(addr, 3), 0x789abcdeL);
199 IpBlockMap::BinaryPrefixTrie root(true);
200 unsigned char value[16];
202 // Default value with no additional nodes
203 memset(value, 0, 16);
204 VERIFY(root.isAllowed(value, 1));
205 value[0] = 0x80;
206 VERIFY(root.isAllowed(value));
208 // Inheritance of parent allow value through multiple levels of new nodes
209 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 1, false);
210 value[0] = 0xf0;
211 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 4, true);
212 VERIFY(root.isAllowed(value));
213 value[0] = 0xe0;
214 VERIFY(!root.isAllowed(value));
215 value[0] = 0xc0;
216 VERIFY(!root.isAllowed(value));
217 value[0] = 0x80;
218 VERIFY(!root.isAllowed(value));
219 value[0] = 0;
220 VERIFY(root.isAllowed(value));
222 // > 1 byte in address
223 value[2] = 0xff;
224 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 24, false);
225 VERIFY(!root.isAllowed(value));
226 value[3] = 0xff;
227 VERIFY(!root.isAllowed(value));
228 value[2] = 0xfe;
229 VERIFY(root.isAllowed(value));
231 // Exact address match
232 value[2] = 0xff;
233 value[15] = 1;
234 IpBlockMap::BinaryPrefixTrie::InsertNewPrefix(&root, value, 128, true);
235 VERIFY(root.isAllowed(value));
237 std::string inistr =
238 "hhvm.ip_block_map[0][location] = /test\n"
239 "hhvm.ip_block_map[0][allow_first] = true\n"
240 "hhvm.ip_block_map[0][ip][allow][0] = 127.0.0.1\n"
241 "hhvm.ip_block_map[0][ip][deny][0] = 8.32.0.0/24\n"
242 "hhvm.ip_block_map[0][ip][deny][1] = "
243 "aaaa:bbbb:cccc:dddd:eeee:ffff:1111::/80\n";
245 IniSetting::Map ini = IniSetting::Map::object;
246 Hdf empty;
248 Config::ParseIniString(inistr, ini);
250 IpBlockMap ibm(ini, empty);
252 VERIFY(!ibm.isBlocking("test/blah.php", "127.0.0.1"));
253 VERIFY(ibm.isBlocking("test/blah.php", "8.32.0.104"));
254 VERIFY(ibm.isBlocking("test/blah.php",
255 "aaaa:bbbb:cccc:dddd:eeee:9999:8888:7777"));
256 // allow first
257 VERIFY(!ibm.isBlocking("test/blah.php",
258 "aaaa:bbbb:cccc:dddd:eee3:4444:3333:2222"));
260 return Count(true);
263 bool TestCppBase::TestVirtualHost() {
264 IniSetting::Map ini = IniSetting::Map::object;
265 Hdf hdf;
266 hdf.fromString(
267 " Server {\n"
268 " AllowedDirectories.* = /var/www\n"
269 " AllowedDirectories.* = /usr/bin\n"
270 " }\n"
271 " VirtualHost {\n"
272 " flibtest {\n"
273 " Prefix = flibtest.\n"
274 " PathTranslation = flib/_bin\n"
275 " ServerName = flibtest.facebook.com\n"
276 " }\n"
277 " upload {\n"
278 " Prefix = upload.\n"
279 " ServerVariables {\n"
280 " TFBENV = 8{\n"
281 " }\n"
282 " overwrite {\n"
283 " Server {\n"
284 " AllowedDirectories.* = /var/www\n"
285 " AllowedDirectories.* = /mnt\n"
286 " AllowedDirectories.* = /tmp\n"
287 " AllowedDirectories.* = /var/tmp/tao\n"
288 " }\n"
289 " MaxPostSize = 100MB\n"
290 " UploadMaxFileSize = 100MB\n"
291 " RequestTimeoutSeconds = 120\n"
292 " }\n"
293 " PathTranslation = html\n"
294 " }\n"
295 " default {\n"
296 " LogFilters {\n"
297 " * {\n"
298 " url = /method/searchme\n"
299 " params {\n"
300 " * = q\n"
301 " * = s\n"
302 " * = atoken\n"
303 " * = otoken\n"
304 " }\n"
305 " value = REMOVED\n"
306 " }\n"
307 " }\n"
308 " RewriteRules {\n"
309 " common {\n"
310 " pattern = /html/common/\n"
311 " to = http://3v4l.org\n"
312 " qsa = true\n"
313 " redirect = 301\n"
314 " }\n"
315 " }\n"
316 " PathTranslation = htm\n"
317 " }\n"
318 " }\n"
321 // reset Cfg::Server::AllowedDirectories to empty because if the INI
322 // version of this test is run at the same time, we don't want to append
323 // the same directories to it. We want to start fresh.
324 Cfg::Server::AllowedDirectories.clear();
325 std::vector<VirtualHost> hosts;
326 Cfg::Server::AllowedDirectories =
327 Config::GetStrVector(ini, hdf, "Server.AllowedDirectories");
328 auto cb = [&] (const IniSetting::Map &ini_cb, const Hdf &hdf_cb,
329 const std::string &host) {
330 if (VirtualHost::IsDefault(ini_cb, hdf_cb, host)) {
331 VirtualHost::GetDefault().init(ini_cb, hdf_cb, host);
332 VirtualHost::GetDefault().
333 addAllowedDirectories(Cfg::Server::AllowedDirectories);
334 } else {
335 auto vh = VirtualHost(ini_cb, hdf_cb, host);
336 // These will be added
337 // " AllowedDirectories.* = /var/www\n"
338 // " AllowedDirectories.* = /usr/bin\n"
339 vh.addAllowedDirectories(Cfg::Server::AllowedDirectories);
340 hosts.push_back(vh);
343 Config::Iterate(cb, ini, hdf, "VirtualHost");
345 for (auto& host : hosts) {
346 VirtualHost::SetCurrent(&host);
347 auto name = host.getName();
348 if (name == "flibtest") {
349 VERIFY(host.getPathTranslation() == "flib/_bin/"); // the / is added
350 VERIFY(host.getDocumentRoot() ==
351 Cfg::Server::SourceRoot + "flib/_bin");
352 VERIFY(host.getServerVars().size() == 0);
353 VERIFY(VirtualHost::GetAllowedDirectories().size() == 2);
354 VERIFY(host.valid() == true);
355 VERIFY(host.hasLogFilter() == false);
356 } else if (name == "upload") {
357 VERIFY(host.getPathTranslation() == "html/"); // the / is added
358 VERIFY(host.getDocumentRoot() ==
359 Cfg::Server::SourceRoot + "html");
360 // SortALlowedDirectories might add something and remove
361 // duplicates. In this case, /var/releases/continuous_www_scripts4
362 // was added and the duplicate /var/www was removed.s
363 VERIFY(VirtualHost::GetAllowedDirectories().size() == 6);
364 VERIFY(host.valid() == true);
365 VERIFY(host.hasLogFilter() == false);
366 VERIFY(VirtualHost::GetMaxPostSize() == 104857600);
370 VERIFY(VirtualHost::GetDefault().getPathTranslation() == "htm/");
371 VERIFY(VirtualHost::GetDefault().hasLogFilter() == true);
372 String rw("/html/common/");
373 String h("default");
374 bool q = false;
375 int rd = 0;
376 VirtualHost::GetDefault().rewriteURL(h, rw, q, rd);
377 VERIFY(rw.toCppString() == "http://3v4l.org");
378 VERIFY(rd == 301);
379 return Count(true);
382 bool TestCppBase::TestVirtualHostIni() {
383 std::string inistr =
384 "hhvm.server.allowed_directories[] = /var/www\n"
385 "hhvm.server.allowed_directories[] = /usr/bin\n"
386 "hhvm.virtual_host[flibtest][prefix] = flibtest.\n"
387 "hhvm.virtual_host[flibtest][path_translation] = flib/_bin\n"
388 "hhvm.virtual_host[flibtest][server_name] = flibtest.facebook.com\n"\
389 "hhvm.virtual_host[flibtest][log_filters][0][url] = function/searchme\n"
390 "hhvm.virtual_host[flibtest][log_filters][0][params][0] = v\n"
391 "hhvm.virtual_host[flibtest][log_filters][0][params][1] = t\n"
392 "hhvm.virtual_host[flibtest][log_filters][0][params][2] = btoken\n"
393 "hhvm.virtual_host[flibtest][log_filters][0][params][3] = ptoken\n"
394 "hhvm.virtual_host[flibtest][log_filters][0][value] = INSERTED\n"
395 "hhvm.virtual_host[flibtest][log_filters][1][url] = property/searchme\n"
396 "hhvm.virtual_host[flibtest][log_filters][1][pattern] = #thePattern#\n"
397 "hhvm.virtual_host[flibtest][log_filters][1][value] = BETWEEN\n"
398 "hhvm.virtual_host[upload][prefix] = upload.\n"
399 "hhvm.virtual_host[upload][server_variables][TFBENV] = 8\n"
400 "hhvm.virtual_host[upload][overwrite][server][allowed_directories][0] = "
401 "/var/www\n"
402 "hhvm.virtual_host[upload][overwrite][server][allowed_directories][1] = "
403 "/mnt\n"
404 "hhvm.virtual_host[upload][overwrite][server][allowed_directories][2] = "
405 "/tmp\n"
406 "hhvm.virtual_host[upload][overwrite][server][allowed_directories][3] = "
407 "/var/tmp/tao\n"
408 "hhvm.virtual_host[upload][overwrite][server][max_post_size] = 100MB\n"
409 "hhvm.virtual_host[upload][overwrite][server][upload]"
410 "[upload_max_file_size] = 100MB\n"
411 "hhvm.virtual_host[upload][overwrite][server]"
412 "[request_timeout_seconds] = 120\n"
413 "hhvm.virtual_host[upload][path_translation] = html\n"
414 "hhvm.virtual_host[default][path_translation] = htm\n"
415 "hhvm.virtual_host[default][log_filters][0][url] = method/searchme\n"
416 "hhvm.virtual_host[default][log_filters][0][params][0] = q\n"
417 "hhvm.virtual_host[default][log_filters][0][params][1] = s\n"
418 "hhvm.virtual_host[default][log_filters][0][params][2] = atoken\n"
419 "hhvm.virtual_host[default][log_filters][0][params][3] = otoken\n"
420 "hhvm.virtual_host[default][log_filters][0][value] = REMOVED\n"
421 "hhvm.virtual_host[default][rewrite_rules][common][pattern] = "
422 "/html/common/\n"
423 "hhvm.virtual_host[default][rewrite_rules][common][to] = "
424 "http://3v4l.org\n"
425 "hhvm.virtual_host[default][rewrite_rules][common][qsa] = true\n"
426 "hhvm.virtual_host[default][rewrite_rules][common][redirect] = 301\n";
428 IniSetting::Map ini = IniSetting::Map::object;
429 Hdf empty;
430 std::vector<VirtualHost> hosts;
432 // reset Cfg::Server::AllowedDirectories to empty because if the Hdf
433 // version of this test is run at the same time, we don't want to append
434 // the same directories to it. We want to start fresh.
435 Cfg::Server::AllowedDirectories.clear();
437 Config::ParseIniString(inistr, ini);
438 Cfg::Server::AllowedDirectories =
439 Config::GetStrVector(ini, empty, "Server.AllowedDirectories");
440 auto cb = [&] (const IniSetting::Map &ini_cb,
441 const Hdf &hdf_cb,
442 const std::string &host){
443 if (VirtualHost::IsDefault(ini_cb, hdf_cb, host)) {
444 VirtualHost::GetDefault().init(ini_cb, hdf_cb, host);
445 VirtualHost::GetDefault().
446 addAllowedDirectories(Cfg::Server::AllowedDirectories);
447 } else {
448 auto vh = VirtualHost(ini_cb, hdf_cb, host);
449 // These will be added
450 // "hhvm.server.allowed_directories[] = /var/www\n"
451 // "hhvm.server.allowed_directories[] = /usr/bin\n"
452 vh.addAllowedDirectories(Cfg::Server::AllowedDirectories);
453 hosts.push_back(vh);
456 Config::Iterate(cb, ini, empty, "VirtualHost");
458 for (auto& host : hosts) {
459 VirtualHost::SetCurrent(&host);
460 auto name = host.getName();
461 if (name == "flibtest") {
462 VERIFY(host.getPathTranslation() == "flib/_bin/"); // the / is added
463 VERIFY(host.getDocumentRoot() ==
464 Cfg::Server::SourceRoot + "flib/_bin");
465 VERIFY(host.getServerVars().size() == 0);
466 VERIFY(VirtualHost::GetAllowedDirectories().size() == 2);
467 VERIFY(host.valid() == true);
468 VERIFY(host.hasLogFilter() == true);
469 VERIFY(host.filterUrl("http://function/searchme/bar?ptoken=baz") ==
470 "http://function/searchme/bar?ptoken=INSERTED");
471 VERIFY(host.filterUrl(
472 "http://function/searchme/thePattern?ptoken=baz") ==
473 "http://function/searchme/thePattern?ptoken=INSERTED"
475 VERIFY(host.filterUrl("http://property/searchme/foothePattern") ==
476 "http://property/searchme/foo=BETWEEN");
477 VERIFY(host.filterUrl("foo") == "foo");
478 } else if (name == "upload") {
479 VERIFY(host.getPathTranslation() == "html/"); // the / is added
480 VERIFY(host.getDocumentRoot() ==
481 Cfg::Server::SourceRoot + "html");
482 // SortALlowedDirectories might add something and remove
483 // duplicates. In this case, /var/releases/continuous_www_scripts4
484 // was added and the duplicate /var/www was removed.s
485 VERIFY(VirtualHost::GetAllowedDirectories().size() == 6);
486 VERIFY(host.valid() == true);
487 VERIFY(host.hasLogFilter() == false);
488 VERIFY(VirtualHost::GetMaxPostSize() == 104857600);
492 VERIFY(VirtualHost::GetDefault().getPathTranslation() == "htm/");
493 VERIFY(VirtualHost::GetDefault().hasLogFilter() == true);
494 String rw("/html/common/");
495 String h("default");
496 bool q = false;
497 int rd = 0;
498 VirtualHost::GetDefault().rewriteURL(h, rw, q, rd);
499 VERIFY(rw.toCppString() == "http://3v4l.org");
500 VERIFY(rd == 301);
502 return Count(true);
505 bool TestCppBase::TestCollectionHdf() {
506 IniSetting::Map ini = IniSetting::Map::object;
507 Hdf hdf;
508 hdf.fromString(
509 " Server {\n"
510 " AllowedDirectories.* = /var/www\n"
511 " AllowedDirectories.* = /usr/bin\n"
512 " HighPriorityEndPoints.* = /end\n"
513 " HighPriorityEndPoints.* = /point\n"
514 " HighPriorityEndPoints.* = /power\n"
515 " }\n"
517 Cfg::Server::AllowedDirectories.clear();
519 Config::Bind(Cfg::Server::AllowedDirectories, ini,
520 hdf, "Server.AllowedDirectories");
521 VERIFY(Cfg::Server::AllowedDirectories.size() == 2);
522 std::vector<std::string> ad =
523 Config::GetStrVector(ini, hdf, "Server.AllowedDirectories",
524 Cfg::Server::AllowedDirectories);
525 VERIFY(Cfg::Server::AllowedDirectories.size() == 2);
526 VERIFY(ad.size() == 2);
528 boost::container::flat_set<std::string> serverHighPriorityEndPoints;
529 Config::Bind(serverHighPriorityEndPoints, ini,
530 hdf, "Server.HighPriorityEndPoints");
531 VERIFY(serverHighPriorityEndPoints.size() == 3);
532 return Count(true);
535 bool TestCppBase::TestCollectionIni() {
536 std::string inistr =
537 "hhvm.server.allowed_directories[] = /var/www\n"
538 "hhvm.server.allowed_directories[] = /usr/bin\n"
539 "hhvm.server.high_priority_end_points[] = /end\n"
540 "hhvm.server.high_priority_end_points[] = /point\n"
541 "hhvm.server.high_priority_end_points[] = /power\n"
542 "hhvm.server.high_priority_end_points[] = /word\n";
544 IniSetting::Map ini = IniSetting::Map::object;
545 Hdf empty;
547 // Ensure we have no residuals left over from the HDF run.
548 Cfg::Server::AllowedDirectories.clear();
550 Config::ParseIniString(inistr, ini);
551 Config::Bind(Cfg::Server::AllowedDirectories, ini, empty,
552 "Server.AllowedDirectories"); // Test converting name
553 VERIFY(Cfg::Server::AllowedDirectories.size() == 2);
554 std::vector<std::string> ad =
555 Config::GetStrVector(ini, empty, "Server.AllowedDirectories",
556 Cfg::Server::AllowedDirectories, false);
557 // This should still be 2. In other words, Get shouldn't append
558 // values.
559 VERIFY(Cfg::Server::AllowedDirectories.size() == 2);
560 VERIFY(ad.size() == 2);
562 boost::container::flat_set<std::string> serverHighPriorityEndPoints;
563 Config::Bind(serverHighPriorityEndPoints, ini, empty,
564 "Server.HighPriorityEndPoints",
565 serverHighPriorityEndPoints, false);
566 VERIFY(serverHighPriorityEndPoints.size() == 4);
567 return Count(true);