summaryrefslogtreecommitdiff
path: root/src/test/test_hs_service.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-07-24 13:03:19 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commitb47139d7583ff247fcdd07904144dc99c412028a (patch)
tree951a7eb73f75313bbb1d7d01f12edb5c7692fbe0 /src/test/test_hs_service.c
parent6f046b2191ed1a10e9058fcc49491b8db5a96280 (diff)
downloadtor-b47139d7583ff247fcdd07904144dc99c412028a.tar.gz
tor-b47139d7583ff247fcdd07904144dc99c412028a.zip
test: Unit tests for the revision counter state file codethe
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_hs_service.c')
-rw-r--r--src/test/test_hs_service.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 30f1682d8c..664277b198 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -1194,6 +1194,65 @@ test_upload_desctriptors(void *arg)
UNMOCK(hs_overlap_mode_is_active);
}
+/** Test the functions that save and load HS revision counters to state. */
+static void
+test_revision_counter_state(void *arg)
+{
+ char *state_line_one = NULL;
+ char *state_line_two = NULL;
+
+ hs_service_descriptor_t *desc_one = service_descriptor_new();
+ hs_service_descriptor_t *desc_two = service_descriptor_new();
+
+ (void) arg;
+
+ /* Prepare both descriptors */
+ desc_one->desc->plaintext_data.revision_counter = 42;
+ desc_two->desc->plaintext_data.revision_counter = 240;
+ memset(&desc_one->blinded_kp.pubkey.pubkey, '\x42',
+ sizeof(desc_one->blinded_kp.pubkey.pubkey));
+ memset(&desc_two->blinded_kp.pubkey.pubkey, '\xf0',
+ sizeof(desc_one->blinded_kp.pubkey.pubkey));
+
+ /* Turn the descriptor rev counters into state lines */
+ state_line_one = encode_desc_rev_counter_for_state(desc_one);
+ tt_str_op(state_line_one, OP_EQ,
+ "QkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkI 42");
+
+ state_line_two = encode_desc_rev_counter_for_state(desc_two);
+ tt_str_op(state_line_two, OP_EQ,
+ "8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PA 240");
+
+ /* Now let's test our state parsing function: */
+ int service_found;
+ uint64_t cached_rev_counter;
+
+ /* First's try with wrong pubkey and check that no service was found */
+ cached_rev_counter =check_state_line_for_service_rev_counter(state_line_one,
+ &desc_two->blinded_kp.pubkey,
+ &service_found);
+ tt_int_op(service_found, OP_EQ, 0);
+
+ /* Now let's try with the right pubkeys */
+ cached_rev_counter =check_state_line_for_service_rev_counter(state_line_one,
+ &desc_one->blinded_kp.pubkey,
+ &service_found);
+ tt_int_op(service_found, OP_EQ, 1);
+ tt_int_op(cached_rev_counter, OP_EQ, 42);
+
+ cached_rev_counter =check_state_line_for_service_rev_counter(state_line_two,
+ &desc_two->blinded_kp.pubkey,
+ &service_found);
+ tt_int_op(service_found, OP_EQ, 1);
+ tt_int_op(cached_rev_counter, OP_EQ, 240);
+
+ done:
+ tor_free(state_line_one);
+ tor_free(state_line_two);
+ service_descriptor_free(desc_one);
+ service_descriptor_free(desc_two);
+}
+
struct testcase_t hs_service_tests[] = {
{ "e2e_rend_circuit_setup", test_e2e_rend_circuit_setup, TT_FORK,
NULL, NULL },
@@ -1221,6 +1280,8 @@ struct testcase_t hs_service_tests[] = {
NULL, NULL },
{ "upload_desctriptors", test_upload_desctriptors, TT_FORK,
NULL, NULL },
+ { "revision_counter_state", test_revision_counter_state, TT_FORK,
+ NULL, NULL },
END_OF_TESTCASES
};