mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-09-22 22:14:58 +02:00
0243895792
This should get rid of most of the users of the old test_* functions. Some are in macros and will need manual cleanup, though. This patch is for 13119, and was automatically generated with these scripts. The perl scripts are there because coccinelle hates operators as macro arguments. ------------------------------ s/==,/_X_EQ_,/g; s/!=,/_X_NE_,/g; s/<,/_X_LT_,/g; s/>,/_X_GT_,/g; s/>=,/_X_GEQ_,/g; s/<=,/_X_LEQ_,/g; ------------------------------ @@ expression a; identifier func; @@ func (...) { <... -test_fail_msg +TT_DIE ( +( a +) ) ...> } @@ identifier func; @@ func (...) { <... -test_fail() +TT_DIE(("Assertion failed.")) ...> } @@ expression a; identifier func; @@ func (...) { <... -test_assert +tt_assert (a) ...> } @@ expression a, b; identifier func; @@ func (...) { <... -test_eq +tt_int_op (a, +_X_EQ_, b) ...> } @@ expression a, b; identifier func; @@ func (...) { <... -test_neq +tt_int_op (a, +_X_NEQ_, b) ...> } @@ expression a, b; identifier func; @@ func (...) { <... -test_streq +tt_str_op (a, +_X_EQ_, b) ...> } @@ expression a, b; identifier func; @@ func (...) { <... -test_strneq +tt_str_op (a, +_X_NEQ_, b) ...> } @@ expression a, b; identifier func; @@ func (...) { <... -test_eq_ptr +tt_ptr_op (a, +_X_EQ_, b) ...> } @@ expression a, b; identifier func; @@ func() { <... -test_neq_ptr +tt_ptr_op (a, +_X_NEQ_, b) ...> } @@ expression a, b, len; identifier func; @@ func (...) { <... -test_memeq +tt_mem_op (a, +_X_EQ_, b, len) ...> } @@ expression a, b, len; identifier func; @@ func (...) { <... -test_memneq +tt_mem_op (a, +_X_NEQ_, b, len) ...> } ------------------------------ @@ char a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a == b +a, _X_EQ_, b ) ...> } @@ int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a == b +a, _X_EQ_, b ) ...> } @@ long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a == b +a, _X_EQ_, b ) ...> } @@ unsigned int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a == b +a, _X_EQ_, b ) ...> } @@ unsigned long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a == b +a, _X_EQ_, b ) ...> } @@ char a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a != b +a, _X_NEQ_, b ) ...> } @@ int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a != b +a, _X_NEQ_, b ) ...> } @@ long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a != b +a, _X_NEQ_, b ) ...> } @@ unsigned int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a != b +a, _X_NEQ_, b ) ...> } @@ unsigned long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a != b +a, _X_NEQ_, b ) ...> } @@ char a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a >= b +a, _X_GEQ_, b ) ...> } @@ int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a >= b +a, _X_GEQ_, b ) ...> } @@ long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a >= b +a, _X_GEQ_, b ) ...> } @@ unsigned int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a >= b +a, _X_GEQ_, b ) ...> } @@ unsigned long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a >= b +a, _X_GEQ_, b ) ...> } @@ char a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a <= b +a, _X_LEQ_, b ) ...> } @@ int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a <= b +a, _X_LEQ_, b ) ...> } @@ long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a <= b +a, _X_LEQ_, b ) ...> } @@ unsigned int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a <= b +a, _X_LEQ_, b ) ...> } @@ unsigned long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a <= b +a, _X_LEQ_, b ) ...> } @@ char a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a > b +a, _X_GT_, b ) ...> } @@ int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a > b +a, _X_GT_, b ) ...> } @@ long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a > b +a, _X_GT_, b ) ...> } @@ unsigned int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a > b +a, _X_GT_, b ) ...> } @@ unsigned long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a > b +a, _X_GT_, b ) ...> } @@ char a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a < b +a, _X_LT_, b ) ...> } @@ int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a < b +a, _X_LT_, b ) ...> } @@ long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_int_op ( -a < b +a, _X_LT_, b ) ...> } @@ unsigned int a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a < b +a, _X_LT_, b ) ...> } @@ unsigned long a, b; identifier func; @@ func (...) { <... -tt_assert +tt_uint_op ( -a < b +a, _X_LT_, b ) ...> } ------------------------------ s/_X_NEQ_/!=/g; s/_X_NE_/!=/g; s/_X_EQ_/==/g; s/_X_GT_/>/g; s/_X_LT_/</g; s/_X_GEQ_/>=/g; s/_X_LEQ_/<=/g; s/test_mem_op\(/tt_mem_op\(/g;
130 lines
4.0 KiB
C
130 lines
4.0 KiB
C
/* Copyright (c) 2007-2013, The Tor Project, Inc. */
|
|
/* See LICENSE for licensing information */
|
|
|
|
/**
|
|
* \file test_hs.c
|
|
* \brief Unit tests for hidden service.
|
|
**/
|
|
|
|
#define CONTROL_PRIVATE
|
|
#include "or.h"
|
|
#include "test.h"
|
|
#include "control.h"
|
|
|
|
/* mock ID digest and longname for node that's in nodelist */
|
|
#define HSDIR_EXIST_ID "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA" \
|
|
"\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
|
|
#define STR_HSDIR_EXIST_LONGNAME \
|
|
"$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=TestDir"
|
|
/* mock ID digest and longname for node that's not in nodelist */
|
|
#define HSDIR_NONE_EXIST_ID "\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB" \
|
|
"\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xBB"
|
|
#define STR_HSDIR_NONE_EXIST_LONGNAME \
|
|
"$BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
|
|
|
|
/* Helper global variable for hidden service descriptor event test.
|
|
* It's used as a pointer to dynamically created message buffer in
|
|
* send_control_event_string_replacement function, which mocks
|
|
* send_control_event_string function.
|
|
*
|
|
* Always free it after use! */
|
|
static char *received_msg = NULL;
|
|
|
|
/** Mock function for send_control_event_string
|
|
*/
|
|
static void
|
|
send_control_event_string_replacement(uint16_t event, event_format_t which,
|
|
const char *msg)
|
|
{
|
|
(void) event;
|
|
(void) which;
|
|
tor_free(received_msg);
|
|
received_msg = tor_strdup(msg);
|
|
}
|
|
|
|
/** Mock function for node_describe_longname_by_id, it returns either
|
|
* STR_HSDIR_EXIST_LONGNAME or STR_HSDIR_NONE_EXIST_LONGNAME
|
|
*/
|
|
static const char *
|
|
node_describe_longname_by_id_replacement(const char *id_digest)
|
|
{
|
|
if (!strcmp(id_digest, HSDIR_EXIST_ID)) {
|
|
return STR_HSDIR_EXIST_LONGNAME;
|
|
} else {
|
|
return STR_HSDIR_NONE_EXIST_LONGNAME;
|
|
}
|
|
}
|
|
|
|
/** Make sure each hidden service descriptor async event generation
|
|
*
|
|
* function generates the message in expected format.
|
|
*/
|
|
static void
|
|
test_hs_desc_event(void *arg)
|
|
{
|
|
#define STR_HS_ADDR "ajhb7kljbiru65qo"
|
|
#define STR_HS_ID "b3oeducbhjmbqmgw2i3jtz4fekkrinwj"
|
|
|
|
rend_data_t rend_query;
|
|
const char *expected_msg;
|
|
|
|
(void) arg;
|
|
MOCK(send_control_event_string,
|
|
send_control_event_string_replacement);
|
|
MOCK(node_describe_longname_by_id,
|
|
node_describe_longname_by_id_replacement);
|
|
|
|
/* setup rend_query struct */
|
|
strncpy(rend_query.onion_address, STR_HS_ADDR,
|
|
REND_SERVICE_ID_LEN_BASE32+1);
|
|
rend_query.auth_type = 0;
|
|
|
|
/* test request event */
|
|
control_event_hs_descriptor_requested(&rend_query, HSDIR_EXIST_ID,
|
|
STR_HS_ID);
|
|
expected_msg = "650 HS_DESC REQUESTED "STR_HS_ADDR" NO_AUTH "\
|
|
STR_HSDIR_EXIST_LONGNAME" "STR_HS_ID"\r\n";
|
|
tt_assert(received_msg);
|
|
tt_str_op(received_msg,==, expected_msg);
|
|
tor_free(received_msg);
|
|
|
|
/* test received event */
|
|
rend_query.auth_type = 1;
|
|
control_event_hs_descriptor_received(&rend_query, HSDIR_EXIST_ID);
|
|
expected_msg = "650 HS_DESC RECEIVED "STR_HS_ADDR" BASIC_AUTH "\
|
|
STR_HSDIR_EXIST_LONGNAME"\r\n";
|
|
tt_assert(received_msg);
|
|
tt_str_op(received_msg,==, expected_msg);
|
|
tor_free(received_msg);
|
|
|
|
/* test failed event */
|
|
rend_query.auth_type = 2;
|
|
control_event_hs_descriptor_failed(&rend_query, HSDIR_NONE_EXIST_ID);
|
|
expected_msg = "650 HS_DESC FAILED "STR_HS_ADDR" STEALTH_AUTH "\
|
|
STR_HSDIR_NONE_EXIST_LONGNAME"\r\n";
|
|
tt_assert(received_msg);
|
|
tt_str_op(received_msg,==, expected_msg);
|
|
tor_free(received_msg);
|
|
|
|
/* test invalid auth type */
|
|
rend_query.auth_type = 999;
|
|
control_event_hs_descriptor_failed(&rend_query, HSDIR_EXIST_ID);
|
|
expected_msg = "650 HS_DESC FAILED "STR_HS_ADDR" UNKNOWN "\
|
|
STR_HSDIR_EXIST_LONGNAME"\r\n";
|
|
tt_assert(received_msg);
|
|
tt_str_op(received_msg,==, expected_msg);
|
|
tor_free(received_msg);
|
|
|
|
done:
|
|
UNMOCK(send_control_event_string);
|
|
UNMOCK(node_describe_longname_by_id);
|
|
tor_free(received_msg);
|
|
}
|
|
|
|
struct testcase_t hs_tests[] = {
|
|
{ "hs_desc_event", test_hs_desc_event, TT_FORK,
|
|
NULL, NULL },
|
|
END_OF_TESTCASES
|
|
};
|
|
|