diff options
author | George Kadianakis <desnacked@riseup.net> | 2017-08-05 23:25:44 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-08 20:29:35 -0400 |
commit | e70341deb7dd8a8f50b872e9f7f999a113bb62b0 (patch) | |
tree | d6412177462e9ea8eec2c173493f5d7dea8c9504 /src/test/test_hs_common.c | |
parent | 4a1b57e9b00c8474ada28dd052a2de73a1e9c641 (diff) | |
download | tor-e70341deb7dd8a8f50b872e9f7f999a113bb62b0.tar.gz tor-e70341deb7dd8a8f50b872e9f7f999a113bb62b0.zip |
prop224 tests: Better HS address tests.
Diffstat (limited to 'src/test/test_hs_common.c')
-rw-r--r-- | src/test/test_hs_common.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c index 60577a2a50..65c6948382 100644 --- a/src/test/test_hs_common.c +++ b/src/test/test_hs_common.c @@ -7,6 +7,7 @@ */ #define HS_COMMON_PRIVATE +#define HS_SERVICE_PRIVATE #include "test.h" #include "test_helpers.h" @@ -14,6 +15,7 @@ #include "hs_test_helpers.h" #include "hs_common.h" +#include "hs_service.h" #include "config.h" /** Test the validation of HS v3 addresses */ @@ -70,6 +72,18 @@ test_validate_address(void *arg) ; } +static int +mock_write_str_to_file(const char *path, const char *str, int bin) +{ + (void)bin; + tt_str_op(path, OP_EQ, "/double/five/squared"); + tt_str_op(str, OP_EQ, + "ijbeeqscijbeeqscijbeeqscijbeeqscijbeeqscijbeeqscijbezhid.onion\n"); + + done: + return 0; +} + /** Test building HS v3 onion addresses */ static void test_build_address(void *arg) @@ -77,9 +91,12 @@ test_build_address(void *arg) int ret; char onion_addr[HS_SERVICE_ADDR_LEN_BASE32 + 1]; ed25519_public_key_t pubkey; + hs_service_t *service = NULL; (void) arg; + MOCK(write_str_to_file, mock_write_str_to_file); + /* The following has been created with hs_build_address.py script that * follows proposal 224 specification to build an onion address. */ static const char *test_addr = @@ -94,8 +111,14 @@ test_build_address(void *arg) ret = hs_address_is_valid(onion_addr); tt_int_op(ret, OP_EQ, 1); + service = tor_malloc_zero(sizeof(hs_service_t)); + memcpy(service->onion_address, onion_addr, sizeof(service->onion_address)); + tor_asprintf(&service->config.directory_path, "/double/five"); + ret = write_address_to_file(service, "squared"); + tt_int_op(ret, OP_EQ, 0); + done: - ; + hs_service_free(service); } /** Test that our HS time period calculation functions work properly */ |