[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] prop224 tests: Better HS address tests.



commit e70341deb7dd8a8f50b872e9f7f999a113bb62b0
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Sat Aug 5 23:25:44 2017 +0300

    prop224 tests: Better HS address tests.
---
 src/or/hs_service.c       |  2 +-
 src/or/hs_service.h       |  3 +++
 src/test/test_hs_common.c | 25 ++++++++++++++++++++++++-
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index 43528a428..6cb24a19a 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -848,7 +848,7 @@ register_all_services(void)
 
 /* Write the onion address of a given service to the given filename fname_ in
  * the service directory. Return 0 on success else -1 on error. */
-static int
+STATIC int
 write_address_to_file(const hs_service_t *service, const char *fname_)
 {
   int ret = -1;
diff --git a/src/or/hs_service.h b/src/or/hs_service.h
index 93d2710cd..8d613d23e 100644
--- a/src/or/hs_service.h
+++ b/src/or/hs_service.h
@@ -335,6 +335,9 @@ check_state_line_for_service_rev_counter(const char *state_line,
                                     const ed25519_public_key_t *blinded_pubkey,
                                     int *service_found_out);
 
+STATIC int
+write_address_to_file(const hs_service_t *service, const char *fname_);
+
 #endif /* TOR_UNIT_TESTS */
 
 #endif /* HS_SERVICE_PRIVATE */
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index 60577a2a5..65c694838 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 */



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits