|
@@ -10,6 +10,7 @@
|
|
|
#include "networkstatus.h"
|
|
|
#include "rendservice.h"
|
|
|
#include "routerlist.h"
|
|
|
+#include "nodelist.h"
|
|
|
#include "test.h"
|
|
|
#include "test_helpers.h"
|
|
|
|
|
@@ -1525,6 +1526,80 @@ test_current_time(void *arg)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+static size_t n_nodelist_get_list = 0;
|
|
|
+static smartlist_t *nodes = NULL;
|
|
|
+
|
|
|
+static smartlist_t *
|
|
|
+mock_nodelist_get_list(void)
|
|
|
+{
|
|
|
+ n_nodelist_get_list++;
|
|
|
+ tor_assert(nodes);
|
|
|
+
|
|
|
+ return nodes;
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+test_getinfo_md_all(void *arg)
|
|
|
+{
|
|
|
+ char *answer = NULL;
|
|
|
+ const char *errmsg = NULL;
|
|
|
+ int retval = 0;
|
|
|
+
|
|
|
+ (void)arg;
|
|
|
+
|
|
|
+ node_t *node1 = tor_malloc(sizeof(node_t));
|
|
|
+ memset(node1, 0, sizeof(node_t));
|
|
|
+ node1->md = tor_malloc(sizeof(microdesc_t));
|
|
|
+ memset(node1->md, 0, sizeof(microdesc_t));
|
|
|
+ node1->md->body = tor_strdup("md1\n");
|
|
|
+ node1->md->bodylen = 4;
|
|
|
+
|
|
|
+ node_t *node2 = tor_malloc(sizeof(node_t));
|
|
|
+ memset(node2, 0, sizeof(node_t));
|
|
|
+ node2->md = tor_malloc(sizeof(microdesc_t));
|
|
|
+ memset(node2->md, 0, sizeof(microdesc_t));
|
|
|
+ node2->md->body = tor_strdup("md2\n");
|
|
|
+ node2->md->bodylen = 4;
|
|
|
+
|
|
|
+ MOCK(nodelist_get_list, mock_nodelist_get_list);
|
|
|
+
|
|
|
+ nodes = smartlist_new();
|
|
|
+
|
|
|
+ retval = getinfo_helper_dir(NULL, "md/all", &answer, &errmsg);
|
|
|
+
|
|
|
+ tt_int_op(n_nodelist_get_list, OP_EQ, 1);
|
|
|
+ tt_int_op(retval, OP_EQ, 0);
|
|
|
+ tt_assert(answer != NULL);
|
|
|
+ tt_assert(errmsg == NULL);
|
|
|
+ tt_str_op(answer, OP_EQ, "");
|
|
|
+
|
|
|
+ tor_free(answer);
|
|
|
+
|
|
|
+ smartlist_add(nodes, node1);
|
|
|
+ smartlist_add(nodes, node2);
|
|
|
+
|
|
|
+ retval = getinfo_helper_dir(NULL, "md/all", &answer, &errmsg);
|
|
|
+
|
|
|
+ tt_int_op(n_nodelist_get_list, OP_EQ, 2);
|
|
|
+ tt_int_op(retval, OP_EQ, 0);
|
|
|
+ tt_assert(answer != NULL);
|
|
|
+ tt_assert(errmsg == NULL);
|
|
|
+
|
|
|
+ tt_str_op(answer, OP_EQ, "md1\nmd2\n");
|
|
|
+
|
|
|
+ done:
|
|
|
+ UNMOCK(nodelist_get_list);
|
|
|
+ tor_free(node1->md->body);
|
|
|
+ tor_free(node1->md);
|
|
|
+ tor_free(node1);
|
|
|
+ tor_free(node2->md->body);
|
|
|
+ tor_free(node2->md);
|
|
|
+ tor_free(node2);
|
|
|
+ tor_free(answer);
|
|
|
+ smartlist_free(nodes);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
struct testcase_t controller_tests[] = {
|
|
|
{ "add_onion_helper_keyarg_v2", test_add_onion_helper_keyarg_v2, 0,
|
|
|
NULL, NULL },
|
|
@@ -1542,6 +1617,7 @@ struct testcase_t controller_tests[] = {
|
|
|
{ "download_status_desc", test_download_status_desc, 0, NULL, NULL },
|
|
|
{ "download_status_bridge", test_download_status_bridge, 0, NULL, NULL },
|
|
|
{ "current_time", test_current_time, 0, NULL, NULL },
|
|
|
+ { "getinfo_md_all", test_getinfo_md_all, 0, NULL, NULL },
|
|
|
END_OF_TESTCASES
|
|
|
};
|
|
|
|