diff options
author | David Goulet <dgoulet@torproject.org> | 2019-08-20 09:38:13 -0400 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2019-08-26 15:53:47 +0300 |
commit | 461d231289584110bde37ab498db3631fb6b0cf1 (patch) | |
tree | f472fd45936c7b5545269af78006adf096c3ca9e /src/test/test_hs_dos.c | |
parent | 1c4607b13254942256b869ff0044d205518cc949 (diff) | |
download | tor-461d231289584110bde37ab498db3631fb6b0cf1.tar.gz tor-461d231289584110bde37ab498db3631fb6b0cf1.zip |
hs-v3: Refactor DoS cell extension parameters validation
Move everything to its own function in order to better log, document and tests
the introduction point validation process.
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_hs_dos.c')
-rw-r--r-- | src/test/test_hs_dos.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/test_hs_dos.c b/src/test/test_hs_dos.c index 370e12bf72..25a04d779e 100644 --- a/src/test/test_hs_dos.c +++ b/src/test/test_hs_dos.c @@ -9,6 +9,7 @@ #define CIRCUITLIST_PRIVATE #define NETWORKSTATUS_PRIVATE #define HS_DOS_PRIVATE +#define HS_INTROPOINT_PRIVATE #include "test/test.h" #include "test/test_helpers.h" @@ -21,6 +22,7 @@ #include "core/or/or_circuit_st.h" #include "feature/hs/hs_dos.h" +#include "feature/hs/hs_intropoint.h" #include "feature/nodelist/networkstatus.h" static void @@ -125,9 +127,50 @@ test_can_send_intro2(void *arg) free_mock_consensus(); } +static void +test_validate_dos_extension_params(void *arg) +{ + bool ret; + + (void) arg; + + /* Validate the default values. */ + ret = validate_cell_dos_extension_parameters( + get_intro2_rate_consensus_param(NULL), + get_intro2_burst_consensus_param(NULL)); + tt_assert(ret); + + /* Valid custom rate/burst. */ + ret = validate_cell_dos_extension_parameters(17, 42); + tt_assert(ret); + + /* Invalid rate. */ + ret = validate_cell_dos_extension_parameters(UINT64_MAX, 42); + tt_assert(!ret); + + /* Invalid burst. */ + ret = validate_cell_dos_extension_parameters(42, UINT64_MAX); + tt_assert(!ret); + + /* Value of 0 should return invalid so defenses can be disabled. */ + ret = validate_cell_dos_extension_parameters(0, 42); + tt_assert(!ret); + ret = validate_cell_dos_extension_parameters(42, 0); + tt_assert(!ret); + + /* Can't have burst smaller than rate. */ + ret = validate_cell_dos_extension_parameters(42, 40); + tt_assert(!ret); + + done: + return; +} + struct testcase_t hs_dos_tests[] = { { "can_send_intro2", test_can_send_intro2, TT_FORK, NULL, NULL }, + { "validate_dos_extension_params", test_validate_dos_extension_params, + TT_FORK, NULL, NULL }, END_OF_TESTCASES }; |