mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
prop224 tests: Better HS address tests.
This commit is contained in:
parent
4a1b57e9b0
commit
e70341deb7
@ -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;
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user