[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Unit tests for dirserv_reject_tor_version().



commit 49d6990cae0f6e7e636e320d0efcaec31b3c0453
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Aug 29 11:45:41 2019 -0400

    Unit tests for dirserv_reject_tor_version().
---
 src/test/include.am           |  1 +
 src/test/test.c               |  1 +
 src/test/test.h               |  1 +
 src/test/test_process_descs.c | 67 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 70 insertions(+)

diff --git a/src/test/include.am b/src/test/include.am
index 1e20f3f53..101e915cf 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -175,6 +175,7 @@ src_test_test_SOURCES += \
 	src/test/test_periodic_event.c \
 	src/test/test_policy.c \
 	src/test/test_process.c \
+	src/test/test_process_descs.c \
 	src/test/test_prob_distr.c \
 	src/test/test_procmon.c \
 	src/test/test_proto_http.c \
diff --git a/src/test/test.c b/src/test/test.c
index b9a1da06f..5f27f994f 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -858,6 +858,7 @@ struct testgroup_t testgroups[] = {
   { "crypto/pem/", pem_tests },
   { "crypto/rng/", crypto_rng_tests },
   { "dir/", dir_tests },
+  { "dir/auth/process_descs/", process_descs_tests },
   { "dir/md/", microdesc_tests },
   { "dir/voting/flags/", voting_flags_tests },
   { "dir/voting/schedule/", voting_schedule_tests },
diff --git a/src/test/test.h b/src/test/test.h
index f5c21bfe8..d0b045a80 100644
--- a/src/test/test.h
+++ b/src/test/test.h
@@ -252,6 +252,7 @@ extern struct testcase_t prob_distr_tests[];
 extern struct testcase_t slow_stochastic_prob_distr_tests[];
 extern struct testcase_t procmon_tests[];
 extern struct testcase_t process_tests[];
+extern struct testcase_t process_descs_tests[];
 extern struct testcase_t proto_http_tests[];
 extern struct testcase_t proto_misc_tests[];
 extern struct testcase_t protover_tests[];
diff --git a/src/test/test_process_descs.c b/src/test/test_process_descs.c
new file mode 100644
index 000000000..7dc9abde3
--- /dev/null
+++ b/src/test/test_process_descs.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 2019, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+
+#include "core/or/or.h"
+#include "feature/dirauth/process_descs.h"
+
+#include "test/test.h"
+
+static void
+test_process_descs_versions(void *arg)
+{
+  (void)arg;
+  struct {
+    const char *version;
+    bool should_reject;
+  } cases[] = {
+    // a very old version: reject.
+    { "Tor 0.1.2.3-alpha", true },
+    // a non-tor program: don't reject.
+    { "Wombat 0.1.2.3-alpha", false },
+    // a slightly old version: reject
+    { "Tor 0.2.9.4-alpha", true },
+    // a slightly old version: just new enough to support.
+    { "Tor 0.2.9.5-alpha", false },
+    // a newer 0.2.9 version: supported.
+    { "Tor 0.2.9.100", false },
+    // some unsupported versions: reject.
+    { "Tor 0.3.0.0-alpha-dev", true },
+    { "Tor 0.3.0.2-alpha", true },
+    { "Tor 0.3.0.5", true },
+    { "Tor 0.3.1.4", true },
+    { "Tor 0.3.2.4", true },
+    { "Tor 0.3.3.4", true },
+    { "Tor 0.3.4.1-alpha", true },
+    { "Tor 0.3.4.100", true },
+    { "Tor 0.3.5.1-alpha", true },
+    { "Tor 0.3.5.6-rc", true},
+    // new enough to be supported
+    { "Tor 0.3.5.7", false },
+    { "Tor 0.3.5.8", false },
+    { "Tor 0.4.0.1-alpha", false },
+    { "Tor 0.4.1.5", false },
+    // Very far in the future
+    { "Tor 100.100.1.5", false },
+  };
+  size_t n_cases = ARRAY_LENGTH(cases);
+
+  for (unsigned i = 0; i < n_cases; ++i) {
+    const char *msg = NULL;
+    bool rejected = dirserv_rejects_tor_version(cases[i].version, &msg);
+    tt_int_op(rejected, OP_EQ, cases[i].should_reject);
+    tt_int_op(msg == NULL, OP_EQ, rejected == false);
+  }
+
+ done:
+  ;
+}
+
+#define T(name,flags)                                   \
+  { #name, test_process_descs_##name, (flags), NULL, NULL }
+
+struct testcase_t process_descs_tests[] = {
+  T(versions,0),
+  END_OF_TESTCASES
+};



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits