test_hs_config.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /* Copyright (c) 2016-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file test_hs_config.c
  5. * \brief Test hidden service configuration functionality.
  6. */
  7. #define CONFIG_PRIVATE
  8. #define HS_SERVICE_PRIVATE
  9. #include "test/test.h"
  10. #include "test/test_helpers.h"
  11. #include "test/log_test_helpers.h"
  12. #include "test/resolve_test_helpers.h"
  13. #include "app/config/config.h"
  14. #include "feature/hs/hs_common.h"
  15. #include "feature/hs/hs_config.h"
  16. #include "feature/hs/hs_service.h"
  17. #include "feature/rend/rendservice.h"
  18. static int
  19. helper_config_service(const char *conf, int validate_only)
  20. {
  21. int ret = 0;
  22. or_options_t *options = NULL;
  23. tt_assert(conf);
  24. options = helper_parse_options(conf);
  25. tt_assert(options);
  26. ret = hs_config_service_all(options, validate_only);
  27. done:
  28. or_options_free(options);
  29. return ret;
  30. }
  31. static void
  32. test_invalid_service(void *arg)
  33. {
  34. int ret;
  35. (void) arg;
  36. /* Try with a missing port configuration. */
  37. {
  38. const char *conf =
  39. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  40. "HiddenServiceVersion 1\n"; /* Wrong not supported version. */
  41. setup_full_capture_of_logs(LOG_WARN);
  42. ret = helper_config_service(conf, 1);
  43. tt_int_op(ret, OP_EQ, -1);
  44. expect_log_msg_containing("HiddenServiceVersion must be between 2 and 3");
  45. teardown_capture_of_logs();
  46. }
  47. /* Bad value of HiddenServiceAllowUnknownPorts. */
  48. {
  49. const char *conf =
  50. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  51. "HiddenServiceVersion 2\n"
  52. "HiddenServiceAllowUnknownPorts 2\n"; /* Should be 0 or 1. */
  53. setup_full_capture_of_logs(LOG_WARN);
  54. ret = helper_config_service(conf, 1);
  55. tt_int_op(ret, OP_EQ, -1);
  56. expect_log_msg_containing("HiddenServiceAllowUnknownPorts must be "
  57. "between 0 and 1, not 2");
  58. teardown_capture_of_logs();
  59. }
  60. /* Bad value of HiddenServiceDirGroupReadable */
  61. {
  62. const char *conf =
  63. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  64. "HiddenServiceVersion 2\n"
  65. "HiddenServiceDirGroupReadable 2\n"; /* Should be 0 or 1. */
  66. setup_full_capture_of_logs(LOG_WARN);
  67. ret = helper_config_service(conf, 1);
  68. tt_int_op(ret, OP_EQ, -1);
  69. expect_log_msg_containing("HiddenServiceDirGroupReadable must be "
  70. "between 0 and 1, not 2");
  71. teardown_capture_of_logs();
  72. }
  73. /* Bad value of HiddenServiceMaxStreamsCloseCircuit */
  74. {
  75. const char *conf =
  76. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  77. "HiddenServiceVersion 2\n"
  78. "HiddenServiceMaxStreamsCloseCircuit 2\n"; /* Should be 0 or 1. */
  79. setup_full_capture_of_logs(LOG_WARN);
  80. ret = helper_config_service(conf, 1);
  81. tt_int_op(ret, OP_EQ, -1);
  82. expect_log_msg_containing("HiddenServiceMaxStreamsCloseCircuit must "
  83. "be between 0 and 1, not 2");
  84. teardown_capture_of_logs();
  85. }
  86. /* Too much max streams. */
  87. {
  88. const char *conf =
  89. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  90. "HiddenServiceVersion 2\n"
  91. "HiddenServicePort 80\n"
  92. "HiddenServiceMaxStreams 65536\n"; /* One too many. */
  93. setup_full_capture_of_logs(LOG_WARN);
  94. ret = helper_config_service(conf, 1);
  95. tt_int_op(ret, OP_EQ, -1);
  96. expect_log_msg_containing("HiddenServiceMaxStreams must be between "
  97. "0 and 65535, not 65536");
  98. teardown_capture_of_logs();
  99. }
  100. /* Duplicate directory directive. */
  101. {
  102. const char *conf =
  103. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  104. "HiddenServiceVersion 2\n"
  105. "HiddenServicePort 80\n"
  106. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  107. "HiddenServiceVersion 2\n"
  108. "HiddenServicePort 81\n";
  109. setup_full_capture_of_logs(LOG_WARN);
  110. ret = helper_config_service(conf, 1);
  111. tt_int_op(ret, OP_EQ, -1);
  112. expect_log_msg_containing("Another hidden service is already "
  113. "configured for directory");
  114. teardown_capture_of_logs();
  115. }
  116. /* Bad port. */
  117. {
  118. const char *conf =
  119. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  120. "HiddenServiceVersion 2\n"
  121. "HiddenServicePort 65536\n";
  122. setup_full_capture_of_logs(LOG_WARN);
  123. ret = helper_config_service(conf, 1);
  124. tt_int_op(ret, OP_EQ, -1);
  125. expect_log_msg_containing("Missing or invalid port");
  126. teardown_capture_of_logs();
  127. }
  128. /* Bad target addr:port separation. */
  129. {
  130. const char *conf =
  131. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  132. "HiddenServiceVersion 2\n"
  133. "HiddenServicePort 80 127.0.0.1 8000\n";
  134. setup_full_capture_of_logs(LOG_WARN);
  135. ret = helper_config_service(conf, 1);
  136. tt_int_op(ret, OP_EQ, -1);
  137. expect_log_msg_containing("HiddenServicePort parse error: "
  138. "invalid port mapping");
  139. teardown_capture_of_logs();
  140. }
  141. /* Out of order directives. */
  142. {
  143. const char *conf =
  144. "HiddenServiceVersion 2\n"
  145. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  146. "HiddenServicePort 80\n";
  147. setup_full_capture_of_logs(LOG_WARN);
  148. ret = helper_config_service(conf, 1);
  149. tt_int_op(ret, OP_EQ, -1);
  150. expect_log_msg_containing("HiddenServiceVersion with no preceding "
  151. "HiddenServiceDir directive");
  152. teardown_capture_of_logs();
  153. }
  154. done:
  155. ;
  156. }
  157. static void
  158. test_valid_service(void *arg)
  159. {
  160. int ret;
  161. (void) arg;
  162. /* Mix of v2 and v3. Still valid. */
  163. {
  164. const char *conf =
  165. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  166. "HiddenServiceVersion 2\n"
  167. "HiddenServicePort 80\n"
  168. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
  169. "HiddenServiceVersion 3\n"
  170. "HiddenServicePort 81\n"
  171. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
  172. "HiddenServiceVersion 2\n"
  173. "HiddenServicePort 82\n";
  174. ret = helper_config_service(conf, 1);
  175. tt_int_op(ret, OP_EQ, 0);
  176. }
  177. done:
  178. ;
  179. }
  180. static void
  181. test_invalid_service_v2(void *arg)
  182. {
  183. int validate_only = 1, ret;
  184. (void) arg;
  185. /* Try with a missing port configuration. */
  186. {
  187. const char *conf =
  188. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  189. "HiddenServiceVersion 2\n";
  190. setup_full_capture_of_logs(LOG_WARN);
  191. ret = helper_config_service(conf, validate_only);
  192. tt_int_op(ret, OP_EQ, -1);
  193. expect_log_msg_containing("with no ports configured.");
  194. teardown_capture_of_logs();
  195. }
  196. /* Too many introduction points. */
  197. {
  198. const char *conf =
  199. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  200. "HiddenServiceVersion 2\n"
  201. "HiddenServicePort 80\n"
  202. "HiddenServiceNumIntroductionPoints 11\n"; /* One too many. */
  203. setup_full_capture_of_logs(LOG_WARN);
  204. ret = helper_config_service(conf, validate_only);
  205. tt_int_op(ret, OP_EQ, -1);
  206. expect_log_msg_containing("HiddenServiceNumIntroductionPoints should "
  207. "be between 0 and 10, not 11");
  208. teardown_capture_of_logs();
  209. }
  210. /* Too little introduction points. */
  211. {
  212. const char *conf =
  213. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  214. "HiddenServiceVersion 2\n"
  215. "HiddenServicePort 80\n"
  216. "HiddenServiceNumIntroductionPoints -1\n";
  217. setup_full_capture_of_logs(LOG_WARN);
  218. ret = helper_config_service(conf, validate_only);
  219. tt_int_op(ret, OP_EQ, -1);
  220. expect_log_msg_containing("HiddenServiceNumIntroductionPoints should "
  221. "be between 0 and 10, not -1");
  222. teardown_capture_of_logs();
  223. }
  224. /* Bad authorized client type. */
  225. {
  226. const char *conf =
  227. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  228. "HiddenServiceVersion 2\n"
  229. "HiddenServicePort 80\n"
  230. "HiddenServiceAuthorizeClient blah alice,bob\n"; /* blah is no good. */
  231. setup_full_capture_of_logs(LOG_WARN);
  232. ret = helper_config_service(conf, validate_only);
  233. tt_int_op(ret, OP_EQ, -1);
  234. expect_log_msg_containing("HiddenServiceAuthorizeClient contains "
  235. "unrecognized auth-type");
  236. teardown_capture_of_logs();
  237. }
  238. done:
  239. ;
  240. }
  241. static void
  242. test_valid_service_v2(void *arg)
  243. {
  244. int ret;
  245. (void) arg;
  246. mock_hostname_resolver();
  247. /* Valid complex configuration. Basic client authorization. */
  248. {
  249. const char *conf =
  250. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  251. "HiddenServiceVersion 2\n"
  252. "HiddenServicePort 80\n"
  253. "HiddenServicePort 22 localhost:22\n"
  254. #ifdef HAVE_SYS_UN_H
  255. "HiddenServicePort 42 unix:/path/to/socket\n"
  256. #endif
  257. "HiddenServiceAuthorizeClient basic alice,bob,eve\n"
  258. "HiddenServiceAllowUnknownPorts 1\n"
  259. "HiddenServiceMaxStreams 42\n"
  260. "HiddenServiceMaxStreamsCloseCircuit 0\n"
  261. "HiddenServiceDirGroupReadable 1\n"
  262. "HiddenServiceNumIntroductionPoints 7\n";
  263. ret = helper_config_service(conf, 1);
  264. tt_int_op(ret, OP_EQ, 0);
  265. }
  266. /* Valid complex configuration. Stealth client authorization. */
  267. {
  268. const char *conf =
  269. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
  270. "HiddenServiceVersion 2\n"
  271. "HiddenServicePort 65535\n"
  272. "HiddenServicePort 22 1.1.1.1:22\n"
  273. #ifdef HAVE_SYS_UN_H
  274. "HiddenServicePort 9000 unix:/path/to/socket\n"
  275. #endif
  276. "HiddenServiceAuthorizeClient stealth charlie,romeo\n"
  277. "HiddenServiceAllowUnknownPorts 0\n"
  278. "HiddenServiceMaxStreams 42\n"
  279. "HiddenServiceMaxStreamsCloseCircuit 0\n"
  280. "HiddenServiceDirGroupReadable 1\n"
  281. "HiddenServiceNumIntroductionPoints 8\n";
  282. ret = helper_config_service(conf, 1);
  283. tt_int_op(ret, OP_EQ, 0);
  284. }
  285. done:
  286. unmock_hostname_resolver();
  287. }
  288. static void
  289. test_invalid_service_v3(void *arg)
  290. {
  291. int validate_only = 1, ret;
  292. (void) arg;
  293. /* Try with a missing port configuration. */
  294. {
  295. const char *conf =
  296. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  297. "HiddenServiceVersion 3\n";
  298. setup_full_capture_of_logs(LOG_WARN);
  299. ret = helper_config_service(conf, validate_only);
  300. tt_int_op(ret, OP_EQ, -1);
  301. expect_log_msg_containing("with no ports configured.");
  302. teardown_capture_of_logs();
  303. }
  304. /* Too many introduction points. */
  305. {
  306. const char *conf =
  307. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  308. "HiddenServiceVersion 3\n"
  309. "HiddenServicePort 80\n"
  310. "HiddenServiceNumIntroductionPoints 21\n"; /* One too many. */
  311. setup_full_capture_of_logs(LOG_WARN);
  312. ret = helper_config_service(conf, validate_only);
  313. tt_int_op(ret, OP_EQ, -1);
  314. expect_log_msg_containing("HiddenServiceNumIntroductionPoints must "
  315. "be between 3 and 20, not 21.");
  316. teardown_capture_of_logs();
  317. }
  318. /* Too little introduction points. */
  319. {
  320. const char *conf =
  321. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  322. "HiddenServiceVersion 3\n"
  323. "HiddenServicePort 80\n"
  324. "HiddenServiceNumIntroductionPoints 1\n";
  325. setup_full_capture_of_logs(LOG_WARN);
  326. ret = helper_config_service(conf, validate_only);
  327. tt_int_op(ret, OP_EQ, -1);
  328. expect_log_msg_containing("HiddenServiceNumIntroductionPoints must "
  329. "be between 3 and 20, not 1.");
  330. teardown_capture_of_logs();
  331. }
  332. /* v2-specific HiddenServiceAuthorizeClient set. */
  333. {
  334. const char *conf =
  335. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  336. "HiddenServiceVersion 3\n"
  337. "HiddenServiceAuthorizeClient stealth client1\n";
  338. setup_full_capture_of_logs(LOG_WARN);
  339. ret = helper_config_service(conf, validate_only);
  340. tt_int_op(ret, OP_EQ, -1);
  341. expect_log_msg_containing("Hidden service option "
  342. "HiddenServiceAuthorizeClient is incompatible "
  343. "with version 3 of service in "
  344. "/tmp/tor-test-hs-RANDOM/hs1");
  345. teardown_capture_of_logs();
  346. }
  347. done:
  348. ;
  349. }
  350. static void
  351. test_valid_service_v3(void *arg)
  352. {
  353. int ret;
  354. (void) arg;
  355. mock_hostname_resolver();
  356. /* Valid complex configuration. */
  357. {
  358. const char *conf =
  359. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  360. "HiddenServiceVersion 3\n"
  361. "HiddenServicePort 80\n"
  362. "HiddenServicePort 22 localhost:22\n"
  363. #ifdef HAVE_SYS_UN_H
  364. "HiddenServicePort 42 unix:/path/to/socket\n"
  365. #endif
  366. "HiddenServiceAllowUnknownPorts 1\n"
  367. "HiddenServiceMaxStreams 42\n"
  368. "HiddenServiceMaxStreamsCloseCircuit 0\n"
  369. "HiddenServiceDirGroupReadable 1\n"
  370. "HiddenServiceNumIntroductionPoints 7\n";
  371. ret = helper_config_service(conf, 1);
  372. tt_int_op(ret, OP_EQ, 0);
  373. }
  374. /* Valid complex configuration. */
  375. {
  376. const char *conf =
  377. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
  378. "HiddenServiceVersion 3\n"
  379. "HiddenServicePort 65535\n"
  380. "HiddenServicePort 22 1.1.1.1:22\n"
  381. #ifdef HAVE_SYS_UN_H
  382. "HiddenServicePort 9000 unix:/path/to/socket\n"
  383. #endif
  384. "HiddenServiceAllowUnknownPorts 0\n"
  385. "HiddenServiceMaxStreams 42\n"
  386. "HiddenServiceMaxStreamsCloseCircuit 0\n"
  387. "HiddenServiceDirGroupReadable 1\n"
  388. "HiddenServiceNumIntroductionPoints 20\n";
  389. ret = helper_config_service(conf, 1);
  390. tt_int_op(ret, OP_EQ, 0);
  391. }
  392. /* Mix of v2 and v3. Still valid. */
  393. {
  394. const char *conf =
  395. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs1\n"
  396. "HiddenServiceVersion 2\n"
  397. "HiddenServicePort 80\n"
  398. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
  399. "HiddenServiceVersion 3\n"
  400. "HiddenServicePort 81\n"
  401. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
  402. "HiddenServiceVersion 2\n"
  403. "HiddenServicePort 82\n";
  404. ret = helper_config_service(conf, 1);
  405. tt_int_op(ret, OP_EQ, 0);
  406. }
  407. done:
  408. unmock_hostname_resolver();
  409. }
  410. static void
  411. test_staging_service_v3(void *arg)
  412. {
  413. int ret;
  414. (void) arg;
  415. /* We don't validate a service object, this is the service test that are in
  416. * charge of doing so. We just check for the stable state after
  417. * registration. */
  418. hs_init();
  419. /* Time for a valid v3 service that should get staged. */
  420. const char *conf =
  421. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs2\n"
  422. "HiddenServiceVersion 3\n"
  423. "HiddenServicePort 65535\n"
  424. "HiddenServicePort 22 1.1.1.1:22\n"
  425. #ifdef HAVE_SYS_UN_H
  426. "HiddenServicePort 9000 unix:/path/to/socket\n"
  427. #endif
  428. "HiddenServiceAllowUnknownPorts 0\n"
  429. "HiddenServiceMaxStreams 42\n"
  430. "HiddenServiceMaxStreamsCloseCircuit 0\n"
  431. "HiddenServiceDirGroupReadable 1\n"
  432. "HiddenServiceNumIntroductionPoints 20\n";
  433. ret = helper_config_service(conf, 0);
  434. tt_int_op(ret, OP_EQ, 0);
  435. /* Ok, we have a service in our map! Registration went well. */
  436. tt_int_op(get_hs_service_staging_list_size(), OP_EQ, 1);
  437. /* Make sure we don't have a magic v2 service out of this. */
  438. tt_int_op(rend_num_services(), OP_EQ, 0);
  439. done:
  440. hs_free_all();
  441. }
  442. static void
  443. test_dos_parameters(void *arg)
  444. {
  445. int ret;
  446. (void) arg;
  447. hs_init();
  448. /* Valid configuration. */
  449. {
  450. const char *conf =
  451. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
  452. "HiddenServiceVersion 3\n"
  453. "HiddenServicePort 22 1.1.1.1:22\n"
  454. "HiddenServiceEnableIntroDoSDefense 1\n"
  455. "HiddenServiceEnableIntroDoSRatePerSec 42\n"
  456. "HiddenServiceEnableIntroDoSBurstPerSec 87\n";
  457. setup_full_capture_of_logs(LOG_INFO);
  458. ret = helper_config_service(conf, 0);
  459. tt_int_op(ret, OP_EQ, 0);
  460. expect_log_msg_containing("Service INTRO2 DoS defenses rate set to: 42");
  461. expect_log_msg_containing("Service INTRO2 DoS defenses burst set to: 87");
  462. teardown_capture_of_logs();
  463. }
  464. /* Invalid rate. Value of 2^37. Max allowed is 2^31. */
  465. {
  466. const char *conf =
  467. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
  468. "HiddenServiceVersion 3\n"
  469. "HiddenServicePort 22 1.1.1.1:22\n"
  470. "HiddenServiceEnableIntroDoSDefense 1\n"
  471. "HiddenServiceEnableIntroDoSRatePerSec 137438953472\n"
  472. "HiddenServiceEnableIntroDoSBurstPerSec 87\n";
  473. setup_full_capture_of_logs(LOG_WARN);
  474. ret = helper_config_service(conf, 0);
  475. tt_int_op(ret, OP_EQ, -1);
  476. expect_log_msg_containing("HiddenServiceEnableIntroDoSRatePerSec must "
  477. "be between 0 and 2147483647, "
  478. "not 137438953472");
  479. teardown_capture_of_logs();
  480. }
  481. /* Invalid burst. Value of 2^38. Max allowed is 2^31. */
  482. {
  483. const char *conf =
  484. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
  485. "HiddenServiceVersion 3\n"
  486. "HiddenServicePort 22 1.1.1.1:22\n"
  487. "HiddenServiceEnableIntroDoSDefense 1\n"
  488. "HiddenServiceEnableIntroDoSRatePerSec 42\n"
  489. "HiddenServiceEnableIntroDoSBurstPerSec 274877906944\n";
  490. setup_full_capture_of_logs(LOG_WARN);
  491. ret = helper_config_service(conf, 0);
  492. tt_int_op(ret, OP_EQ, -1);
  493. expect_log_msg_containing("HiddenServiceEnableIntroDoSBurstPerSec must "
  494. "be between 0 and 2147483647, "
  495. "not 274877906944");
  496. teardown_capture_of_logs();
  497. }
  498. /* Burst is smaller than rate. */
  499. {
  500. const char *conf =
  501. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
  502. "HiddenServiceVersion 3\n"
  503. "HiddenServicePort 22 1.1.1.1:22\n"
  504. "HiddenServiceEnableIntroDoSDefense 1\n"
  505. "HiddenServiceEnableIntroDoSRatePerSec 42\n"
  506. "HiddenServiceEnableIntroDoSBurstPerSec 27\n";
  507. setup_full_capture_of_logs(LOG_WARN);
  508. ret = helper_config_service(conf, 0);
  509. tt_int_op(ret, OP_EQ, -1);
  510. expect_log_msg_containing("Hidden service DoS defenses burst (27) can "
  511. "not be smaller than the rate value (42).");
  512. teardown_capture_of_logs();
  513. }
  514. /* Negative value. */
  515. {
  516. const char *conf =
  517. "HiddenServiceDir /tmp/tor-test-hs-RANDOM/hs3\n"
  518. "HiddenServiceVersion 3\n"
  519. "HiddenServicePort 22 1.1.1.1:22\n"
  520. "HiddenServiceEnableIntroDoSDefense 1\n"
  521. "HiddenServiceEnableIntroDoSRatePerSec -1\n"
  522. "HiddenServiceEnableIntroDoSBurstPerSec 42\n";
  523. setup_full_capture_of_logs(LOG_WARN);
  524. ret = helper_config_service(conf, 0);
  525. tt_int_op(ret, OP_EQ, -1);
  526. expect_log_msg_containing("HiddenServiceEnableIntroDoSRatePerSec must be "
  527. "between 0 and 2147483647, not -1");
  528. teardown_capture_of_logs();
  529. }
  530. done:
  531. hs_free_all();
  532. }
  533. struct testcase_t hs_config_tests[] = {
  534. /* Invalid service not specific to any version. */
  535. { "invalid_service", test_invalid_service, TT_FORK,
  536. NULL, NULL },
  537. { "valid_service", test_valid_service, TT_FORK,
  538. NULL, NULL },
  539. /* Test case only for version 2. */
  540. { "invalid_service_v2", test_invalid_service_v2, TT_FORK,
  541. NULL, NULL },
  542. { "valid_service_v2", test_valid_service_v2, TT_FORK,
  543. NULL, NULL },
  544. /* Test case only for version 3. */
  545. { "invalid_service_v3", test_invalid_service_v3, TT_FORK,
  546. NULL, NULL },
  547. { "valid_service_v3", test_valid_service_v3, TT_FORK,
  548. NULL, NULL },
  549. /* Test service staging. */
  550. { "staging_service_v3", test_staging_service_v3, TT_FORK,
  551. NULL, NULL },
  552. /* Test HS DoS parameters. */
  553. { "dos_parameters", test_dos_parameters, TT_FORK,
  554. NULL, NULL },
  555. END_OF_TESTCASES
  556. };