mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-13 06:33:44 +01:00
Add regression test for #22304
This commit is contained in:
parent
8b89faf424
commit
7bc636fdc9
@ -1873,7 +1873,7 @@ getinfo_helper_listeners(control_connection_t *control_conn,
|
|||||||
|
|
||||||
/** Implementation helper for GETINFO: knows the answers for questions about
|
/** Implementation helper for GETINFO: knows the answers for questions about
|
||||||
* directory information. */
|
* directory information. */
|
||||||
static int
|
STATIC int
|
||||||
getinfo_helper_dir(control_connection_t *control_conn,
|
getinfo_helper_dir(control_connection_t *control_conn,
|
||||||
const char *question, char **answer,
|
const char *question, char **answer,
|
||||||
const char **errmsg)
|
const char **errmsg)
|
||||||
|
@ -290,6 +290,10 @@ STATIC int getinfo_helper_downloads(
|
|||||||
control_connection_t *control_conn,
|
control_connection_t *control_conn,
|
||||||
const char *question, char **answer,
|
const char *question, char **answer,
|
||||||
const char **errmsg);
|
const char **errmsg);
|
||||||
|
STATIC int getinfo_helper_dir(
|
||||||
|
control_connection_t *control_conn,
|
||||||
|
const char *question, char **answer,
|
||||||
|
const char **errmsg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3045,8 +3045,8 @@ router_get_by_extrainfo_digest,(const char *digest))
|
|||||||
/** Return the signed descriptor for the extrainfo_t in our routerlist whose
|
/** Return the signed descriptor for the extrainfo_t in our routerlist whose
|
||||||
* extra-info-digest is <b>digest</b>. Return NULL if no such extra-info
|
* extra-info-digest is <b>digest</b>. Return NULL if no such extra-info
|
||||||
* document is known. */
|
* document is known. */
|
||||||
signed_descriptor_t *
|
MOCK_IMPL(signed_descriptor_t *,
|
||||||
extrainfo_get_by_descriptor_digest(const char *digest)
|
extrainfo_get_by_descriptor_digest,(const char *digest))
|
||||||
{
|
{
|
||||||
extrainfo_t *ei;
|
extrainfo_t *ei;
|
||||||
tor_assert(digest);
|
tor_assert(digest);
|
||||||
|
@ -92,7 +92,8 @@ routerinfo_t *router_get_mutable_by_digest(const char *digest);
|
|||||||
signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
|
signed_descriptor_t *router_get_by_descriptor_digest(const char *digest);
|
||||||
MOCK_DECL(signed_descriptor_t *,router_get_by_extrainfo_digest,
|
MOCK_DECL(signed_descriptor_t *,router_get_by_extrainfo_digest,
|
||||||
(const char *digest));
|
(const char *digest));
|
||||||
signed_descriptor_t *extrainfo_get_by_descriptor_digest(const char *digest);
|
MOCK_DECL(signed_descriptor_t *,extrainfo_get_by_descriptor_digest,
|
||||||
|
(const char *digest));
|
||||||
const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
|
const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
|
||||||
const char *signed_descriptor_get_annotations(const signed_descriptor_t *desc);
|
const char *signed_descriptor_get_annotations(const signed_descriptor_t *desc);
|
||||||
routerlist_t *router_get_routerlist(void);
|
routerlist_t *router_get_routerlist(void);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define CONFIG_PRIVATE
|
#define CONFIG_PRIVATE
|
||||||
|
#define CONTROL_PRIVATE
|
||||||
#define DIRSERV_PRIVATE
|
#define DIRSERV_PRIVATE
|
||||||
#define DIRVOTE_PRIVATE
|
#define DIRVOTE_PRIVATE
|
||||||
#define ROUTER_PRIVATE
|
#define ROUTER_PRIVATE
|
||||||
@ -19,6 +20,7 @@
|
|||||||
#include "or.h"
|
#include "or.h"
|
||||||
#include "confparse.h"
|
#include "confparse.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "control.h"
|
||||||
#include "crypto_ed25519.h"
|
#include "crypto_ed25519.h"
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
#include "dirserv.h"
|
#include "dirserv.h"
|
||||||
@ -910,6 +912,23 @@ mock_get_by_ei_desc_digest(const char *d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static signed_descriptor_t *
|
||||||
|
mock_ei_get_by_ei_digest(const char *d)
|
||||||
|
{
|
||||||
|
char hex[HEX_DIGEST_LEN+1];
|
||||||
|
base16_encode(hex, sizeof(hex), d, DIGEST_LEN);
|
||||||
|
signed_descriptor_t *sd = &sd_ei_minimal;
|
||||||
|
|
||||||
|
if (!strcmp(hex, "11E0EDF526950739F7769810FCACAB8C882FAEEE")) {
|
||||||
|
sd->signed_descriptor_body = (char *)EX_EI_MINIMAL;
|
||||||
|
sd->signed_descriptor_len = sizeof(EX_EI_MINIMAL);
|
||||||
|
sd->annotations_len = 0;
|
||||||
|
sd->saved_location = SAVED_NOWHERE;
|
||||||
|
return sd;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static smartlist_t *mock_ei_insert_list = NULL;
|
static smartlist_t *mock_ei_insert_list = NULL;
|
||||||
static was_router_added_t
|
static was_router_added_t
|
||||||
mock_ei_insert(routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible)
|
mock_ei_insert(routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible)
|
||||||
@ -998,6 +1017,37 @@ test_dir_load_extrainfo(void *arg)
|
|||||||
tor_free(list);
|
tor_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_dir_getinfo_extra(void *arg)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
char *answer = NULL;
|
||||||
|
const char *errmsg = NULL;
|
||||||
|
|
||||||
|
(void)arg;
|
||||||
|
MOCK(extrainfo_get_by_descriptor_digest, mock_ei_get_by_ei_digest);
|
||||||
|
r = getinfo_helper_dir(NULL, "extra-info/digest/"
|
||||||
|
"11E0EDF526950739F7769810FCACAB8C882FAEEE", &answer,
|
||||||
|
&errmsg);
|
||||||
|
tt_int_op(0, OP_EQ, r);
|
||||||
|
tt_ptr_op(NULL, OP_EQ, errmsg);
|
||||||
|
tt_str_op(answer, OP_EQ, EX_EI_MINIMAL);
|
||||||
|
tor_free(answer);
|
||||||
|
|
||||||
|
answer = NULL;
|
||||||
|
r = getinfo_helper_dir(NULL, "extra-info/digest/"
|
||||||
|
"NOTAVALIDHEXSTRINGNOTAVALIDHEXSTRINGNOTA", &answer,
|
||||||
|
&errmsg);
|
||||||
|
tt_int_op(0, OP_EQ, r);
|
||||||
|
/* getinfo_helper_dir() should maybe return an error here but doesn't */
|
||||||
|
tt_ptr_op(NULL, OP_EQ, errmsg);
|
||||||
|
/* In any case, there should be no answer for an invalid hex string. */
|
||||||
|
tt_ptr_op(NULL, OP_EQ, answer);
|
||||||
|
|
||||||
|
done:
|
||||||
|
UNMOCK(extrainfo_get_by_descriptor_digest);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_dir_versions(void *arg)
|
test_dir_versions(void *arg)
|
||||||
{
|
{
|
||||||
@ -5970,6 +6020,7 @@ struct testcase_t dir_tests[] = {
|
|||||||
DIR(parse_router_list, TT_FORK),
|
DIR(parse_router_list, TT_FORK),
|
||||||
DIR(load_routers, TT_FORK),
|
DIR(load_routers, TT_FORK),
|
||||||
DIR(load_extrainfo, TT_FORK),
|
DIR(load_extrainfo, TT_FORK),
|
||||||
|
DIR(getinfo_extra, 0),
|
||||||
DIR_LEGACY(versions),
|
DIR_LEGACY(versions),
|
||||||
DIR_LEGACY(fp_pairs),
|
DIR_LEGACY(fp_pairs),
|
||||||
DIR(split_fps, 0),
|
DIR(split_fps, 0),
|
||||||
|
Loading…
Reference in New Issue
Block a user