aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_hs_service.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-02-13 15:31:34 +0200
committerDavid Goulet <dgoulet@torproject.org>2017-04-18 11:03:15 -0400
commite1a59ade9557cc2a7b0345397148dcfd2e16d35c (patch)
tree9bc5f37119a4e64a8d8400ea91d62dad2643c818 /src/test/test_hs_service.c
parentb081a7ed21ae729f6e195715e130edaca3e0b7fe (diff)
downloadtor-e1a59ade9557cc2a7b0345397148dcfd2e16d35c.tar.gz
tor-e1a59ade9557cc2a7b0345397148dcfd2e16d35c.zip
prop224: Add time period functions and unittests
This will be used by the build blinded key functions. 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.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index ec9cc4579b..8207ddc160 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -6,6 +6,7 @@
* \brief Test hidden service functionality.
*/
+#define HS_COMMON_PRIVATE
#define HS_SERVICE_PRIVATE
#define HS_INTROPOINT_PRIVATE
@@ -14,6 +15,7 @@
#include "crypto.h"
#include "hs/cell_establish_intro.h"
+#include "hs_common.h"
#include "hs_service.h"
#include "hs_intropoint.h"
@@ -196,12 +198,52 @@ test_hs_ntor(void *arg)
;
}
+/** Test that our HS time period calculation functions work properly */
+static void
+test_time_period(void *arg)
+{
+ (void) arg;
+ unsigned int tn;
+ int retval;
+ time_t fake_time;
+
+ /* Let's do the example in prop224 section [TIME-PERIODS] */
+ retval = parse_rfc1123_time("Wed, 13 Apr 2016 11:00:00 UTC",
+ &fake_time);
+ tt_int_op(retval, ==, 0);
+
+ /* Check that the time period number is right */
+ tn = get_time_period_num(fake_time);
+ tt_int_op(tn, ==, 16903);
+
+ /* Increase current time to 11:59:59 UTC and check that the time period
+ number is still the same */
+ fake_time += 3599;
+ tn = get_time_period_num(fake_time);
+ tt_int_op(tn, ==, 16903);
+
+ /* Now take time to 12:00:00 UTC and check that the time period rotated */
+ fake_time += 1;
+ tn = get_time_period_num(fake_time);
+ tt_int_op(tn, ==, 16904);
+
+ /* Now also check our hs_get_next_time_period_num() function */
+ tn = hs_get_next_time_period_num(fake_time);
+ tt_int_op(tn, ==, 16905);
+
+ done:
+ ;
+}
+
struct testcase_t hs_service_tests[] = {
{ "gen_establish_intro_cell", test_gen_establish_intro_cell, TT_FORK,
NULL, NULL },
{ "gen_establish_intro_cell_bad", test_gen_establish_intro_cell_bad, TT_FORK,
NULL, NULL },
- { "hs_ntor", test_hs_ntor, TT_FORK, NULL, NULL },
+ { "hs_ntor", test_hs_ntor, TT_FORK,
+ NULL, NULL },
+ { "time_period", test_time_period, TT_FORK,
+ NULL, NULL },
END_OF_TESTCASES
};