diff options
author | Qingping Hou <dave2008713@gmail.com> | 2014-02-04 19:33:48 -0500 |
---|---|---|
committer | Qingping Hou <dave2008713@gmail.com> | 2014-02-06 16:13:55 -0500 |
commit | bf66ff915aa3b97922c3313542ed2f2f554d9c57 (patch) | |
tree | af3e53609c0e2954a394887f12d8d2241fc940ed /src/test/test_hs.c | |
parent | 2d41cab1502666eaace21f10385964737d246388 (diff) | |
download | tor-bf66ff915aa3b97922c3313542ed2f2f554d9c57.tar.gz tor-bf66ff915aa3b97922c3313542ed2f2f554d9c57.zip |
fix longname returned in HS_DESC control events
According to control spec, longname should not contain any spaces and is
consists only of identy_digest + nickname
added two functions:
* node_get_verbose_nickname_by_id()
* node_describe_longname_by_id()
Diffstat (limited to 'src/test/test_hs.c')
-rw-r--r-- | src/test/test_hs.c | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/src/test/test_hs.c b/src/test/test_hs.c index 75c9b62871..99ef7dd570 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -11,6 +11,17 @@ #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 @@ -31,6 +42,19 @@ send_control_event_string_replacement(uint16_t event, event_format_t which, 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. @@ -39,8 +63,6 @@ static void test_hs_desc_event(void *arg) { #define STR_HS_ADDR "ajhb7kljbiru65qo" - #define STR_HS_DIR_LONGNAME \ - "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=TestDir at 1.2.3.4" #define STR_HS_ID "b3oeducbhjmbqmgw2i3jtz4fekkrinwj" rend_data_t rend_query; @@ -49,6 +71,8 @@ test_hs_desc_event(void *arg) (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, @@ -56,44 +80,44 @@ test_hs_desc_event(void *arg) rend_query.auth_type = 0; /* test request event */ - control_event_hs_descriptor_requested(&rend_query, STR_HS_DIR_LONGNAME, + 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_HS_DIR_LONGNAME\ - " "STR_HS_ID"\r\n"; + expected_msg = "650 HS_DESC REQUESTED "STR_HS_ADDR" NO_AUTH "\ + STR_HSDIR_EXIST_LONGNAME" "STR_HS_ID"\r\n"; test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); /* test received event */ rend_query.auth_type = 1; - control_event_hs_descriptor_received(&rend_query, STR_HS_DIR_LONGNAME); - expected_msg = - "650 HS_DESC RECEIVED "STR_HS_ADDR" BASIC_AUTH "STR_HS_DIR_LONGNAME"\r\n"; + 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"; test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); /* test failed event */ rend_query.auth_type = 2; - control_event_hs_descriptor_failed(&rend_query, STR_HS_DIR_LONGNAME); - expected_msg = - "650 HS_DESC FAILED "STR_HS_ADDR" STEALTH_AUTH "STR_HS_DIR_LONGNAME"\r\n"; + 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"; test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); /* test invalid auth type */ rend_query.auth_type = 999; - control_event_hs_descriptor_failed(&rend_query, STR_HS_DIR_LONGNAME); - expected_msg = - "650 HS_DESC FAILED "STR_HS_ADDR" UNKNOWN "STR_HS_DIR_LONGNAME"\r\n"; + 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"; test_assert(received_msg); test_streq(received_msg, expected_msg); tor_free(received_msg); done: UNMOCK(send_control_event_string); + UNMOCK(node_describe_longname_by_id); tor_free(received_msg); } |