commit 14cb337e803c766c2831364f71516f4c247810db Author: teor teor@torproject.org Date: Wed Feb 12 22:07:26 2020 +1000
test/protover: Test hard-coded protover sorting
Make sure that the following hard-coded protocol version lists are sorted: * supported protocols * recommended relay and client protocols * required relay and client protocols
This test currently fails, because the supported protocols are not sorted.
Tests for 33285. --- src/test/test_protover.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
diff --git a/src/test/test_protover.c b/src/test/test_protover.c index f1d1ef0d4..7d0891102 100644 --- a/src/test/test_protover.c +++ b/src/test/test_protover.c @@ -2,6 +2,7 @@ /* See LICENSE for licensing information */
#define PROTOVER_PRIVATE +#define DIRVOTE_PRIVATE
#include "orconfig.h" #include "test/test.h" @@ -12,6 +13,8 @@ #include "core/or/connection_or.h" #include "lib/tls/tortls.h"
+#include "feature/dirauth/dirvote.h" + static void test_protover_parse(void *arg) { @@ -634,6 +637,43 @@ test_protover_vote_roundtrip(void *args) tor_free(result); }
+static void +test_protover_vote_roundtrip_ours(void *args) +{ + (void) args; + const char *examples[] = { + protover_get_supported_protocols(), + DIRVOTE_RECCOMEND_RELAY_PROTO, + DIRVOTE_RECCOMEND_CLIENT_PROTO, + DIRVOTE_REQUIRE_RELAY_PROTO, + DIRVOTE_REQUIRE_CLIENT_PROTO, + }; + unsigned u; + smartlist_t *votes = smartlist_new(); + char *result = NULL; + + for (u = 0; u < ARRAY_LENGTH(examples); ++u) { + tt_assert(examples[u]); + const char *input = examples[u]; + const char *expected_output = examples[u]; + + smartlist_add(votes, (void*)input); + result = protover_compute_vote(votes, 1); + if (expected_output != NULL) { + tt_str_op(result, OP_EQ, expected_output); + } else { + tt_str_op(result, OP_EQ, ""); + } + + smartlist_clear(votes); + tor_free(result); + } + + done: + smartlist_free(votes); + tor_free(result); +} + #define PV_TEST(name, flags) \ { #name, test_protover_ ##name, (flags), NULL, NULL }
@@ -647,5 +687,6 @@ struct testcase_t protover_tests[] = { PV_TEST(supports_version, 0), PV_TEST(supported_protocols, 0), PV_TEST(vote_roundtrip, 0), + PV_TEST(vote_roundtrip_ours, 0), END_OF_TESTCASES };