aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_protover.c
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2020-02-12 22:07:26 +1000
committerteor <teor@torproject.org>2020-02-12 22:07:26 +1000
commit14cb337e803c766c2831364f71516f4c247810db (patch)
tree815a797b83420449098ec1ce976d8360700ae87c /src/test/test_protover.c
parent64bb6e622dbce6448e29e4ff6140a1c6bb44c298 (diff)
downloadtor-14cb337e803c766c2831364f71516f4c247810db.tar.gz
tor-14cb337e803c766c2831364f71516f4c247810db.zip
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.
Diffstat (limited to 'src/test/test_protover.c')
-rw-r--r--src/test/test_protover.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/test_protover.c b/src/test/test_protover.c
index f1d1ef0d4a..7d08911021 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
};