mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Merge remote-tracking branch 'dgoulet/ticket16943_029_05-squashed'
Trivial Conflicts: src/or/or.h src/or/routerparse.c
This commit is contained in:
+84
-3
@@ -31,6 +31,7 @@
|
||||
#include "routerlist.h"
|
||||
#include "routerparse.h"
|
||||
#include "routerset.h"
|
||||
#include "shared_random_state.h"
|
||||
#include "test.h"
|
||||
#include "test_dir_common.h"
|
||||
#include "torcert.h"
|
||||
@@ -1436,6 +1437,19 @@ test_dir_measured_bw_kb_cache(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
static char *
|
||||
my_dirvote_compute_params(smartlist_t *votes, int method, int total_authorities)
|
||||
{
|
||||
smartlist_t *s = dirvote_compute_params(votes, method, total_authorities);
|
||||
tor_assert(s);
|
||||
char *res = smartlist_join_strings(s, " ", 0, NULL);
|
||||
SMARTLIST_FOREACH(s, char *, cp, tor_free(cp));
|
||||
smartlist_free(s);
|
||||
return res;
|
||||
}
|
||||
|
||||
#define dirvote_compute_params my_dirvote_compute_params
|
||||
|
||||
static void
|
||||
test_dir_param_voting(void *arg)
|
||||
{
|
||||
@@ -1545,6 +1559,43 @@ test_dir_param_voting(void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
test_dir_param_voting_lookup(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
smartlist_t *lst = smartlist_new();
|
||||
|
||||
smartlist_split_string(lst,
|
||||
"moomin=9 moomin=10 moomintroll=5 fred "
|
||||
"jack= electricity=sdk opa=6z abc=9 abcd=99",
|
||||
NULL, 0, 0);
|
||||
|
||||
tt_int_op(1000,
|
||||
OP_EQ, dirvote_get_intermediate_param_value(lst, "ab", 1000));
|
||||
tt_int_op(9, OP_EQ, dirvote_get_intermediate_param_value(lst, "abc", 1000));
|
||||
tt_int_op(99, OP_EQ, dirvote_get_intermediate_param_value(lst, "abcd", 1000));
|
||||
|
||||
/* moomin appears twice. */
|
||||
tt_int_op(-100, OP_EQ,
|
||||
dirvote_get_intermediate_param_value(lst, "moomin", -100));
|
||||
/* fred and jack are truncated */
|
||||
tt_int_op(-100, OP_EQ,
|
||||
dirvote_get_intermediate_param_value(lst, "fred", -100));
|
||||
tt_int_op(-100, OP_EQ,
|
||||
dirvote_get_intermediate_param_value(lst, "jack", -100));
|
||||
/* electricity and opa aren't integers. */
|
||||
tt_int_op(-100, OP_EQ,
|
||||
dirvote_get_intermediate_param_value(lst, "electricity", -100));
|
||||
tt_int_op(-100, OP_EQ,
|
||||
dirvote_get_intermediate_param_value(lst, "opa", -100));
|
||||
|
||||
done:
|
||||
SMARTLIST_FOREACH(lst, char *, cp, tor_free(cp));
|
||||
smartlist_free(lst);
|
||||
}
|
||||
|
||||
#undef dirvote_compute_params
|
||||
|
||||
/** Helper: Test that two networkstatus_voter_info_t do in fact represent the
|
||||
* same voting authority, and that they do in fact have all the same
|
||||
* information. */
|
||||
@@ -1789,6 +1840,15 @@ test_routerstatus_for_v3ns(routerstatus_t *rs, time_t now)
|
||||
return;
|
||||
}
|
||||
|
||||
static authority_cert_t *mock_cert;
|
||||
|
||||
static authority_cert_t *
|
||||
get_my_v3_authority_cert_m(void)
|
||||
{
|
||||
tor_assert(mock_cert);
|
||||
return mock_cert;
|
||||
}
|
||||
|
||||
/** Run a unit tests for generating and parsing networkstatuses, with
|
||||
* the supply test fns. */
|
||||
static void
|
||||
@@ -1832,10 +1892,30 @@ test_a_networkstatus(
|
||||
tt_assert(rs_test);
|
||||
tt_assert(vrs_test);
|
||||
|
||||
tt_assert(!dir_common_authority_pk_init(&cert1, &cert2, &cert3,
|
||||
&sign_skey_1, &sign_skey_2,
|
||||
&sign_skey_3));
|
||||
MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
|
||||
|
||||
/* Parse certificates and keys. */
|
||||
cert1 = mock_cert = authority_cert_parse_from_string(AUTHORITY_CERT_1, NULL);
|
||||
tt_assert(cert1);
|
||||
cert2 = authority_cert_parse_from_string(AUTHORITY_CERT_2, NULL);
|
||||
tt_assert(cert2);
|
||||
cert3 = authority_cert_parse_from_string(AUTHORITY_CERT_3, NULL);
|
||||
tt_assert(cert3);
|
||||
sign_skey_1 = crypto_pk_new();
|
||||
sign_skey_2 = crypto_pk_new();
|
||||
sign_skey_3 = crypto_pk_new();
|
||||
sign_skey_leg1 = pk_generate(4);
|
||||
sr_state_init(0, 0);
|
||||
|
||||
tt_assert(!crypto_pk_read_private_key_from_string(sign_skey_1,
|
||||
AUTHORITY_SIGNKEY_1, -1));
|
||||
tt_assert(!crypto_pk_read_private_key_from_string(sign_skey_2,
|
||||
AUTHORITY_SIGNKEY_2, -1));
|
||||
tt_assert(!crypto_pk_read_private_key_from_string(sign_skey_3,
|
||||
AUTHORITY_SIGNKEY_3, -1));
|
||||
|
||||
tt_assert(!crypto_pk_cmp_keys(sign_skey_1, cert1->signing_key));
|
||||
tt_assert(!crypto_pk_cmp_keys(sign_skey_2, cert2->signing_key));
|
||||
|
||||
tt_assert(!dir_common_construct_vote_1(&vote, cert1, sign_skey_1, vrs_gen,
|
||||
&v1, &n_vrs, now, 1));
|
||||
@@ -5287,6 +5367,7 @@ struct testcase_t dir_tests[] = {
|
||||
DIR_LEGACY(measured_bw_kb),
|
||||
DIR_LEGACY(measured_bw_kb_cache),
|
||||
DIR_LEGACY(param_voting),
|
||||
DIR(param_voting_lookup, 0),
|
||||
DIR_LEGACY(v3_networkstatus),
|
||||
DIR(random_weighted, 0),
|
||||
DIR(scale_bw, 0),
|
||||
|
||||
Reference in New Issue
Block a user