]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
test/protover: Test hard-coded protover sorting
authorteor <teor@torproject.org>
Wed, 12 Feb 2020 12:07:26 +0000 (22:07 +1000)
committerteor <teor@torproject.org>
Wed, 12 Feb 2020 12:07:26 +0000 (22:07 +1000)
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

index f1d1ef0d4af3575faafa64fe0606cc05a2ebf2e1..7d08911021f7fa36be4d6b9d0fdca7f693a262fb 100644 (file)
@@ -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
 };