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

[tor-commits] [tor/master] Add GETINFO "rephist/{tap, ntor}/onion_handshakes_{assigned/requested}" test



commit 4173876bc4a81c471be53b5c93dacf2566b52fb0
Author: Neel Chauhan <neel@xxxxxxxxx>
Date:   Wed May 27 21:49:22 2020 -0700

    Add GETINFO "rephist/{tap,ntor}/onion_handshakes_{assigned/requested}" test
---
 src/test/test_controller.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/src/test/test_controller.c b/src/test/test_controller.c
index a69ec17db..f6dccf3bf 100644
--- a/src/test/test_controller.c
+++ b/src/test/test_controller.c
@@ -19,6 +19,7 @@
 #include "feature/rend/rendservice.h"
 #include "feature/nodelist/authcert.h"
 #include "feature/nodelist/nodelist.h"
+#include "feature/stats/rephist.h"
 #include "test/test.h"
 #include "test/test_helpers.h"
 #include "lib/net/resolve.h"
@@ -2112,6 +2113,91 @@ test_control_getconf(void *arg)
   smartlist_free(reply_strs);
 }
 
+static int
+mock_rep_hist_get_circuit_handshake(uint16_t type)
+{
+  int ret;
+
+  switch (type) {
+    case ONION_HANDSHAKE_TYPE_NTOR:
+      ret = 80;
+      break;
+    case ONION_HANDSHAKE_TYPE_TAP:
+      ret = 86;
+      break;
+    default:
+      ret = 0;
+      break;
+  }
+
+  return ret;
+}
+
+static void
+test_rep_hist(void *arg)
+{
+  /* We just need one of these to pass, it doesn't matter what's in it */
+  control_connection_t dummy;
+  /* Get results out */
+  char *answer = NULL;
+  const char *errmsg = NULL;
+
+  (void) arg;
+
+  /* We need these for returning the (mock) rephist. */
+  MOCK(rep_hist_get_circuit_handshake_requested,
+       mock_rep_hist_get_circuit_handshake);
+  MOCK(rep_hist_get_circuit_handshake_assigned,
+       mock_rep_hist_get_circuit_handshake);
+
+  /* NTor tests */
+  getinfo_helper_rephist(&dummy, "stats/ntor/requested",
+                         &answer, &errmsg);
+  tt_ptr_op(answer, OP_NE, NULL);
+  tt_ptr_op(errmsg, OP_EQ, NULL);
+  tt_str_op(answer, OP_EQ, "80");
+  tor_free(answer);
+  errmsg = NULL;
+
+  getinfo_helper_rephist(&dummy, "stats/ntor/assigned",
+                         &answer, &errmsg);
+  tt_ptr_op(answer, OP_NE, NULL);
+  tt_ptr_op(errmsg, OP_EQ, NULL);
+  tt_str_op(answer, OP_EQ, "80");
+  tor_free(answer);
+  errmsg = NULL;
+
+  /* TAP tests */
+  getinfo_helper_rephist(&dummy, "stats/tap/requested",
+                         &answer, &errmsg);
+  tt_ptr_op(answer, OP_NE, NULL);
+  tt_ptr_op(errmsg, OP_EQ, NULL);
+  tt_str_op(answer, OP_EQ, "86");
+  tor_free(answer);
+  errmsg = NULL;
+
+  getinfo_helper_rephist(&dummy, "stats/tap/assigned",
+                         &answer, &errmsg);
+  tt_ptr_op(answer, OP_NE, NULL);
+  tt_ptr_op(errmsg, OP_EQ, NULL);
+  tt_str_op(answer, OP_EQ, "86");
+  tor_free(answer);
+  errmsg = NULL;
+
+  getinfo_helper_rephist(&dummy, "stats/tap/onion_circuits_ddosed",
+                         &answer, &errmsg);
+  tt_ptr_op(answer, OP_EQ, NULL);
+  tt_str_op(errmsg, OP_EQ, "Unrecognized handshake type");
+  errmsg = NULL;
+
+ done:
+  UNMOCK(rep_hist_get_circuit_handshake_requested);
+  UNMOCK(rep_hist_get_circuit_handshake_assigned);
+  tor_free(answer);
+
+  return;
+}
+
 #ifndef COCCI
 #define PARSER_TEST(type)                                             \
   { "parse/" #type, test_controller_parse_cmd, 0, &passthrough_setup, \
@@ -2146,5 +2232,6 @@ struct testcase_t controller_tests[] = {
   { "getinfo_md_all", test_getinfo_md_all, 0, NULL, NULL },
   { "control_reply", test_control_reply, 0, NULL, NULL },
   { "control_getconf", test_control_getconf, 0, NULL, NULL },
+  { "rep_hist", test_rep_hist, 0, NULL, NULL },
   END_OF_TESTCASES
 };



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