mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
apply ahf's test_assert_int.cocci
This commit is contained in:
parent
0b36208fd8
commit
047790a253
@ -409,11 +409,11 @@ test_circuit_timeout(void *arg)
|
||||
} while (fabs(circuit_build_times_cdf(&initial, timeout0) -
|
||||
circuit_build_times_cdf(&initial, timeout1)) > 0.02);
|
||||
|
||||
tt_assert(estimate.total_build_times <= CBT_NCIRCUITS_TO_OBSERVE);
|
||||
tt_int_op(estimate.total_build_times, OP_LE, CBT_NCIRCUITS_TO_OBSERVE);
|
||||
|
||||
circuit_build_times_update_state(&estimate, state);
|
||||
circuit_build_times_free_timeouts(&final);
|
||||
tt_assert(circuit_build_times_parse_state(&final, state) == 0);
|
||||
tt_int_op(circuit_build_times_parse_state(&final, state), OP_EQ, 0);
|
||||
|
||||
circuit_build_times_update_alpha(&final);
|
||||
timeout2 = circuit_build_times_calculate_timeout(&final,
|
||||
@ -491,7 +491,7 @@ test_circuit_timeout(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
tt_assert(estimate.liveness.after_firsthop_idx == 0);
|
||||
tt_int_op(estimate.liveness.after_firsthop_idx, OP_EQ, 0);
|
||||
tt_assert(final.liveness.after_firsthop_idx ==
|
||||
CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT-1);
|
||||
|
||||
@ -571,20 +571,15 @@ test_rend_fns(void *arg)
|
||||
intro->intro_key = crypto_pk_dup_key(pk2);
|
||||
smartlist_add(generated->intro_nodes, intro);
|
||||
}
|
||||
tt_assert(rend_encode_v2_descriptors(descs, generated, now, 0,
|
||||
REND_NO_AUTH, NULL, NULL) > 0);
|
||||
tt_assert(rend_compute_v2_desc_id(computed_desc_id, service_id_base32,
|
||||
NULL, now, 0) == 0);
|
||||
tt_int_op(rend_encode_v2_descriptors(descs, generated, now, 0, REND_NO_AUTH, NULL, NULL),
|
||||
OP_GT, 0);
|
||||
tt_int_op(rend_compute_v2_desc_id(computed_desc_id, service_id_base32, NULL, now, 0),
|
||||
OP_EQ, 0);
|
||||
tt_mem_op(((rend_encoded_v2_service_descriptor_t *)
|
||||
smartlist_get(descs, 0))->desc_id, OP_EQ,
|
||||
computed_desc_id, DIGEST_LEN);
|
||||
tt_assert(rend_parse_v2_service_descriptor(&parsed, parsed_desc_id,
|
||||
&intro_points_encrypted,
|
||||
&intro_points_size,
|
||||
&encoded_size,
|
||||
&next_desc,
|
||||
((rend_encoded_v2_service_descriptor_t *)
|
||||
smartlist_get(descs, 0))->desc_str, 1) == 0);
|
||||
tt_int_op(rend_parse_v2_service_descriptor(&parsed, parsed_desc_id, &intro_points_encrypted, &intro_points_size, &encoded_size, &next_desc, ((rend_encoded_v2_service_descriptor_t *)smartlist_get(descs, 0))->desc_str, 1),
|
||||
OP_EQ, 0);
|
||||
tt_assert(parsed);
|
||||
tt_mem_op(((rend_encoded_v2_service_descriptor_t *)
|
||||
smartlist_get(descs, 0))->desc_id,OP_EQ, parsed_desc_id, DIGEST_LEN);
|
||||
|
@ -451,10 +451,10 @@ test_addr_ip6_helpers(void *arg)
|
||||
"::ffff:6.0.0.0"); /* XXXX wrong. */
|
||||
tor_addr_parse_mask_ports("[::ffff:2.3.4.5]", 0, &t1, NULL, NULL, NULL);
|
||||
tor_addr_parse_mask_ports("2.3.4.5", 0, &t2, NULL, NULL, NULL);
|
||||
tt_assert(tor_addr_compare(&t1, &t2, CMP_SEMANTIC) == 0);
|
||||
tt_int_op(tor_addr_compare(&t1, &t2, CMP_SEMANTIC), OP_EQ, 0);
|
||||
tor_addr_parse_mask_ports("[::ffff:2.3.4.4]", 0, &t1, NULL, NULL, NULL);
|
||||
tor_addr_parse_mask_ports("2.3.4.5", 0, &t2, NULL, NULL, NULL);
|
||||
tt_assert(tor_addr_compare(&t1, &t2, CMP_SEMANTIC) < 0);
|
||||
tt_int_op(tor_addr_compare(&t1, &t2, CMP_SEMANTIC), OP_LT, 0);
|
||||
|
||||
/* test compare_masked */
|
||||
test_addr_compare_masked("ffff::", OP_EQ, "ffff::0", 128);
|
||||
@ -637,7 +637,7 @@ test_addr_ip6_helpers(void *arg)
|
||||
/* Try some long addresses. */
|
||||
r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:1111]",
|
||||
0, &t1, NULL, NULL, NULL);
|
||||
tt_assert(r == AF_INET6);
|
||||
tt_int_op(r, OP_EQ, AF_INET6);
|
||||
r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:11111]",
|
||||
0, &t1, NULL, NULL, NULL);
|
||||
tt_int_op(r, OP_EQ, -1);
|
||||
@ -686,38 +686,38 @@ test_addr_ip6_helpers(void *arg)
|
||||
tt_int_op(r, OP_EQ, -1);
|
||||
r=tor_addr_parse_mask_ports("*6",0,&t1, &mask, NULL, NULL);
|
||||
tt_int_op(r, OP_EQ, -1);
|
||||
tt_assert(r == -1);
|
||||
tt_int_op(r, OP_EQ, -1);
|
||||
/* Try a mask with a wildcard. */
|
||||
r=tor_addr_parse_mask_ports("*/16",0,&t1, &mask, NULL, NULL);
|
||||
tt_assert(r == -1);
|
||||
tt_int_op(r, OP_EQ, -1);
|
||||
r=tor_addr_parse_mask_ports("*4/16",TAPMP_EXTENDED_STAR,
|
||||
&t1, &mask, NULL, NULL);
|
||||
tt_assert(r == -1);
|
||||
tt_int_op(r, OP_EQ, -1);
|
||||
r=tor_addr_parse_mask_ports("*6/30",TAPMP_EXTENDED_STAR,
|
||||
&t1, &mask, NULL, NULL);
|
||||
tt_assert(r == -1);
|
||||
tt_int_op(r, OP_EQ, -1);
|
||||
/* Basic mask tests*/
|
||||
r=tor_addr_parse_mask_ports("1.1.2.2/31",0,&t1, &mask, NULL, NULL);
|
||||
tt_assert(r == AF_INET);
|
||||
tt_int_op(r, OP_EQ, AF_INET);
|
||||
tt_int_op(mask,OP_EQ,31);
|
||||
tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
|
||||
tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0x01010202);
|
||||
r=tor_addr_parse_mask_ports("3.4.16.032:1-2",0,&t1, &mask, &port1, &port2);
|
||||
tt_assert(r == AF_INET);
|
||||
tt_int_op(r, OP_EQ, AF_INET);
|
||||
tt_int_op(mask,OP_EQ,32);
|
||||
tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
|
||||
tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0x03041020);
|
||||
tt_assert(port1 == 1);
|
||||
tt_assert(port2 == 2);
|
||||
tt_uint_op(port1, OP_EQ, 1);
|
||||
tt_uint_op(port2, OP_EQ, 2);
|
||||
r=tor_addr_parse_mask_ports("1.1.2.3/255.255.128.0",0,&t1, &mask,NULL,NULL);
|
||||
tt_assert(r == AF_INET);
|
||||
tt_int_op(r, OP_EQ, AF_INET);
|
||||
tt_int_op(mask,OP_EQ,17);
|
||||
tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
|
||||
tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0x01010203);
|
||||
r=tor_addr_parse_mask_ports("[efef::]/112",0,&t1, &mask, &port1, &port2);
|
||||
tt_assert(r == AF_INET6);
|
||||
tt_assert(port1 == 1);
|
||||
tt_assert(port2 == 65535);
|
||||
tt_int_op(r, OP_EQ, AF_INET6);
|
||||
tt_uint_op(port1, OP_EQ, 1);
|
||||
tt_uint_op(port2, OP_EQ, 65535);
|
||||
/* Try regular wildcard behavior without TAPMP_EXTENDED_STAR */
|
||||
r=tor_addr_parse_mask_ports("*:80-443",0,&t1,&mask,&port1,&port2);
|
||||
tt_int_op(r,OP_EQ,AF_INET); /* Old users of this always get inet */
|
||||
@ -752,9 +752,9 @@ test_addr_ip6_helpers(void *arg)
|
||||
tt_int_op(port2,OP_EQ,65535);
|
||||
|
||||
/* make sure inet address lengths >= max */
|
||||
tt_assert(INET_NTOA_BUF_LEN >= sizeof("255.255.255.255"));
|
||||
tt_assert(TOR_ADDR_BUF_LEN >=
|
||||
sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"));
|
||||
tt_int_op(INET_NTOA_BUF_LEN, OP_GE, sizeof("255.255.255.255"));
|
||||
tt_int_op(TOR_ADDR_BUF_LEN, OP_GE,
|
||||
sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"));
|
||||
|
||||
tt_assert(sizeof(tor_addr_t) >= sizeof(struct in6_addr));
|
||||
|
||||
|
@ -224,7 +224,7 @@ test_address_ifaddrs_to_smartlist(void *arg)
|
||||
smartlist = ifaddrs_to_smartlist(ifa, AF_UNSPEC);
|
||||
|
||||
tt_assert(smartlist);
|
||||
tt_assert(smartlist_len(smartlist) == 3);
|
||||
tt_int_op(smartlist_len(smartlist), OP_EQ, 3);
|
||||
|
||||
sockaddr_to_check = tor_malloc(sizeof(struct sockaddr_in6));
|
||||
|
||||
@ -384,7 +384,7 @@ test_address_ip_adapter_addresses_to_smartlist(void *arg)
|
||||
result = ip_adapter_addresses_to_smartlist(addrs1);
|
||||
|
||||
tt_assert(result);
|
||||
tt_assert(smartlist_len(result) == 3);
|
||||
tt_int_op(smartlist_len(result), OP_EQ, 3);
|
||||
|
||||
tor_addr = smartlist_get(result,0);
|
||||
|
||||
@ -730,7 +730,7 @@ test_address_udp_socket_trick_blackbox(void *arg)
|
||||
retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
|
||||
AF_INET+AF_INET6,&addr4);
|
||||
|
||||
tt_assert(retval == -1);
|
||||
tt_int_op(retval, OP_EQ, -1);
|
||||
|
||||
done:
|
||||
return;
|
||||
@ -935,10 +935,10 @@ test_address_get_if_addrs_internal_fail(void *arg)
|
||||
tt_int_op(smartlist_len(results2),OP_EQ,0);
|
||||
|
||||
rv = get_interface_address6(LOG_ERR, AF_INET6, &ipv6_addr);
|
||||
tt_assert(rv == -1);
|
||||
tt_int_op(rv, OP_EQ, -1);
|
||||
|
||||
rv = get_interface_address(LOG_ERR, &ipv4h_addr);
|
||||
tt_assert(rv == -1);
|
||||
tt_int_op(rv, OP_EQ, -1);
|
||||
|
||||
done:
|
||||
UNMOCK(get_interface_addresses_raw);
|
||||
|
@ -1780,7 +1780,7 @@ test_channel_id_map(void *arg)
|
||||
ed25519_public_key_t ed_zero;
|
||||
memset(&ed_zero, 0, sizeof(ed_zero));
|
||||
|
||||
tt_assert(sizeof(rsa_id[0]) == DIGEST_LEN); // Do I remember C?
|
||||
tt_int_op(DIGEST_LEN, OP_EQ, sizeof(rsa_id[0])); // Do I remember C?
|
||||
|
||||
for (i = 0; i < N_CHAN; ++i) {
|
||||
crypto_rand(rsa_id[i], DIGEST_LEN);
|
||||
|
@ -274,7 +274,7 @@ tlschan_connection_or_connect_mock(const tor_addr_t *addr,
|
||||
(void) ed_id; // XXXX Not yet used.
|
||||
|
||||
tt_assert(addr != NULL);
|
||||
tt_assert(port != 0);
|
||||
tt_uint_op(port, OP_NE, 0);
|
||||
tt_assert(digest != NULL);
|
||||
tt_assert(tlschan != NULL);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -70,7 +70,7 @@ test_conn_lookup_addr_helper(const char *address, int family, tor_addr_t *addr)
|
||||
|
||||
rv = tor_addr_lookup(address, family, addr);
|
||||
/* XXXX - should we retry on transient failure? */
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(tor_addr_is_loopback(addr));
|
||||
tt_assert(tor_addr_is_v4(addr));
|
||||
|
||||
@ -292,7 +292,7 @@ test_conn_download_status_teardown(const struct testcase_t *tc, void *arg)
|
||||
|
||||
/* connection_free_() cleans up requested_resource */
|
||||
rv = test_conn_get_rsrc_teardown(tc, conn);
|
||||
tt_assert(rv == 1);
|
||||
tt_int_op(rv, OP_EQ, 1);
|
||||
}
|
||||
} SMARTLIST_FOREACH_END(conn);
|
||||
|
||||
@ -485,7 +485,7 @@ test_conn_get_rend(void *arg)
|
||||
#define sl_is_conn_assert(sl_input, conn) \
|
||||
do { \
|
||||
the_sl = (sl_input); \
|
||||
tt_assert(smartlist_len((the_sl)) == 1); \
|
||||
tt_int_op(smartlist_len((the_sl)), OP_EQ, 1); \
|
||||
tt_assert(smartlist_get((the_sl), 0) == (conn)); \
|
||||
smartlist_free(the_sl); the_sl = NULL; \
|
||||
} while (0)
|
||||
@ -493,7 +493,7 @@ test_conn_get_rend(void *arg)
|
||||
#define sl_no_conn_assert(sl_input) \
|
||||
do { \
|
||||
the_sl = (sl_input); \
|
||||
tt_assert(smartlist_len((the_sl)) == 0); \
|
||||
tt_int_op(smartlist_len((the_sl)), OP_EQ, 0); \
|
||||
smartlist_free(the_sl); the_sl = NULL; \
|
||||
} while (0)
|
||||
|
||||
@ -539,43 +539,23 @@ test_conn_get_rsrc(void *arg)
|
||||
TEST_CONN_RSRC_2,
|
||||
!TEST_CONN_STATE));
|
||||
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
conn->base_.purpose,
|
||||
conn->requested_resource)
|
||||
== 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
TEST_CONN_RSRC)
|
||||
== 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
!conn->base_.purpose,
|
||||
"")
|
||||
== 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
!TEST_CONN_RSRC_PURPOSE,
|
||||
TEST_CONN_RSRC_2)
|
||||
== 0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(conn->base_.purpose, conn->requested_resource),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, TEST_CONN_RSRC),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(!conn->base_.purpose, ""),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(!TEST_CONN_RSRC_PURPOSE, TEST_CONN_RSRC_2),
|
||||
OP_EQ, 0);
|
||||
|
||||
tt_assert(connection_dir_count_by_purpose_resource_and_state(
|
||||
conn->base_.purpose,
|
||||
conn->requested_resource,
|
||||
conn->base_.state)
|
||||
== 1);
|
||||
tt_assert(connection_dir_count_by_purpose_resource_and_state(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
TEST_CONN_RSRC,
|
||||
TEST_CONN_STATE)
|
||||
== 1);
|
||||
tt_assert(connection_dir_count_by_purpose_resource_and_state(
|
||||
!conn->base_.purpose,
|
||||
"",
|
||||
!conn->base_.state)
|
||||
== 0);
|
||||
tt_assert(connection_dir_count_by_purpose_resource_and_state(
|
||||
!TEST_CONN_RSRC_PURPOSE,
|
||||
TEST_CONN_RSRC_2,
|
||||
!TEST_CONN_STATE)
|
||||
== 0);
|
||||
tt_int_op(connection_dir_count_by_purpose_resource_and_state(conn->base_.purpose, conn->requested_resource, conn->base_.state),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_resource_and_state(TEST_CONN_RSRC_PURPOSE, TEST_CONN_RSRC, TEST_CONN_STATE),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_resource_and_state(!conn->base_.purpose, "", !conn->base_.state),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(connection_dir_count_by_purpose_resource_and_state(!TEST_CONN_RSRC_PURPOSE, TEST_CONN_RSRC_2, !TEST_CONN_STATE),
|
||||
OP_EQ, 0);
|
||||
|
||||
done:
|
||||
smartlist_free(the_sl);
|
||||
@ -601,117 +581,107 @@ test_conn_download_status(void *arg)
|
||||
const char *other_res = networkstatus_get_flavor_name(other_flavor);
|
||||
|
||||
/* no connections */
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 0);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* one connection, not downloading */
|
||||
conn = test_conn_download_status_add_a_connection(res);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 0);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* one connection, downloading but not linked (not possible on a client,
|
||||
* but possible on a relay) */
|
||||
conn->base_.state = TEST_CONN_DL_STATE;
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 0);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* one connection, downloading and linked, but not yet attached */
|
||||
ap_conn = test_conn_get_linked_connection(TO_CONN(conn),
|
||||
TEST_CONN_UNATTACHED_STATE);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 0);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* one connection, downloading and linked and attached */
|
||||
ap_conn->state = TEST_CONN_ATTACHED_STATE;
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 1);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* one connection, linked and attached but not downloading */
|
||||
conn->base_.state = TEST_CONN_STATE;
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 0);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* two connections, both not downloading */
|
||||
conn2 = test_conn_download_status_add_a_connection(res);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 0);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 2);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 2);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* two connections, one downloading */
|
||||
conn->base_.state = TEST_CONN_DL_STATE;
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 1);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 2);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 2);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
conn->base_.state = TEST_CONN_STATE;
|
||||
|
||||
/* more connections, all not downloading */
|
||||
/* ignore the return value, it's free'd using the connection list */
|
||||
(void)test_conn_download_status_add_a_connection(res);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 0);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 3);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 3);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* more connections, one downloading */
|
||||
conn->base_.state = TEST_CONN_DL_STATE;
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 1);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 3);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 3);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* more connections, two downloading (should never happen, but needs
|
||||
* to be tested for completeness) */
|
||||
@ -719,38 +689,35 @@ test_conn_download_status(void *arg)
|
||||
/* ignore the return value, it's free'd using the connection list */
|
||||
(void)test_conn_get_linked_connection(TO_CONN(conn2),
|
||||
TEST_CONN_ATTACHED_STATE);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 1);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 3);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 3);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
conn->base_.state = TEST_CONN_STATE;
|
||||
|
||||
/* more connections, a different one downloading */
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 1);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 3);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 0);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 3);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* a connection for the other flavor (could happen if a client is set to
|
||||
* cache directory documents), one preferred flavor downloading
|
||||
*/
|
||||
conn4 = test_conn_download_status_add_a_connection(other_res);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 1);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 0);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 3);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
0);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 3);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 1);
|
||||
|
||||
/* a connection for the other flavor (could happen if a client is set to
|
||||
* cache directory documents), both flavors downloading
|
||||
@ -759,14 +726,13 @@ test_conn_download_status(void *arg)
|
||||
/* ignore the return value, it's free'd using the connection list */
|
||||
(void)test_conn_get_linked_connection(TO_CONN(conn4),
|
||||
TEST_CONN_ATTACHED_STATE);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(res) == 1);
|
||||
tt_assert(networkstatus_consensus_is_already_downloading(other_res) == 1);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
res) == 3);
|
||||
tt_assert(connection_dir_count_by_purpose_and_resource(
|
||||
TEST_CONN_RSRC_PURPOSE,
|
||||
other_res) == 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(res), OP_EQ, 1);
|
||||
tt_int_op(networkstatus_consensus_is_already_downloading(other_res), OP_EQ,
|
||||
1);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, res),
|
||||
OP_EQ, 3);
|
||||
tt_int_op(connection_dir_count_by_purpose_and_resource(TEST_CONN_RSRC_PURPOSE, other_res),
|
||||
OP_EQ, 1);
|
||||
|
||||
done:
|
||||
/* the teardown function removes all the connections in the global list*/;
|
||||
|
@ -73,7 +73,7 @@ test_add_onion_helper_keyarg(void *arg)
|
||||
tt_assert(!key_new_alg);
|
||||
tt_assert(!key_new_blob);
|
||||
tt_assert(!err_msg);
|
||||
tt_assert(crypto_pk_cmp_keys(pk, pk2) == 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(pk, pk2), OP_EQ, 0);
|
||||
|
||||
/* Test loading a invalid key type. */
|
||||
tor_free(arg_str);
|
||||
@ -123,13 +123,13 @@ test_getinfo_helper_onion(void *arg)
|
||||
|
||||
/* successfully get an empty answer */
|
||||
rt = getinfo_helper_onions(&dummy, "onions/current", &answer, &errmsg);
|
||||
tt_assert(rt == 0);
|
||||
tt_int_op(rt, OP_EQ, 0);
|
||||
tt_str_op(answer, OP_EQ, "");
|
||||
tor_free(answer);
|
||||
|
||||
/* successfully get an empty answer */
|
||||
rt = getinfo_helper_onions(&dummy, "onions/detached", &answer, &errmsg);
|
||||
tt_assert(rt == 0);
|
||||
tt_int_op(rt, OP_EQ, 0);
|
||||
tt_str_op(answer, OP_EQ, "");
|
||||
tor_free(answer);
|
||||
|
||||
@ -138,7 +138,7 @@ test_getinfo_helper_onion(void *arg)
|
||||
dummy.ephemeral_onion_services = smartlist_new();
|
||||
smartlist_add(dummy.ephemeral_onion_services, service_id);
|
||||
rt = getinfo_helper_onions(&dummy, "onions/current", &answer, &errmsg);
|
||||
tt_assert(rt == 0);
|
||||
tt_int_op(rt, OP_EQ, 0);
|
||||
tt_str_op(answer, OP_EQ, "dummy_onion_id");
|
||||
|
||||
done:
|
||||
|
@ -1208,12 +1208,12 @@ test_crypto_pk(void *arg)
|
||||
tt_assert(! crypto_pk_write_private_key_to_filename(pk1,
|
||||
get_fname("pkey1")));
|
||||
/* failing case for read: can't read. */
|
||||
tt_assert(crypto_pk_read_private_key_from_filename(pk2,
|
||||
get_fname("xyzzy")) < 0);
|
||||
tt_int_op(crypto_pk_read_private_key_from_filename(pk2, get_fname("xyzzy")),
|
||||
OP_LT, 0);
|
||||
write_str_to_file(get_fname("xyzzy"), "foobar", 6);
|
||||
/* Failing case for read: no key. */
|
||||
tt_assert(crypto_pk_read_private_key_from_filename(pk2,
|
||||
get_fname("xyzzy")) < 0);
|
||||
tt_int_op(crypto_pk_read_private_key_from_filename(pk2, get_fname("xyzzy")),
|
||||
OP_LT, 0);
|
||||
tt_assert(! crypto_pk_read_private_key_from_filename(pk2,
|
||||
get_fname("pkey1")));
|
||||
tt_int_op(15,OP_EQ,
|
||||
@ -1245,7 +1245,7 @@ test_crypto_pk(void *arg)
|
||||
i = crypto_pk_asn1_encode(pk1, data1, 1024);
|
||||
tt_int_op(i, OP_GT, 0);
|
||||
pk2 = crypto_pk_asn1_decode(data1, i);
|
||||
tt_assert(crypto_pk_cmp_keys(pk1,pk2) == 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(pk1, pk2), OP_EQ, 0);
|
||||
|
||||
/* Try with hybrid encryption wrappers. */
|
||||
crypto_rand(data1, 1024);
|
||||
@ -1266,7 +1266,7 @@ test_crypto_pk(void *arg)
|
||||
pk2 = crypto_pk_copy_full(pk1);
|
||||
tt_assert(pk2 != NULL);
|
||||
tt_ptr_op(pk1, OP_NE, pk2);
|
||||
tt_assert(crypto_pk_cmp_keys(pk1,pk2) == 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(pk1, pk2), OP_EQ, 0);
|
||||
|
||||
done:
|
||||
if (pk1)
|
||||
@ -1344,7 +1344,7 @@ test_crypto_pk_base64(void *arg)
|
||||
/* Test decoding a valid key. */
|
||||
pk2 = crypto_pk_base64_decode(encoded, strlen(encoded));
|
||||
tt_assert(pk2);
|
||||
tt_assert(crypto_pk_cmp_keys(pk1,pk2) == 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(pk1, pk2), OP_EQ, 0);
|
||||
crypto_pk_free(pk2);
|
||||
|
||||
/* Test decoding a invalid key (not Base64). */
|
||||
@ -1495,7 +1495,7 @@ test_crypto_formats(void *arg)
|
||||
tt_mem_op(data1,OP_EQ, data3, DIGEST_LEN);
|
||||
tt_int_op(99,OP_EQ, data3[DIGEST_LEN+1]);
|
||||
|
||||
tt_assert(digest_from_base64(data3, "###") < 0);
|
||||
tt_int_op(digest_from_base64(data3, "###"), OP_LT, 0);
|
||||
|
||||
/* Encoding SHA256 */
|
||||
crypto_rand(data2, DIGEST256_LEN);
|
||||
@ -2936,17 +2936,17 @@ test_crypto_failure_modes(void *arg)
|
||||
(void)arg;
|
||||
|
||||
rv = crypto_early_init();
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
|
||||
/* Check random works */
|
||||
rv = crypto_rand_check_failure_mode_zero();
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
|
||||
rv = crypto_rand_check_failure_mode_identical();
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
|
||||
rv = crypto_rand_check_failure_mode_predict();
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
;
|
||||
|
@ -516,7 +516,7 @@ test_crypto_ed25519_fuzz_donna(void *arg)
|
||||
unsigned i;
|
||||
(void)arg;
|
||||
|
||||
tt_assert(sizeof(msg) == iters);
|
||||
tt_uint_op(iters, OP_EQ, sizeof(msg));
|
||||
crypto_rand((char*) msg, sizeof(msg));
|
||||
|
||||
/* Fuzz Ed25519-donna vs ref10, alternating the implementation used to
|
||||
|
@ -275,8 +275,8 @@ test_dir_formats(void *arg)
|
||||
tt_int_op(rp1->bandwidthrate,OP_EQ, r1->bandwidthrate);
|
||||
tt_int_op(rp1->bandwidthburst,OP_EQ, r1->bandwidthburst);
|
||||
tt_int_op(rp1->bandwidthcapacity,OP_EQ, r1->bandwidthcapacity);
|
||||
tt_assert(crypto_pk_cmp_keys(rp1->onion_pkey, pk1) == 0);
|
||||
tt_assert(crypto_pk_cmp_keys(rp1->identity_pkey, pk2) == 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(rp1->onion_pkey, pk1), OP_EQ, 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(rp1->identity_pkey, pk2), OP_EQ, 0);
|
||||
tt_assert(rp1->supports_tunnelled_dir_requests);
|
||||
//tt_assert(rp1->exit_policy == NULL);
|
||||
tor_free(buf);
|
||||
@ -294,9 +294,8 @@ test_dir_formats(void *arg)
|
||||
strlcat(buf2, "master-key-ed25519 ", sizeof(buf2));
|
||||
{
|
||||
char k[ED25519_BASE64_LEN+1];
|
||||
tt_assert(ed25519_public_to_base64(k,
|
||||
&r2->cache_info.signing_key_cert->signing_key)
|
||||
>= 0);
|
||||
tt_int_op(ed25519_public_to_base64(k, &r2->cache_info.signing_key_cert->signing_key),
|
||||
OP_GE, 0);
|
||||
strlcat(buf2, k, sizeof(buf2));
|
||||
strlcat(buf2, "\n", sizeof(buf2));
|
||||
}
|
||||
@ -392,8 +391,8 @@ test_dir_formats(void *arg)
|
||||
tt_mem_op(rp2->onion_curve25519_pkey->public_key,OP_EQ,
|
||||
r2->onion_curve25519_pkey->public_key,
|
||||
CURVE25519_PUBKEY_LEN);
|
||||
tt_assert(crypto_pk_cmp_keys(rp2->onion_pkey, pk2) == 0);
|
||||
tt_assert(crypto_pk_cmp_keys(rp2->identity_pkey, pk1) == 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(rp2->onion_pkey, pk2), OP_EQ, 0);
|
||||
tt_int_op(crypto_pk_cmp_keys(rp2->identity_pkey, pk1), OP_EQ, 0);
|
||||
tt_assert(rp2->supports_tunnelled_dir_requests);
|
||||
|
||||
tt_int_op(smartlist_len(rp2->exit_policy),OP_EQ, 2);
|
||||
@ -1537,12 +1536,12 @@ test_dir_measured_bw_kb(void *arg)
|
||||
(void)arg;
|
||||
for (i = 0; strcmp(lines_fail[i], "end"); i++) {
|
||||
//fprintf(stderr, "Testing: %s\n", lines_fail[i]);
|
||||
tt_assert(measured_bw_line_parse(&mbwl, lines_fail[i]) == -1);
|
||||
tt_int_op(measured_bw_line_parse(&mbwl, lines_fail[i]), OP_EQ, -1);
|
||||
}
|
||||
|
||||
for (i = 0; strcmp(lines_pass[i], "end"); i++) {
|
||||
//fprintf(stderr, "Testing: %s %d\n", lines_pass[i], TOR_ISSPACE('\n'));
|
||||
tt_assert(measured_bw_line_parse(&mbwl, lines_pass[i]) == 0);
|
||||
tt_int_op(measured_bw_line_parse(&mbwl, lines_pass[i]), OP_EQ, 0);
|
||||
tt_assert(mbwl.bw_kb == 1024);
|
||||
tt_assert(strcmp(mbwl.node_hex,
|
||||
"557365204145532d32353620696e73746561642e") == 0);
|
||||
@ -1873,8 +1872,7 @@ vote_tweaks_for_v3ns(networkstatus_t *v, int voter, time_t now)
|
||||
measured_bw_line_t mbw;
|
||||
memset(mbw.node_id, 33, sizeof(mbw.node_id));
|
||||
mbw.bw_kb = 1024;
|
||||
tt_assert(measured_bw_line_apply(&mbw,
|
||||
v->routerstatus_list) == 1);
|
||||
tt_int_op(measured_bw_line_apply(&mbw, v->routerstatus_list), OP_EQ, 1);
|
||||
} else if (voter == 2 || voter == 3) {
|
||||
/* Monkey around with the list a bit */
|
||||
vrs = smartlist_get(v->routerstatus_list, 2);
|
||||
@ -3162,7 +3160,7 @@ test_consensus_for_umbw(networkstatus_t *con, time_t now)
|
||||
tt_assert(con);
|
||||
tt_assert(!con->cert);
|
||||
// tt_assert(con->consensus_method >= MIN_METHOD_TO_CLIP_UNMEASURED_BW_KB);
|
||||
tt_assert(con->consensus_method >= 16);
|
||||
tt_int_op(con->consensus_method, OP_GE, 16);
|
||||
tt_int_op(4,OP_EQ, smartlist_len(con->routerstatus_list));
|
||||
/* There should be four listed routers; all voters saw the same in this */
|
||||
|
||||
@ -3427,15 +3425,17 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
* Return values are {2, 3, 4} */
|
||||
|
||||
/* We want 3 ("*" means match all addresses) */
|
||||
tt_assert(routerset_contains_routerstatus(routerset_all, rs_a, 0) == 3);
|
||||
tt_assert(routerset_contains_routerstatus(routerset_all, rs_b, 0) == 3);
|
||||
tt_int_op(routerset_contains_routerstatus(routerset_all, rs_a, 0), OP_EQ, 3);
|
||||
tt_int_op(routerset_contains_routerstatus(routerset_all, rs_b, 0), OP_EQ, 3);
|
||||
|
||||
/* We want 4 (match id_digest [or nickname]) */
|
||||
tt_assert(routerset_contains_routerstatus(routerset_a, rs_a, 0) == 4);
|
||||
tt_assert(routerset_contains_routerstatus(routerset_a, rs_b, 0) == 0);
|
||||
tt_int_op(routerset_contains_routerstatus(routerset_a, rs_a, 0), OP_EQ, 4);
|
||||
tt_int_op(routerset_contains_routerstatus(routerset_a, rs_b, 0), OP_EQ, 0);
|
||||
|
||||
tt_assert(routerset_contains_routerstatus(routerset_none, rs_a, 0) == 0);
|
||||
tt_assert(routerset_contains_routerstatus(routerset_none, rs_b, 0) == 0);
|
||||
tt_int_op(routerset_contains_routerstatus(routerset_none, rs_a, 0), OP_EQ,
|
||||
0);
|
||||
tt_int_op(routerset_contains_routerstatus(routerset_none, rs_b, 0), OP_EQ,
|
||||
0);
|
||||
|
||||
/* Check that "*" sets flags on all routers: Exit
|
||||
* Check the flags aren't being confused with each other */
|
||||
@ -3447,17 +3447,17 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
mock_options->TestingDirAuthVoteExitIsStrict = 0;
|
||||
|
||||
dirserv_set_routerstatus_testing(rs_a);
|
||||
tt_assert(mock_get_options_calls == 1);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 1);
|
||||
dirserv_set_routerstatus_testing(rs_b);
|
||||
tt_assert(mock_get_options_calls == 2);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 2);
|
||||
|
||||
tt_assert(rs_a->is_exit == 1);
|
||||
tt_assert(rs_b->is_exit == 1);
|
||||
tt_uint_op(rs_a->is_exit, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_exit, OP_EQ, 1);
|
||||
/* Be paranoid - check no other flags are set */
|
||||
tt_assert(rs_a->is_possible_guard == 0);
|
||||
tt_assert(rs_b->is_possible_guard == 0);
|
||||
tt_assert(rs_a->is_hs_dir == 0);
|
||||
tt_assert(rs_b->is_hs_dir == 0);
|
||||
tt_uint_op(rs_a->is_possible_guard, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_possible_guard, OP_EQ, 0);
|
||||
tt_uint_op(rs_a->is_hs_dir, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_hs_dir, OP_EQ, 0);
|
||||
|
||||
/* Check that "*" sets flags on all routers: Guard & HSDir
|
||||
* Cover the remaining flags in one test */
|
||||
@ -3471,17 +3471,17 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
mock_options->TestingDirAuthVoteHSDirIsStrict = 0;
|
||||
|
||||
dirserv_set_routerstatus_testing(rs_a);
|
||||
tt_assert(mock_get_options_calls == 1);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 1);
|
||||
dirserv_set_routerstatus_testing(rs_b);
|
||||
tt_assert(mock_get_options_calls == 2);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 2);
|
||||
|
||||
tt_assert(rs_a->is_possible_guard == 1);
|
||||
tt_assert(rs_b->is_possible_guard == 1);
|
||||
tt_assert(rs_a->is_hs_dir == 1);
|
||||
tt_assert(rs_b->is_hs_dir == 1);
|
||||
tt_uint_op(rs_a->is_possible_guard, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_possible_guard, OP_EQ, 1);
|
||||
tt_uint_op(rs_a->is_hs_dir, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_hs_dir, OP_EQ, 1);
|
||||
/* Be paranoid - check exit isn't set */
|
||||
tt_assert(rs_a->is_exit == 0);
|
||||
tt_assert(rs_b->is_exit == 0);
|
||||
tt_uint_op(rs_a->is_exit, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_exit, OP_EQ, 0);
|
||||
|
||||
/* Check routerset A sets all flags on router A,
|
||||
* but leaves router B unmodified */
|
||||
@ -3497,16 +3497,16 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
mock_options->TestingDirAuthVoteHSDirIsStrict = 0;
|
||||
|
||||
dirserv_set_routerstatus_testing(rs_a);
|
||||
tt_assert(mock_get_options_calls == 1);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 1);
|
||||
dirserv_set_routerstatus_testing(rs_b);
|
||||
tt_assert(mock_get_options_calls == 2);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 2);
|
||||
|
||||
tt_assert(rs_a->is_exit == 1);
|
||||
tt_assert(rs_b->is_exit == 0);
|
||||
tt_assert(rs_a->is_possible_guard == 1);
|
||||
tt_assert(rs_b->is_possible_guard == 0);
|
||||
tt_assert(rs_a->is_hs_dir == 1);
|
||||
tt_assert(rs_b->is_hs_dir == 0);
|
||||
tt_uint_op(rs_a->is_exit, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_exit, OP_EQ, 0);
|
||||
tt_uint_op(rs_a->is_possible_guard, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_possible_guard, OP_EQ, 0);
|
||||
tt_uint_op(rs_a->is_hs_dir, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_hs_dir, OP_EQ, 0);
|
||||
|
||||
/* Check routerset A unsets all flags on router B when Strict is set */
|
||||
reset_options(mock_options, &mock_get_options_calls);
|
||||
@ -3524,11 +3524,11 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
rs_b->is_hs_dir = 1;
|
||||
|
||||
dirserv_set_routerstatus_testing(rs_b);
|
||||
tt_assert(mock_get_options_calls == 1);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 1);
|
||||
|
||||
tt_assert(rs_b->is_exit == 0);
|
||||
tt_assert(rs_b->is_possible_guard == 0);
|
||||
tt_assert(rs_b->is_hs_dir == 0);
|
||||
tt_uint_op(rs_b->is_exit, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_possible_guard, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_hs_dir, OP_EQ, 0);
|
||||
|
||||
/* Check routerset A doesn't modify flags on router B without Strict set */
|
||||
reset_options(mock_options, &mock_get_options_calls);
|
||||
@ -3546,11 +3546,11 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
rs_b->is_hs_dir = 1;
|
||||
|
||||
dirserv_set_routerstatus_testing(rs_b);
|
||||
tt_assert(mock_get_options_calls == 1);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 1);
|
||||
|
||||
tt_assert(rs_b->is_exit == 1);
|
||||
tt_assert(rs_b->is_possible_guard == 1);
|
||||
tt_assert(rs_b->is_hs_dir == 1);
|
||||
tt_uint_op(rs_b->is_exit, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_possible_guard, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_hs_dir, OP_EQ, 1);
|
||||
|
||||
/* Check the empty routerset zeroes all flags
|
||||
* on routers A & B with Strict set */
|
||||
@ -3569,11 +3569,11 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
rs_b->is_hs_dir = 1;
|
||||
|
||||
dirserv_set_routerstatus_testing(rs_b);
|
||||
tt_assert(mock_get_options_calls == 1);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 1);
|
||||
|
||||
tt_assert(rs_b->is_exit == 0);
|
||||
tt_assert(rs_b->is_possible_guard == 0);
|
||||
tt_assert(rs_b->is_hs_dir == 0);
|
||||
tt_uint_op(rs_b->is_exit, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_possible_guard, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_hs_dir, OP_EQ, 0);
|
||||
|
||||
/* Check the empty routerset doesn't modify any flags
|
||||
* on A or B without Strict set */
|
||||
@ -3593,16 +3593,16 @@ test_dir_dirserv_set_routerstatus_testing(void *arg)
|
||||
rs_b->is_hs_dir = 1;
|
||||
|
||||
dirserv_set_routerstatus_testing(rs_a);
|
||||
tt_assert(mock_get_options_calls == 1);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 1);
|
||||
dirserv_set_routerstatus_testing(rs_b);
|
||||
tt_assert(mock_get_options_calls == 2);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 2);
|
||||
|
||||
tt_assert(rs_a->is_exit == 0);
|
||||
tt_assert(rs_a->is_possible_guard == 0);
|
||||
tt_assert(rs_a->is_hs_dir == 0);
|
||||
tt_assert(rs_b->is_exit == 1);
|
||||
tt_assert(rs_b->is_possible_guard == 1);
|
||||
tt_assert(rs_b->is_hs_dir == 1);
|
||||
tt_uint_op(rs_a->is_exit, OP_EQ, 0);
|
||||
tt_uint_op(rs_a->is_possible_guard, OP_EQ, 0);
|
||||
tt_uint_op(rs_a->is_hs_dir, OP_EQ, 0);
|
||||
tt_uint_op(rs_b->is_exit, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_possible_guard, OP_EQ, 1);
|
||||
tt_uint_op(rs_b->is_hs_dir, OP_EQ, 1);
|
||||
|
||||
done:
|
||||
tor_free(mock_options);
|
||||
@ -4259,9 +4259,9 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + no_delay);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_failure)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* regression test for 17750: initial delay */
|
||||
mock_options->TestingClientDownloadSchedule = schedule;
|
||||
@ -4272,9 +4272,9 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + delay0);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_failure)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* regression test for 17750: exponential, no initial delay */
|
||||
mock_options->TestingClientDownloadSchedule = schedule_no_initial_delay;
|
||||
@ -4285,9 +4285,9 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + no_delay);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_exp)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_exp) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_exp) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_exp), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_exp), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* regression test for 17750: exponential, initial delay */
|
||||
mock_options->TestingClientDownloadSchedule = schedule;
|
||||
@ -4298,9 +4298,9 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + delay0);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_exp)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_exp) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_exp) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_exp), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_exp), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check that a failure reset works */
|
||||
mock_get_options_calls = 0;
|
||||
@ -4311,48 +4311,41 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + delay0);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_failure)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* avoid timing inconsistencies */
|
||||
dls_failure.next_attempt_at = current_time + delay0;
|
||||
|
||||
/* check that a reset schedule becomes ready at the right time */
|
||||
tt_assert(download_status_is_ready(&dls_failure,
|
||||
current_time + delay0 - 1,
|
||||
1) == 0);
|
||||
tt_assert(download_status_is_ready(&dls_failure,
|
||||
current_time + delay0,
|
||||
1) == 1);
|
||||
tt_assert(download_status_is_ready(&dls_failure,
|
||||
current_time + delay0 + 1,
|
||||
1) == 1);
|
||||
tt_int_op(download_status_is_ready(&dls_failure, current_time + delay0 - 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(download_status_is_ready(&dls_failure, current_time + delay0, 1),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(download_status_is_ready(&dls_failure, current_time + delay0 + 1, 1),
|
||||
OP_EQ, 1);
|
||||
|
||||
/* Check that a failure increment works */
|
||||
mock_get_options_calls = 0;
|
||||
next_at = download_status_increment_failure(&dls_failure, 404, "test", 0,
|
||||
current_time);
|
||||
tt_assert(next_at == current_time + delay1);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 1);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 1);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 1);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 1);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* check that an incremented schedule becomes ready at the right time */
|
||||
tt_assert(download_status_is_ready(&dls_failure,
|
||||
current_time + delay1 - 1,
|
||||
1) == 0);
|
||||
tt_assert(download_status_is_ready(&dls_failure,
|
||||
current_time + delay1,
|
||||
1) == 1);
|
||||
tt_assert(download_status_is_ready(&dls_failure,
|
||||
current_time + delay1 + 1,
|
||||
1) == 1);
|
||||
tt_int_op(download_status_is_ready(&dls_failure, current_time + delay1 - 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(download_status_is_ready(&dls_failure, current_time + delay1, 1),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(download_status_is_ready(&dls_failure, current_time + delay1 + 1, 1),
|
||||
OP_EQ, 1);
|
||||
|
||||
/* check that a schedule isn't ready if it's had too many failures */
|
||||
tt_assert(download_status_is_ready(&dls_failure,
|
||||
current_time + delay1 + 10,
|
||||
0) == 0);
|
||||
tt_int_op(download_status_is_ready(&dls_failure, current_time + delay1 + 10, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Check that failure increments do happen on 503 for clients, and
|
||||
* attempt increments do too. */
|
||||
@ -4362,25 +4355,25 @@ test_dir_download_status_increment(void *arg)
|
||||
tt_i64_op(next_at, OP_EQ, current_time + delay2);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 2);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 2);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check that failure increments do happen on 503 for servers */
|
||||
mock_get_options_calls = 0;
|
||||
next_at = download_status_increment_failure(&dls_failure, 503, "test", 1,
|
||||
current_time);
|
||||
tt_assert(next_at == current_time + delay2);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 3);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 3);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 3);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 3);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check what happens when we run off the end of the schedule */
|
||||
mock_get_options_calls = 0;
|
||||
next_at = download_status_increment_failure(&dls_failure, 404, "test", 0,
|
||||
current_time);
|
||||
tt_assert(next_at == current_time + delay2);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 4);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 4);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 4);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 4);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check what happens when we hit the failure limit */
|
||||
mock_get_options_calls = 0;
|
||||
@ -4388,22 +4381,22 @@ test_dir_download_status_increment(void *arg)
|
||||
next_at = download_status_increment_failure(&dls_failure, 404, "test", 0,
|
||||
current_time);
|
||||
tt_assert(next_at == TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check that a failure reset doesn't reset at the limit */
|
||||
mock_get_options_calls = 0;
|
||||
download_status_reset(&dls_failure);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_failure)
|
||||
== TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(mock_get_options_calls == 0);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 0);
|
||||
|
||||
/* Check that a failure reset resets just before the limit */
|
||||
mock_get_options_calls = 0;
|
||||
@ -4416,9 +4409,9 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + delay0);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_failure)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check that failure increments do happen on attempt-based schedules,
|
||||
* but that the retry is set at the end of time */
|
||||
@ -4426,9 +4419,9 @@ test_dir_download_status_increment(void *arg)
|
||||
next_at = download_status_increment_failure(&dls_attempt, 404, "test", 0,
|
||||
current_time);
|
||||
tt_assert(next_at == TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt) == 1);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ, 1);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check that an attempt reset works */
|
||||
mock_get_options_calls = 0;
|
||||
@ -4439,65 +4432,58 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + delay0);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_attempt)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* avoid timing inconsistencies */
|
||||
dls_attempt.next_attempt_at = current_time + delay0;
|
||||
|
||||
/* check that a reset schedule becomes ready at the right time */
|
||||
tt_assert(download_status_is_ready(&dls_attempt,
|
||||
current_time + delay0 - 1,
|
||||
1) == 0);
|
||||
tt_assert(download_status_is_ready(&dls_attempt,
|
||||
current_time + delay0,
|
||||
1) == 1);
|
||||
tt_assert(download_status_is_ready(&dls_attempt,
|
||||
current_time + delay0 + 1,
|
||||
1) == 1);
|
||||
tt_int_op(download_status_is_ready(&dls_attempt, current_time + delay0 - 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(download_status_is_ready(&dls_attempt, current_time + delay0, 1),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(download_status_is_ready(&dls_attempt, current_time + delay0 + 1, 1),
|
||||
OP_EQ, 1);
|
||||
|
||||
/* Check that an attempt increment works */
|
||||
mock_get_options_calls = 0;
|
||||
next_at = download_status_increment_attempt(&dls_attempt, "test",
|
||||
current_time);
|
||||
tt_assert(next_at == current_time + delay1);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt) == 1);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ, 1);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* check that an incremented schedule becomes ready at the right time */
|
||||
tt_assert(download_status_is_ready(&dls_attempt,
|
||||
current_time + delay1 - 1,
|
||||
1) == 0);
|
||||
tt_assert(download_status_is_ready(&dls_attempt,
|
||||
current_time + delay1,
|
||||
1) == 1);
|
||||
tt_assert(download_status_is_ready(&dls_attempt,
|
||||
current_time + delay1 + 1,
|
||||
1) == 1);
|
||||
tt_int_op(download_status_is_ready(&dls_attempt, current_time + delay1 - 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(download_status_is_ready(&dls_attempt, current_time + delay1, 1),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(download_status_is_ready(&dls_attempt, current_time + delay1 + 1, 1),
|
||||
OP_EQ, 1);
|
||||
|
||||
/* check that a schedule isn't ready if it's had too many attempts */
|
||||
tt_assert(download_status_is_ready(&dls_attempt,
|
||||
current_time + delay1 + 10,
|
||||
0) == 0);
|
||||
tt_int_op(download_status_is_ready(&dls_attempt, current_time + delay1 + 10, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Check what happens when we reach then run off the end of the schedule */
|
||||
mock_get_options_calls = 0;
|
||||
next_at = download_status_increment_attempt(&dls_attempt, "test",
|
||||
current_time);
|
||||
tt_assert(next_at == current_time + delay2);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt) == 2);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ, 2);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
mock_get_options_calls = 0;
|
||||
next_at = download_status_increment_attempt(&dls_attempt, "test",
|
||||
current_time);
|
||||
tt_assert(next_at == current_time + delay2);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt) == 3);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ, 3);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check what happens when we hit the attempt limit */
|
||||
mock_get_options_calls = 0;
|
||||
@ -4505,22 +4491,22 @@ test_dir_download_status_increment(void *arg)
|
||||
next_at = download_status_increment_attempt(&dls_attempt, "test",
|
||||
current_time);
|
||||
tt_assert(next_at == TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check that an attempt reset doesn't reset at the limit */
|
||||
mock_get_options_calls = 0;
|
||||
download_status_reset(&dls_attempt);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_attempt)
|
||||
== TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt)
|
||||
== IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_assert(mock_get_options_calls == 0);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ,
|
||||
IMPOSSIBLE_TO_DOWNLOAD);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 0);
|
||||
|
||||
/* Check that an attempt reset resets just before the limit */
|
||||
mock_get_options_calls = 0;
|
||||
@ -4533,9 +4519,9 @@ test_dir_download_status_increment(void *arg)
|
||||
>= current_time + delay0);
|
||||
tt_assert(download_status_get_next_attempt_at(&dls_attempt)
|
||||
!= TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_attempt) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_attempt) == 0);
|
||||
tt_assert(mock_get_options_calls >= 1);
|
||||
tt_int_op(download_status_get_n_failures(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_attempt), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_GE, 1);
|
||||
|
||||
/* Check that attempt increments don't happen on failure-based schedules,
|
||||
* and that the attempt is set at the end of time */
|
||||
@ -4548,9 +4534,9 @@ test_dir_download_status_increment(void *arg)
|
||||
"schedule.");
|
||||
teardown_capture_of_logs();
|
||||
tt_assert(next_at == TIME_MAX);
|
||||
tt_assert(download_status_get_n_failures(&dls_failure) == 0);
|
||||
tt_assert(download_status_get_n_attempts(&dls_failure) == 0);
|
||||
tt_assert(mock_get_options_calls == 0);
|
||||
tt_int_op(download_status_get_n_failures(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(download_status_get_n_attempts(&dls_failure), OP_EQ, 0);
|
||||
tt_int_op(mock_get_options_calls, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
/* the pointers in schedule are allocated on the stack */
|
||||
|
@ -595,20 +595,20 @@ test_entry_guard_parse_from_state_full(void *arg)
|
||||
MOCK(get_or_state,
|
||||
get_or_state_replacement);
|
||||
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_assert(lines);
|
||||
|
||||
state->Guard = lines;
|
||||
|
||||
/* Try it first without setting the result. */
|
||||
r = entry_guards_parse_state(state, 0, &msg);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
guard_selection_t *gs_br =
|
||||
get_guard_selection_by_name("bridges", GS_TYPE_BRIDGE, 0);
|
||||
tt_assert(!gs_br);
|
||||
|
||||
r = entry_guards_parse_state(state, 1, &msg);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
gs_br = get_guard_selection_by_name("bridges", GS_TYPE_BRIDGE, 0);
|
||||
guard_selection_t *gs_df =
|
||||
get_guard_selection_by_name("default", GS_TYPE_NORMAL, 0);
|
||||
@ -625,7 +625,7 @@ test_entry_guard_parse_from_state_full(void *arg)
|
||||
|
||||
/* Try again; make sure it doesn't double-add the guards. */
|
||||
r = entry_guards_parse_state(state, 1, &msg);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
gs_br = get_guard_selection_by_name("bridges", GS_TYPE_BRIDGE, 0);
|
||||
gs_df = get_guard_selection_by_name("default", GS_TYPE_NORMAL, 0);
|
||||
tt_assert(gs_br);
|
||||
@ -730,7 +730,7 @@ test_entry_guard_parse_from_state_broken(void *arg)
|
||||
MOCK(get_or_state,
|
||||
get_or_state_replacement);
|
||||
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_assert(lines);
|
||||
|
||||
state->Guard = lines;
|
||||
@ -847,15 +847,15 @@ test_entry_guard_add_single_guard(void *arg)
|
||||
tt_i64_op(g1->sampled_on_date, OP_GE, now - 12*86400);
|
||||
tt_i64_op(g1->sampled_on_date, OP_LE, now);
|
||||
tt_str_op(g1->sampled_by_version, OP_EQ, VERSION);
|
||||
tt_assert(g1->currently_listed == 1);
|
||||
tt_uint_op(g1->currently_listed, OP_EQ, 1);
|
||||
tt_i64_op(g1->confirmed_on_date, OP_EQ, 0);
|
||||
tt_int_op(g1->confirmed_idx, OP_EQ, -1);
|
||||
tt_int_op(g1->last_tried_to_connect, OP_EQ, 0);
|
||||
tt_uint_op(g1->is_reachable, OP_EQ, GUARD_REACHABLE_MAYBE);
|
||||
tt_i64_op(g1->failing_since, OP_EQ, 0);
|
||||
tt_assert(g1->is_filtered_guard == 1);
|
||||
tt_assert(g1->is_usable_filtered_guard == 1);
|
||||
tt_assert(g1->is_primary == 0);
|
||||
tt_uint_op(g1->is_filtered_guard, OP_EQ, 1);
|
||||
tt_uint_op(g1->is_usable_filtered_guard, OP_EQ, 1);
|
||||
tt_uint_op(g1->is_primary, OP_EQ, 0);
|
||||
tt_assert(g1->extra_state_fields == NULL);
|
||||
|
||||
/* Make sure it got added. */
|
||||
@ -886,16 +886,16 @@ test_entry_guard_node_filter(void *arg)
|
||||
g[i] = entry_guard_add_to_sample(gs, n[i]);
|
||||
|
||||
// everything starts out filtered-in
|
||||
tt_assert(g[i]->is_filtered_guard == 1);
|
||||
tt_assert(g[i]->is_usable_filtered_guard == 1);
|
||||
tt_uint_op(g[i]->is_filtered_guard, OP_EQ, 1);
|
||||
tt_uint_op(g[i]->is_usable_filtered_guard, OP_EQ, 1);
|
||||
}
|
||||
tt_int_op(num_reachable_filtered_guards(gs, NULL), OP_EQ, NUM);
|
||||
|
||||
/* Make sure refiltering doesn't hurt */
|
||||
entry_guards_update_filtered_sets(gs);
|
||||
for (i = 0; i < NUM; ++i) {
|
||||
tt_assert(g[i]->is_filtered_guard == 1);
|
||||
tt_assert(g[i]->is_usable_filtered_guard == 1);
|
||||
tt_uint_op(g[i]->is_filtered_guard, OP_EQ, 1);
|
||||
tt_uint_op(g[i]->is_usable_filtered_guard, OP_EQ, 1);
|
||||
}
|
||||
tt_int_op(num_reachable_filtered_guards(gs, NULL), OP_EQ, NUM);
|
||||
|
||||
@ -948,8 +948,8 @@ test_entry_guard_node_filter(void *arg)
|
||||
});
|
||||
entry_guards_update_filtered_sets(gs);
|
||||
for (i = 0; i < NUM; ++i) {
|
||||
tt_assert(g[i]->is_filtered_guard == 0);
|
||||
tt_assert(g[i]->is_usable_filtered_guard == 0);
|
||||
tt_uint_op(g[i]->is_filtered_guard, OP_EQ, 0);
|
||||
tt_uint_op(g[i]->is_usable_filtered_guard, OP_EQ, 0);
|
||||
}
|
||||
tt_int_op(num_reachable_filtered_guards(gs, NULL), OP_EQ, 0);
|
||||
|
||||
@ -1707,7 +1707,7 @@ test_entry_guard_select_for_circuit_no_confirmed(void *arg)
|
||||
tt_assert(g);
|
||||
tt_assert(g->is_primary);
|
||||
tt_int_op(g->confirmed_idx, OP_EQ, -1);
|
||||
tt_assert(g->is_pending == 0); // primary implies non-pending.
|
||||
tt_uint_op(g->is_pending, OP_EQ, 0); // primary implies non-pending.
|
||||
tt_uint_op(state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
tt_i64_op(g->last_tried_to_connect, OP_EQ, approx_time());
|
||||
|
||||
@ -1727,7 +1727,7 @@ test_entry_guard_select_for_circuit_no_confirmed(void *arg)
|
||||
tt_assert(g2);
|
||||
tt_assert(g2->is_primary);
|
||||
tt_int_op(g2->confirmed_idx, OP_EQ, -1);
|
||||
tt_assert(g2->is_pending == 0); // primary implies non-pending.
|
||||
tt_uint_op(g2->is_pending, OP_EQ, 0); // primary implies non-pending.
|
||||
tt_uint_op(state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
tt_i64_op(g2->last_tried_to_connect, OP_EQ, approx_time());
|
||||
|
||||
@ -1755,7 +1755,7 @@ test_entry_guard_select_for_circuit_no_confirmed(void *arg)
|
||||
tt_assert(g2);
|
||||
tt_assert(!g2->is_primary);
|
||||
tt_int_op(g2->confirmed_idx, OP_EQ, -1);
|
||||
tt_assert(g2->is_pending == 1);
|
||||
tt_uint_op(g2->is_pending, OP_EQ, 1);
|
||||
tt_uint_op(state, OP_EQ, GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD);
|
||||
tt_i64_op(g2->last_tried_to_connect, OP_EQ, approx_time());
|
||||
tt_int_op(g2->is_reachable, OP_EQ, GUARD_REACHABLE_MAYBE);
|
||||
@ -1813,7 +1813,7 @@ test_entry_guard_select_for_circuit_confirmed(void *arg)
|
||||
tt_assert(g);
|
||||
tt_assert(g->is_primary);
|
||||
tt_int_op(g->confirmed_idx, OP_EQ, 0);
|
||||
tt_assert(g->is_pending == 0); // primary implies non-pending.
|
||||
tt_uint_op(g->is_pending, OP_EQ, 0); // primary implies non-pending.
|
||||
tt_uint_op(state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
tt_i64_op(g->last_tried_to_connect, OP_EQ, approx_time());
|
||||
tt_ptr_op(g, OP_EQ, smartlist_get(gs->primary_entry_guards, 0));
|
||||
@ -1913,7 +1913,7 @@ test_entry_guard_select_for_circuit_highlevel_primary(void *arg)
|
||||
int r = entry_guard_pick_for_circuit(gs, GUARD_USAGE_TRAFFIC, NULL,
|
||||
&node, &guard);
|
||||
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
@ -1945,7 +1945,7 @@ test_entry_guard_select_for_circuit_highlevel_primary(void *arg)
|
||||
update_approx_time(start+35);
|
||||
r = entry_guard_pick_for_circuit(gs, GUARD_USAGE_TRAFFIC, NULL,
|
||||
&node, &guard);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
@ -1981,7 +1981,7 @@ test_entry_guard_select_for_circuit_highlevel_primary(void *arg)
|
||||
update_approx_time(start+60);
|
||||
r = entry_guard_pick_for_circuit(gs, GUARD_USAGE_TRAFFIC, NULL,
|
||||
&node, &guard);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
@ -2036,7 +2036,7 @@ test_entry_guard_select_for_circuit_highlevel_confirm_other(void *arg)
|
||||
&node, &guard);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
entry_guard_failed(&guard);
|
||||
circuit_guard_state_free(guard);
|
||||
@ -2050,7 +2050,7 @@ test_entry_guard_select_for_circuit_highlevel_confirm_other(void *arg)
|
||||
&node, &guard);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
entry_guard_t *g = entry_guard_handle_get(guard->guard);
|
||||
tt_assert(g);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD);
|
||||
@ -2102,7 +2102,7 @@ test_entry_guard_select_for_circuit_highlevel_primary_retry(void *arg)
|
||||
&node, &guard);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
g = entry_guard_handle_get(guard->guard);
|
||||
make_guard_confirmed(gs, g);
|
||||
@ -2119,7 +2119,7 @@ test_entry_guard_select_for_circuit_highlevel_primary_retry(void *arg)
|
||||
&node, &guard);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD);
|
||||
g = entry_guard_handle_get(guard->guard);
|
||||
tt_int_op(g->is_primary, OP_EQ, 0);
|
||||
@ -2145,7 +2145,7 @@ test_entry_guard_select_for_circuit_highlevel_primary_retry(void *arg)
|
||||
/* Have a circuit to a primary guard succeed. */
|
||||
r = entry_guard_pick_for_circuit(gs, GUARD_USAGE_TRAFFIC, NULL,
|
||||
&node, &guard2);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_int_op(guard2->state, OP_EQ, GUARD_CIRC_STATE_USABLE_ON_COMPLETION);
|
||||
u = entry_guard_succeeded(&guard2);
|
||||
tt_assert(u == GUARD_USABLE_NOW);
|
||||
@ -2194,7 +2194,7 @@ test_entry_guard_select_and_cancel(void *arg)
|
||||
&node, &guard);
|
||||
tt_assert(node);
|
||||
tt_assert(guard);
|
||||
tt_assert(r == 0);
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_int_op(guard->state, OP_EQ, GUARD_CIRC_STATE_USABLE_IF_NO_BETTER_GUARD);
|
||||
g = entry_guard_handle_get(guard->guard);
|
||||
tt_int_op(g->is_primary, OP_EQ, 0);
|
||||
|
@ -189,7 +189,7 @@ mock_connection_connect_sockaddr(connection_t *conn,
|
||||
/* We really should call tor_libevent_initialize() here. Because we don't,
|
||||
* we are relying on other parts of the code not checking if the_event_base
|
||||
* (and therefore event->ev_base) is NULL. */
|
||||
tt_assert(connection_add_connecting(conn) == 0);
|
||||
tt_int_op(connection_add_connecting(conn), OP_EQ, 0);
|
||||
|
||||
done:
|
||||
/* Fake "connected" status */
|
||||
@ -222,7 +222,7 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose)
|
||||
mock_connection_connect_sockaddr_called = 0;
|
||||
in_progress = connection_connect(conn, TEST_CONN_ADDRESS_PORT, &addr,
|
||||
TEST_CONN_PORT, &socket_err);
|
||||
tt_assert(mock_connection_connect_sockaddr_called == 1);
|
||||
tt_int_op(mock_connection_connect_sockaddr_called, OP_EQ, 1);
|
||||
tt_assert(!socket_err);
|
||||
tt_assert(in_progress == 0 || in_progress == 1);
|
||||
|
||||
|
@ -671,14 +671,14 @@ test_single_onion_poisoning(void *arg)
|
||||
* The data directory is required for the lockfile, which is used when
|
||||
* loading keys. */
|
||||
ret = check_private_dir(mock_options->DataDirectory, CPD_CREATE, NULL);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
if (create_dir_mask & CREATE_HS_DIR1) {
|
||||
ret = check_private_dir(dir1, CPD_CREATE, NULL);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
if (create_dir_mask & CREATE_HS_DIR2) {
|
||||
ret = check_private_dir(dir2, CPD_CREATE, NULL);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
}
|
||||
|
||||
service_1->directory = dir1;
|
||||
@ -705,17 +705,17 @@ test_single_onion_poisoning(void *arg)
|
||||
mock_options->HiddenServiceSingleHopMode = 0;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 0;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Either way, no problem. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Add the first service */
|
||||
ret = hs_check_service_private_dir(mock_options->User, service_1->directory,
|
||||
@ -728,75 +728,75 @@ test_single_onion_poisoning(void *arg)
|
||||
mock_options->HiddenServiceSingleHopMode = 0;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 0;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Either way, no problem. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Poison! Poison! Poison!
|
||||
* This can only be done in HiddenServiceSingleHopMode. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_poison_new_single_onion_dir(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
/* Poisoning twice is a no-op. */
|
||||
ret = rend_service_poison_new_single_onion_dir(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Poisoned service directories, but no previous keys, no problem! */
|
||||
mock_options->HiddenServiceSingleHopMode = 0;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 0;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Either way, no problem. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Now add some keys, and we'll have a problem. */
|
||||
ret = rend_service_load_all_keys(services);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Poisoned service directories with previous keys are not allowed. */
|
||||
mock_options->HiddenServiceSingleHopMode = 0;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 0;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret < 0);
|
||||
tt_int_op(ret, OP_LT, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* But they are allowed if we're in non-anonymous mode. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Re-poisoning directories with existing keys is a no-op, because
|
||||
* directories with existing keys are ignored. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_poison_new_single_onion_dir(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
/* And it keeps the poison. */
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Now add the second service: it has no key and no poison file */
|
||||
ret = hs_check_service_private_dir(mock_options->User, service_2->directory,
|
||||
@ -808,77 +808,77 @@ test_single_onion_poisoning(void *arg)
|
||||
mock_options->HiddenServiceSingleHopMode = 0;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 0;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret < 0);
|
||||
tt_int_op(ret, OP_LT, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* But ok to add in non-anonymous mode. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Now remove the poisoning from the first service, and we have the opposite
|
||||
* problem. */
|
||||
poison_path = rend_service_sos_poison_path(service_1);
|
||||
tt_assert(poison_path);
|
||||
ret = unlink(poison_path);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Unpoisoned service directories with previous keys are ok, as are empty
|
||||
* directories. */
|
||||
mock_options->HiddenServiceSingleHopMode = 0;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 0;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* But the existing unpoisoned key is not ok in non-anonymous mode, even if
|
||||
* there is an empty service. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret < 0);
|
||||
tt_int_op(ret, OP_LT, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Poisoning directories with existing keys is a no-op, because directories
|
||||
* with existing keys are ignored. But the new directory should poison. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_poison_new_single_onion_dir(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_poison_new_single_onion_dir(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
/* And the old directory remains unpoisoned. */
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret < 0);
|
||||
tt_int_op(ret, OP_LT, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* And the new directory should be ignored, because it has no key. */
|
||||
mock_options->HiddenServiceSingleHopMode = 0;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 0;
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Re-poisoning directories without existing keys is a no-op. */
|
||||
mock_options->HiddenServiceSingleHopMode = 1;
|
||||
mock_options->HiddenServiceNonAnonymousMode = 1;
|
||||
ret = rend_service_poison_new_single_onion_dir(service_1, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = rend_service_poison_new_single_onion_dir(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
/* And the old directory remains unpoisoned. */
|
||||
ret = rend_service_verify_single_onion_poison(service_1, mock_options);
|
||||
tt_assert(ret < 0);
|
||||
tt_int_op(ret, OP_LT, 0);
|
||||
ret = rend_service_verify_single_onion_poison(service_2, mock_options);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
/* The test harness deletes the directories at exit */
|
||||
|
@ -430,24 +430,24 @@ get_options_test_data(const char *conf)
|
||||
result->opt->ConnectionPadding = -1; // default must be "auto"
|
||||
|
||||
rv = config_get_lines(conf, &cl, 1);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
rv = config_assign(&options_format, result->opt, cl, 0, &msg);
|
||||
if (msg) {
|
||||
/* Display the parse error message by comparing it with an empty string */
|
||||
tt_str_op(msg, OP_EQ, "");
|
||||
}
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
config_free_lines(cl);
|
||||
result->opt->LogTimeGranularity = 1;
|
||||
result->opt->TokenBucketRefillInterval = 1;
|
||||
rv = config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
rv = config_assign(&options_format, result->def_opt, cl, 0, &msg);
|
||||
if (msg) {
|
||||
/* Display the parse error message by comparing it with an empty string */
|
||||
tt_str_op(msg, OP_EQ, "");
|
||||
}
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
|
||||
done:
|
||||
config_free_lines(cl);
|
||||
|
@ -1148,7 +1148,7 @@ test_policies_reject_exit_address(void *arg)
|
||||
/* test that IPv4 addresses are rejected on an IPv4-only exit */
|
||||
policies_parse_exit_policy_reject_private(&policy, 0, ipv4_list, 0, 0);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 1);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 1);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_addr));
|
||||
addr_policy_list_free(policy);
|
||||
policy = NULL;
|
||||
@ -1163,7 +1163,7 @@ test_policies_reject_exit_address(void *arg)
|
||||
/* test that only IPv4 addresses are rejected on an IPv4-only exit */
|
||||
policies_parse_exit_policy_reject_private(&policy, 0, both_list, 0, 0);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 1);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 1);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_addr));
|
||||
addr_policy_list_free(policy);
|
||||
policy = NULL;
|
||||
@ -1171,7 +1171,7 @@ test_policies_reject_exit_address(void *arg)
|
||||
/* Test that lists with duplicate entries produce the same results */
|
||||
policies_parse_exit_policy_reject_private(&policy, 0, dupl_list, 0, 0);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 1);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 1);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_addr));
|
||||
addr_policy_list_free(policy);
|
||||
policy = NULL;
|
||||
@ -1181,7 +1181,7 @@ test_policies_reject_exit_address(void *arg)
|
||||
/* test that IPv4 addresses are rejected on an IPv4/IPv6 exit */
|
||||
policies_parse_exit_policy_reject_private(&policy, 1, ipv4_list, 0, 0);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 1);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 1);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_addr));
|
||||
addr_policy_list_free(policy);
|
||||
policy = NULL;
|
||||
@ -1189,7 +1189,7 @@ test_policies_reject_exit_address(void *arg)
|
||||
/* test that IPv6 addresses are rejected on an IPv4/IPv6 exit */
|
||||
policies_parse_exit_policy_reject_private(&policy, 1, ipv6_list, 0, 0);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 1);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 1);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv6_addr));
|
||||
addr_policy_list_free(policy);
|
||||
policy = NULL;
|
||||
@ -1197,7 +1197,7 @@ test_policies_reject_exit_address(void *arg)
|
||||
/* test that IPv4 and IPv6 addresses are rejected on an IPv4/IPv6 exit */
|
||||
policies_parse_exit_policy_reject_private(&policy, 1, both_list, 0, 0);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 2);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 2);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_addr));
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv6_addr));
|
||||
addr_policy_list_free(policy);
|
||||
@ -1206,7 +1206,7 @@ test_policies_reject_exit_address(void *arg)
|
||||
/* Test that lists with duplicate entries produce the same results */
|
||||
policies_parse_exit_policy_reject_private(&policy, 1, dupl_list, 0, 0);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 2);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 2);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_addr));
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv6_addr));
|
||||
addr_policy_list_free(policy);
|
||||
@ -1258,7 +1258,7 @@ test_policies_reject_port_address(void *arg)
|
||||
* with IPv6 addresses on IPv4-only exits) */
|
||||
policies_parse_exit_policy_reject_private(&policy, 0, NULL, 0, 1);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 1);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 1);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_port->addr));
|
||||
addr_policy_list_free(policy);
|
||||
policy = NULL;
|
||||
@ -1266,7 +1266,7 @@ test_policies_reject_port_address(void *arg)
|
||||
/* test that IPv4 and IPv6 ports are rejected on an IPv4/IPv6 exit */
|
||||
policies_parse_exit_policy_reject_private(&policy, 1, NULL, 0, 1);
|
||||
tt_assert(policy);
|
||||
tt_assert(smartlist_len(policy) == 2);
|
||||
tt_int_op(smartlist_len(policy), OP_EQ, 2);
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv4_port->addr));
|
||||
tt_assert(test_policy_has_address_helper(policy, &ipv6_port->addr));
|
||||
addr_policy_list_free(policy);
|
||||
@ -1528,14 +1528,14 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
memset(&mock_my_routerinfo, 0, sizeof(mock_my_routerinfo));
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/default", &answer, &errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) > 0);
|
||||
tor_free(answer);
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/reject-private/default",
|
||||
&answer, &errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) > 0);
|
||||
tor_free(answer);
|
||||
@ -1550,14 +1550,14 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/reject-private/relay",
|
||||
&answer, &errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) == 0);
|
||||
tor_free(answer);
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/ipv4", &answer,
|
||||
&errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
ipv4_len = strlen(answer);
|
||||
tt_assert(ipv4_len == 0 || ipv4_len == strlen(DEFAULT_POLICY_STRING));
|
||||
@ -1566,7 +1566,7 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/ipv6", &answer,
|
||||
&errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
ipv6_len = strlen(answer);
|
||||
tt_assert(ipv6_len == 0 || ipv6_len == strlen(DEFAULT_POLICY_STRING));
|
||||
@ -1575,7 +1575,7 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/full", &answer,
|
||||
&errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
/* It's either empty or it's the default */
|
||||
tt_assert(strlen(answer) == 0 || !strcasecmp(answer, DEFAULT_POLICY_STRING));
|
||||
@ -1599,7 +1599,7 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/reject-private/relay",
|
||||
&answer, &errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) > 0);
|
||||
tor_free(answer);
|
||||
@ -1609,7 +1609,7 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/reject-private/relay",
|
||||
&answer, &errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) > 0);
|
||||
tor_free(answer);
|
||||
@ -1619,7 +1619,7 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/reject-private/relay",
|
||||
&answer, &errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) > 0);
|
||||
tor_free(answer);
|
||||
@ -1629,14 +1629,14 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/reject-private/relay",
|
||||
&answer, &errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) == 0);
|
||||
tor_free(answer);
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/ipv4", &answer,
|
||||
&errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
ipv4_len = strlen(answer);
|
||||
tt_assert(ipv4_len > 0);
|
||||
@ -1644,7 +1644,7 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/ipv6", &answer,
|
||||
&errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
ipv6_len = strlen(answer);
|
||||
tt_assert(ipv6_len > 0);
|
||||
@ -1652,7 +1652,7 @@ test_policies_getinfo_helper_policies(void *arg)
|
||||
|
||||
rv = getinfo_helper_policies(NULL, "exit-policy/full", &answer,
|
||||
&errmsg);
|
||||
tt_assert(rv == 0);
|
||||
tt_int_op(rv, OP_EQ, 0);
|
||||
tt_assert(answer != NULL);
|
||||
tt_assert(strlen(answer) > 0);
|
||||
tt_assert(strlen(answer) == ipv4_len + ipv6_len + 1);
|
||||
@ -1746,34 +1746,34 @@ test_policies_fascist_firewall_allows_address(void *arg)
|
||||
mock_options.ClientUseIPv6 = 1;
|
||||
mock_options.UseBridges = 0;
|
||||
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Preferring IPv4 */
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Preferring IPv6 */
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 1)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 1)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 1)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 1)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 1),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 1),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Test the function's address matching with UseBridges on */
|
||||
memset(&mock_options, 0, sizeof(or_options_t));
|
||||
@ -1781,46 +1781,46 @@ test_policies_fascist_firewall_allows_address(void *arg)
|
||||
mock_options.ClientUseIPv6 = 1;
|
||||
mock_options.UseBridges = 1;
|
||||
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Preferring IPv4 */
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Preferring IPv6 */
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 1)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 1)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 1)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 1)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 1, 1),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 1, 1),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 1, 1),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* bridge clients always use IPv6, regardless of ClientUseIPv6 */
|
||||
mock_options.ClientUseIPv4 = 1;
|
||||
mock_options.ClientUseIPv6 = 0;
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Test the function's address matching with IPv4 on */
|
||||
memset(&mock_options, 0, sizeof(or_options_t));
|
||||
@ -1828,14 +1828,14 @@ test_policies_fascist_firewall_allows_address(void *arg)
|
||||
mock_options.ClientUseIPv6 = 0;
|
||||
mock_options.UseBridges = 0;
|
||||
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Test the function's address matching with IPv6 on */
|
||||
memset(&mock_options, 0, sizeof(or_options_t));
|
||||
@ -1843,14 +1843,14 @@ test_policies_fascist_firewall_allows_address(void *arg)
|
||||
mock_options.ClientUseIPv6 = 1;
|
||||
mock_options.UseBridges = 0;
|
||||
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Test the function's address matching with ClientUseIPv4 0.
|
||||
* This means "use IPv6" regardless of the other settings. */
|
||||
@ -1859,14 +1859,14 @@ test_policies_fascist_firewall_allows_address(void *arg)
|
||||
mock_options.ClientUseIPv6 = 0;
|
||||
mock_options.UseBridges = 0;
|
||||
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&r_ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* Test the function's address matching for unusual inputs */
|
||||
memset(&mock_options, 0, sizeof(or_options_t));
|
||||
@ -1875,27 +1875,28 @@ test_policies_fascist_firewall_allows_address(void *arg)
|
||||
mock_options.UseBridges = 1;
|
||||
|
||||
/* NULL and tor_addr_is_null addresses are rejected */
|
||||
tt_assert(fascist_firewall_allows_address(NULL, port, policy, 0, 0) == 0);
|
||||
tt_assert(fascist_firewall_allows_address(&n_ipv4_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&n_ipv6_addr, port, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(NULL, port, policy, 0, 0), OP_EQ,
|
||||
0);
|
||||
tt_int_op(fascist_firewall_allows_address(&n_ipv4_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&n_ipv6_addr, port, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* zero ports are rejected */
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, 0, policy, 0, 0)
|
||||
== 0);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, 0, policy, 0, 0)
|
||||
== 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, 0, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, 0, policy, 0, 0),
|
||||
OP_EQ, 0);
|
||||
|
||||
/* NULL and empty policies accept everything */
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, NULL, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, NULL, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv4_addr, port, e_policy, 0, 0)
|
||||
== 1);
|
||||
tt_assert(fascist_firewall_allows_address(&ipv6_addr, port, e_policy, 0, 0)
|
||||
== 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, NULL, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, NULL, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv4_addr, port, e_policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(fascist_firewall_allows_address(&ipv6_addr, port, e_policy, 0, 0),
|
||||
OP_EQ, 1);
|
||||
|
||||
done:
|
||||
addr_policy_free(item);
|
||||
|
@ -40,34 +40,34 @@ test_pt_parsing(void *arg)
|
||||
|
||||
/* incomplete cmethod */
|
||||
strlcpy(line,"CMETHOD trebuchet",sizeof(line));
|
||||
tt_assert(parse_cmethod_line(line, mp) < 0);
|
||||
tt_int_op(parse_cmethod_line(line, mp), OP_LT, 0);
|
||||
|
||||
reset_mp(mp);
|
||||
|
||||
/* wrong proxy type */
|
||||
strlcpy(line,"CMETHOD trebuchet dog 127.0.0.1:1999",sizeof(line));
|
||||
tt_assert(parse_cmethod_line(line, mp) < 0);
|
||||
tt_int_op(parse_cmethod_line(line, mp), OP_LT, 0);
|
||||
|
||||
reset_mp(mp);
|
||||
|
||||
/* wrong addrport */
|
||||
strlcpy(line,"CMETHOD trebuchet socks4 abcd",sizeof(line));
|
||||
tt_assert(parse_cmethod_line(line, mp) < 0);
|
||||
tt_int_op(parse_cmethod_line(line, mp), OP_LT, 0);
|
||||
|
||||
reset_mp(mp);
|
||||
|
||||
/* correct line */
|
||||
strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line));
|
||||
tt_assert(parse_cmethod_line(line, mp) == 0);
|
||||
tt_assert(smartlist_len(mp->transports) == 1);
|
||||
tt_int_op(parse_cmethod_line(line, mp), OP_EQ, 0);
|
||||
tt_int_op(smartlist_len(mp->transports), OP_EQ, 1);
|
||||
transport = smartlist_get(mp->transports, 0);
|
||||
/* test registered address of transport */
|
||||
tor_addr_parse(&test_addr, "127.0.0.1");
|
||||
tt_assert(tor_addr_eq(&test_addr, &transport->addr));
|
||||
/* test registered port of transport */
|
||||
tt_assert(transport->port == 1999);
|
||||
tt_uint_op(transport->port, OP_EQ, 1999);
|
||||
/* test registered SOCKS version of transport */
|
||||
tt_assert(transport->socks_version == PROXY_SOCKS5);
|
||||
tt_int_op(transport->socks_version, OP_EQ, PROXY_SOCKS5);
|
||||
/* test registered name of transport */
|
||||
tt_str_op(transport->name,OP_EQ, "trebuchet");
|
||||
|
||||
@ -75,26 +75,26 @@ test_pt_parsing(void *arg)
|
||||
|
||||
/* incomplete smethod */
|
||||
strlcpy(line,"SMETHOD trebuchet",sizeof(line));
|
||||
tt_assert(parse_smethod_line(line, mp) < 0);
|
||||
tt_int_op(parse_smethod_line(line, mp), OP_LT, 0);
|
||||
|
||||
reset_mp(mp);
|
||||
|
||||
/* wrong addr type */
|
||||
strlcpy(line,"SMETHOD trebuchet abcd",sizeof(line));
|
||||
tt_assert(parse_smethod_line(line, mp) < 0);
|
||||
tt_int_op(parse_smethod_line(line, mp), OP_LT, 0);
|
||||
|
||||
reset_mp(mp);
|
||||
|
||||
/* cowwect */
|
||||
strlcpy(line,"SMETHOD trebuchy 127.0.0.2:2999",sizeof(line));
|
||||
tt_assert(parse_smethod_line(line, mp) == 0);
|
||||
tt_assert(smartlist_len(mp->transports) == 1);
|
||||
tt_int_op(parse_smethod_line(line, mp), OP_EQ, 0);
|
||||
tt_int_op(smartlist_len(mp->transports), OP_EQ, 1);
|
||||
transport = smartlist_get(mp->transports, 0);
|
||||
/* test registered address of transport */
|
||||
tor_addr_parse(&test_addr, "127.0.0.2");
|
||||
tt_assert(tor_addr_eq(&test_addr, &transport->addr));
|
||||
/* test registered port of transport */
|
||||
tt_assert(transport->port == 2999);
|
||||
tt_uint_op(transport->port, OP_EQ, 2999);
|
||||
/* test registered name of transport */
|
||||
tt_str_op(transport->name,OP_EQ, "trebuchy");
|
||||
|
||||
@ -104,7 +104,7 @@ test_pt_parsing(void *arg)
|
||||
strlcpy(line,"SMETHOD trebuchet 127.0.0.1:9999 "
|
||||
"ARGS:counterweight=3,sling=snappy",
|
||||
sizeof(line));
|
||||
tt_assert(parse_smethod_line(line, mp) == 0);
|
||||
tt_int_op(parse_smethod_line(line, mp), OP_EQ, 0);
|
||||
tt_int_op(1, OP_EQ, smartlist_len(mp->transports));
|
||||
{
|
||||
const transport_t *transport_ = smartlist_get(mp->transports, 0);
|
||||
@ -119,15 +119,15 @@ test_pt_parsing(void *arg)
|
||||
|
||||
/* unsupported version */
|
||||
strlcpy(line,"VERSION 666",sizeof(line));
|
||||
tt_assert(parse_version(line, mp) < 0);
|
||||
tt_int_op(parse_version(line, mp), OP_LT, 0);
|
||||
|
||||
/* incomplete VERSION */
|
||||
strlcpy(line,"VERSION ",sizeof(line));
|
||||
tt_assert(parse_version(line, mp) < 0);
|
||||
tt_int_op(parse_version(line, mp), OP_LT, 0);
|
||||
|
||||
/* correct VERSION */
|
||||
strlcpy(line,"VERSION 1",sizeof(line));
|
||||
tt_assert(parse_version(line, mp) == 0);
|
||||
tt_int_op(parse_version(line, mp), OP_EQ, 0);
|
||||
|
||||
done:
|
||||
reset_mp(mp);
|
||||
|
@ -101,10 +101,10 @@ test_routerkeys_ed_certs(void *args)
|
||||
cert[i] = tor_cert_create(&kp1, 5, &kp2.pubkey, now, 10000, flags);
|
||||
tt_assert(cert[i]);
|
||||
|
||||
tt_assert(cert[i]->sig_bad == 0);
|
||||
tt_assert(cert[i]->sig_ok == 1);
|
||||
tt_assert(cert[i]->cert_expired == 0);
|
||||
tt_assert(cert[i]->cert_valid == 1);
|
||||
tt_uint_op(cert[i]->sig_bad, OP_EQ, 0);
|
||||
tt_uint_op(cert[i]->sig_ok, OP_EQ, 1);
|
||||
tt_uint_op(cert[i]->cert_expired, OP_EQ, 0);
|
||||
tt_uint_op(cert[i]->cert_valid, OP_EQ, 1);
|
||||
tt_int_op(cert[i]->cert_type, OP_EQ, 5);
|
||||
tt_mem_op(cert[i]->signed_key.pubkey, OP_EQ, &kp2.pubkey.pubkey, 32);
|
||||
tt_mem_op(cert[i]->signing_key.pubkey, OP_EQ, &kp1.pubkey.pubkey, 32);
|
||||
@ -120,26 +120,26 @@ test_routerkeys_ed_certs(void *args)
|
||||
tt_int_op(cert[i]->encoded_len, OP_EQ, parsed_cert[i]->encoded_len);
|
||||
tt_mem_op(cert[i]->encoded, OP_EQ, parsed_cert[i]->encoded,
|
||||
cert[i]->encoded_len);
|
||||
tt_assert(parsed_cert[i]->sig_bad == 0);
|
||||
tt_assert(parsed_cert[i]->sig_ok == 0);
|
||||
tt_assert(parsed_cert[i]->cert_expired == 0);
|
||||
tt_assert(parsed_cert[i]->cert_valid == 0);
|
||||
tt_uint_op(parsed_cert[i]->sig_bad, OP_EQ, 0);
|
||||
tt_uint_op(parsed_cert[i]->sig_ok, OP_EQ, 0);
|
||||
tt_uint_op(parsed_cert[i]->cert_expired, OP_EQ, 0);
|
||||
tt_uint_op(parsed_cert[i]->cert_valid, OP_EQ, 0);
|
||||
|
||||
/* Expired */
|
||||
tt_int_op(tor_cert_checksig(parsed_cert[i], &kp1.pubkey, now + 30000),
|
||||
OP_LT, 0);
|
||||
tt_assert(parsed_cert[i]->cert_expired == 1);
|
||||
tt_uint_op(parsed_cert[i]->cert_expired, OP_EQ, 1);
|
||||
parsed_cert[i]->cert_expired = 0;
|
||||
|
||||
/* Wrong key */
|
||||
tt_int_op(tor_cert_checksig(parsed_cert[i], &kp2.pubkey, now), OP_LT, 0);
|
||||
tt_assert(parsed_cert[i]->sig_bad== 1);
|
||||
tt_uint_op(parsed_cert[i]->sig_bad, OP_EQ, 1);
|
||||
parsed_cert[i]->sig_bad = 0;
|
||||
|
||||
/* Missing key */
|
||||
int ok = tor_cert_checksig(parsed_cert[i], NULL, now);
|
||||
tt_int_op(ok < 0, OP_EQ, i == 0);
|
||||
tt_assert(parsed_cert[i]->sig_bad == 0);
|
||||
tt_uint_op(parsed_cert[i]->sig_bad, OP_EQ, 0);
|
||||
tt_assert(parsed_cert[i]->sig_ok == (i != 0));
|
||||
tt_assert(parsed_cert[i]->cert_valid == (i != 0));
|
||||
parsed_cert[i]->sig_bad = 0;
|
||||
@ -148,10 +148,10 @@ test_routerkeys_ed_certs(void *args)
|
||||
|
||||
/* Right key */
|
||||
tt_int_op(tor_cert_checksig(parsed_cert[i], &kp1.pubkey, now), OP_EQ, 0);
|
||||
tt_assert(parsed_cert[i]->sig_bad == 0);
|
||||
tt_assert(parsed_cert[i]->sig_ok == 1);
|
||||
tt_assert(parsed_cert[i]->cert_expired == 0);
|
||||
tt_assert(parsed_cert[i]->cert_valid == 1);
|
||||
tt_uint_op(parsed_cert[i]->sig_bad, OP_EQ, 0);
|
||||
tt_uint_op(parsed_cert[i]->sig_ok, OP_EQ, 1);
|
||||
tt_uint_op(parsed_cert[i]->cert_expired, OP_EQ, 0);
|
||||
tt_uint_op(parsed_cert[i]->cert_valid, OP_EQ, 1);
|
||||
}
|
||||
|
||||
/* Now try some junky certs. */
|
||||
|
@ -449,27 +449,27 @@ test_routerlist_router_is_already_dir_fetching(void *arg)
|
||||
|
||||
/* Test that we never get 1 from a NULL connection */
|
||||
mocked_connection = NULL;
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 1, 1) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 1, 0) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 0, 1) == 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 1, 1), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 1, 0), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 0, 1), OP_EQ, 0);
|
||||
/* We always expect 0 in these cases */
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 0, 0) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(NULL, 1, 1) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(&null_addr_ap, 1, 1) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(&zero_port_ap, 1, 1) == 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 0, 0), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(NULL, 1, 1), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&null_addr_ap, 1, 1), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&zero_port_ap, 1, 1), OP_EQ, 0);
|
||||
|
||||
/* Test that we get 1 with a connection in the appropriate circumstances */
|
||||
mocked_connection = connection_new(CONN_TYPE_DIR, AF_INET);
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 1, 1) == 1);
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 1, 0) == 1);
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 0, 1) == 1);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 1, 1), OP_EQ, 1);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 1, 0), OP_EQ, 1);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 0, 1), OP_EQ, 1);
|
||||
|
||||
/* Test that we get 0 even with a connection in the appropriate
|
||||
* circumstances */
|
||||
tt_assert(router_is_already_dir_fetching(&test_ap, 0, 0) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(NULL, 1, 1) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(&null_addr_ap, 1, 1) == 0);
|
||||
tt_assert(router_is_already_dir_fetching(&zero_port_ap, 1, 1) == 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&test_ap, 0, 0), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(NULL, 1, 1), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&null_addr_ap, 1, 1), OP_EQ, 0);
|
||||
tt_int_op(router_is_already_dir_fetching(&zero_port_ap, 1, 1), OP_EQ, 0);
|
||||
|
||||
done:
|
||||
/* If a connection is never set up, connection_free chokes on it. */
|
||||
|
@ -743,7 +743,7 @@ test_state_load_from_disk(void *arg)
|
||||
|
||||
/* First try with a nonexistent path. */
|
||||
ret = disk_state_load_from_disk_impl("NONEXISTENTNONEXISTENT");
|
||||
tt_assert(ret == -ENOENT);
|
||||
tt_int_op(ret, OP_EQ, -ENOENT);
|
||||
|
||||
/* Now create a mock state directory and state file */
|
||||
#ifdef _WIN32
|
||||
@ -751,9 +751,9 @@ test_state_load_from_disk(void *arg)
|
||||
#else
|
||||
ret = mkdir(dir, 0700);
|
||||
#endif
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
ret = write_str_to_file(sr_state_path, sr_state_str, 0);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Try to load the directory itself. Should fail. */
|
||||
ret = disk_state_load_from_disk_impl(dir);
|
||||
@ -765,7 +765,7 @@ test_state_load_from_disk(void *arg)
|
||||
|
||||
/* Now try to load the correct file! */
|
||||
ret = disk_state_load_from_disk_impl(sr_state_path);
|
||||
tt_assert(ret == 0);
|
||||
tt_int_op(ret, OP_EQ, 0);
|
||||
|
||||
/* Check the content of the state */
|
||||
/* XXX check more deeply!!! */
|
||||
|
@ -61,8 +61,8 @@ test_socks_4_unsupported_commands(void *ptr)
|
||||
|
||||
/* SOCKS 4 Send BIND [02] to IP address 2.2.2.2:4369 */
|
||||
ADD_DATA(buf, "\x04\x02\x11\x11\x02\x02\x02\x02\x00");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == -1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, -1);
|
||||
tt_int_op(4,OP_EQ, socks->socks_version);
|
||||
tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
|
||||
|
||||
@ -80,8 +80,8 @@ test_socks_4_supported_commands(void *ptr)
|
||||
|
||||
/* SOCKS 4 Send CONNECT [01] to IP address 2.2.2.2:4370 */
|
||||
ADD_DATA(buf, "\x04\x01\x11\x12\x02\x02\x02\x03\x00");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == 1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(4,OP_EQ, socks->socks_version);
|
||||
tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
|
||||
tt_int_op(SOCKS_COMMAND_CONNECT,OP_EQ, socks->command);
|
||||
@ -95,8 +95,8 @@ test_socks_4_supported_commands(void *ptr)
|
||||
|
||||
/* SOCKS 4 Send CONNECT [01] to IP address 2.2.2.2:4369 with userid*/
|
||||
ADD_DATA(buf, "\x04\x01\x11\x12\x02\x02\x02\x04me\x00");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == 1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(4,OP_EQ, socks->socks_version);
|
||||
tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
|
||||
tt_int_op(SOCKS_COMMAND_CONNECT,OP_EQ, socks->command);
|
||||
@ -112,8 +112,8 @@ test_socks_4_supported_commands(void *ptr)
|
||||
|
||||
/* SOCKS 4a Send RESOLVE [F0] request for torproject.org */
|
||||
ADD_DATA(buf, "\x04\xF0\x01\x01\x00\x00\x00\x02me\x00torproject.org\x00");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == 1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(4,OP_EQ, socks->socks_version);
|
||||
tt_int_op(0,OP_EQ, socks->replylen); /* XXX: shouldn't tor reply? */
|
||||
tt_str_op("torproject.org",OP_EQ, socks->address);
|
||||
@ -218,8 +218,8 @@ test_socks_5_supported_commands(void *ptr)
|
||||
/* SOCKS 5 Send RESOLVE [F0] request for torproject.org:4369 */
|
||||
ADD_DATA(buf, "\x05\x01\x00");
|
||||
ADD_DATA(buf, "\x05\xF0\x00\x03\x0Etorproject.org\x01\x02");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == 1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(5,OP_EQ, socks->socks_version);
|
||||
tt_int_op(2,OP_EQ, socks->replylen);
|
||||
tt_int_op(5,OP_EQ, socks->reply[0]);
|
||||
@ -236,8 +236,8 @@ test_socks_5_supported_commands(void *ptr)
|
||||
ADD_DATA(buf, "\x05\xF0\x00\x03\x07");
|
||||
ADD_DATA(buf, "8.8.8.8");
|
||||
ADD_DATA(buf, "\x11\x11");
|
||||
tt_assert(fetch_from_buf_socks(buf,socks,get_options()->TestSocks,1)
|
||||
== 1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, 1),
|
||||
OP_EQ, 1);
|
||||
|
||||
tt_str_op("8.8.8.8", OP_EQ, socks->address);
|
||||
tt_int_op(4369, OP_EQ, socks->port);
|
||||
@ -253,8 +253,8 @@ test_socks_5_supported_commands(void *ptr)
|
||||
ADD_DATA(buf, "\x05\xF0\x00\x03\x27");
|
||||
ADD_DATA(buf, "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
||||
ADD_DATA(buf, "\x01\x02");
|
||||
tt_assert(fetch_from_buf_socks(buf,socks,get_options()->TestSocks,1)
|
||||
== -1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, 1),
|
||||
OP_EQ, -1);
|
||||
|
||||
tt_str_op("2001:0db8:85a3:0000:0000:8a2e:0370:7334", OP_EQ, socks->address);
|
||||
tt_int_op(258, OP_EQ, socks->port);
|
||||
@ -266,8 +266,8 @@ test_socks_5_supported_commands(void *ptr)
|
||||
/* SOCKS 5 Send RESOLVE_PTR [F1] for IP address 2.2.2.5 */
|
||||
ADD_DATA(buf, "\x05\x01\x00");
|
||||
ADD_DATA(buf, "\x05\xF1\x00\x01\x02\x02\x02\x05\x01\x03");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks, get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == 1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(5,OP_EQ, socks->socks_version);
|
||||
tt_int_op(2,OP_EQ, socks->replylen);
|
||||
tt_int_op(5,OP_EQ, socks->reply[0]);
|
||||
@ -378,9 +378,8 @@ test_socks_5_authenticate_with_data(void *ptr)
|
||||
/* SOCKS 5 Send username/password */
|
||||
/* SOCKS 5 Send CONNECT [01] to IP address 2.2.2.2:4369 */
|
||||
ADD_DATA(buf, "\x01\x02me\x03you\x05\x01\x00\x01\x02\x02\x02\x02\x11\x11");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks,
|
||||
get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == 1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, 1);
|
||||
tt_int_op(5,OP_EQ, socks->socks_version);
|
||||
tt_int_op(2,OP_EQ, socks->replylen);
|
||||
tt_int_op(1,OP_EQ, socks->reply[0]);
|
||||
@ -406,9 +405,8 @@ test_socks_5_auth_before_negotiation(void *ptr)
|
||||
|
||||
/* SOCKS 5 Send username/password */
|
||||
ADD_DATA(buf, "\x01\x02me\x02me");
|
||||
tt_assert(fetch_from_buf_socks(buf, socks,
|
||||
get_options()->TestSocks,
|
||||
get_options()->SafeSocks) == -1);
|
||||
tt_int_op(fetch_from_buf_socks(buf, socks, get_options()->TestSocks, get_options()->SafeSocks),
|
||||
OP_EQ, -1);
|
||||
tt_int_op(0,OP_EQ, socks->socks_version);
|
||||
tt_int_op(0,OP_EQ, socks->replylen);
|
||||
tt_int_op(0,OP_EQ, socks->reply[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user