|
@@ -2217,6 +2217,31 @@ test_dir_handle_get_status_vote_next_authority_not_found(void* data)
|
|
|
tor_free(header);
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+test_dir_handle_get_status_vote_next_bandwidth_not_found(void* data)
|
|
|
+{
|
|
|
+ dir_connection_t *conn = NULL;
|
|
|
+ char *header = NULL;
|
|
|
+ (void) data;
|
|
|
+
|
|
|
+ MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
|
|
+
|
|
|
+ conn = new_dir_conn();
|
|
|
+
|
|
|
+ tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
|
|
|
+ GET("/tor/status-vote/next/bandwdith"), NULL, 0));
|
|
|
+
|
|
|
+ fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
|
|
|
+ NULL, NULL, 1, 0);
|
|
|
+ tt_assert(header);
|
|
|
+ tt_str_op(NOT_FOUND, OP_EQ, header);
|
|
|
+
|
|
|
+ done:
|
|
|
+ UNMOCK(connection_write_to_buf_impl_);
|
|
|
+ connection_free_minimal(TO_CONN(conn));
|
|
|
+ tor_free(header);
|
|
|
+}
|
|
|
+
|
|
|
NS_DECL(const char*,
|
|
|
dirvote_get_pending_consensus, (consensus_flavor_t flav));
|
|
|
|
|
@@ -2454,6 +2479,55 @@ test_dir_handle_get_status_vote_next_authority(void* data)
|
|
|
dirvote_free_all();
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+test_dir_handle_get_status_vote_next_bandwidth(void* data)
|
|
|
+{
|
|
|
+ dir_connection_t *conn = NULL;
|
|
|
+ char *header = NULL, *body = NULL;
|
|
|
+ size_t body_used = 0;
|
|
|
+ (void) data;
|
|
|
+
|
|
|
+ const char *content =
|
|
|
+ "1541171221\n"
|
|
|
+ "node_id=$68A483E05A2ABDCA6DA5A3EF8DB5177638A27F80 "
|
|
|
+ "master_key_ed25519=YaqV4vbvPYKucElk297eVdNArDz9HtIwUoIeo0+cVIpQ "
|
|
|
+ "bw=760 nick=Test time=2018-05-08T16:13:26\n";
|
|
|
+
|
|
|
+ init_mock_options();
|
|
|
+ MOCK(get_options, mock_get_options);
|
|
|
+ mock_options->V3BandwidthsFile = tor_strdup(
|
|
|
+ get_fname_rnd("V3BandwidthsFile")
|
|
|
+ );
|
|
|
+
|
|
|
+ write_str_to_file(mock_options->V3BandwidthsFile, content, 0);
|
|
|
+
|
|
|
+ MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
|
|
|
+
|
|
|
+ conn = new_dir_conn();
|
|
|
+ tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
|
|
|
+ GET("/tor/status-vote/next/bandwidth"), NULL, 0));
|
|
|
+
|
|
|
+ fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
|
|
|
+ &body, &body_used, strlen(content)+1, 0);
|
|
|
+
|
|
|
+ tt_assert(header);
|
|
|
+ tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
|
|
|
+ tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
|
|
|
+ tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
|
|
|
+ tt_assert(strstr(header, "Content-Length: 167\r\n"));
|
|
|
+
|
|
|
+ tt_int_op(body_used, OP_EQ, strlen(body));
|
|
|
+ tt_str_op(content, OP_EQ, body);
|
|
|
+
|
|
|
+ done:
|
|
|
+ UNMOCK(get_options);
|
|
|
+ UNMOCK(connection_write_to_buf_impl_);
|
|
|
+ connection_free_minimal(TO_CONN(conn));
|
|
|
+ tor_free(header);
|
|
|
+ tor_free(body);
|
|
|
+ or_options_free(mock_options); mock_options = NULL;
|
|
|
+}
|
|
|
+
|
|
|
static void
|
|
|
test_dir_handle_get_status_vote_current_authority(void* data)
|
|
|
{
|
|
@@ -2627,6 +2701,8 @@ struct testcase_t dir_handle_get_tests[] = {
|
|
|
DIR_HANDLE_CMD(status_vote_current_authority, 0),
|
|
|
DIR_HANDLE_CMD(status_vote_next_authority_not_found, 0),
|
|
|
DIR_HANDLE_CMD(status_vote_next_authority, 0),
|
|
|
+ DIR_HANDLE_CMD(status_vote_next_bandwidth_not_found, 0),
|
|
|
+ DIR_HANDLE_CMD(status_vote_next_bandwidth, 0),
|
|
|
DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_enough_sigs, TT_FORK),
|
|
|
DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_found, TT_FORK),
|
|
|
DIR_HANDLE_CMD(status_vote_current_consensus_too_old, TT_FORK),
|