[tor-commits] [tor/master] consdiffmgr: add tests for cdm_entry_get_sha3_value

nickm at torproject.org nickm at torproject.org
Mon Apr 24 15:05:43 UTC 2017


commit 6cc21aa89cc1b9dea6e5256722597e3bf07d1a20
Author: Nick Mathewson <nickm at torproject.org>
Date:   Sun Apr 16 15:36:20 2017 -0400

    consdiffmgr: add tests for cdm_entry_get_sha3_value
---
 src/or/consdiffmgr.c        |  2 +-
 src/or/consdiffmgr.h        |  3 +++
 src/test/test_consdiffmgr.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/src/or/consdiffmgr.c b/src/or/consdiffmgr.c
index 1c9c2a9..59d0f28 100644
--- a/src/or/consdiffmgr.c
+++ b/src/or/consdiffmgr.c
@@ -320,7 +320,7 @@ cdm_labels_prepend_sha3(config_line_t **labels,
  * given label, set <b>digest_out</b> to that value (decoded), and return 0.
  *
  * Return -1 if there is no such label, and -2 if it is badly formatted. */
-static int
+STATIC int
 cdm_entry_get_sha3_value(uint8_t *digest_out,
                          consensus_cache_entry_t *ent,
                          const char *label)
diff --git a/src/or/consdiffmgr.h b/src/or/consdiffmgr.h
index 3e89ea2..b6b7555 100644
--- a/src/or/consdiffmgr.h
+++ b/src/or/consdiffmgr.h
@@ -39,6 +39,9 @@ int consdiffmgr_validate(void);
 STATIC consensus_cache_t *cdm_cache_get(void);
 STATIC consensus_cache_entry_t *cdm_cache_lookup_consensus(
                           consensus_flavor_t flavor, time_t valid_after);
+STATIC int cdm_entry_get_sha3_value(uint8_t *digest_out,
+                                    consensus_cache_entry_t *ent,
+                                    const char *label);
 #endif
 
 #endif
diff --git a/src/test/test_consdiffmgr.c b/src/test/test_consdiffmgr.c
index a1b5983..0035029 100644
--- a/src/test/test_consdiffmgr.c
+++ b/src/test/test_consdiffmgr.c
@@ -221,6 +221,45 @@ test_consdiffmgr_init_failure(void *arg)
 #endif
 
 static void
+test_consdiffmgr_sha3_helper(void *arg)
+{
+  (void) arg;
+  consensus_cache_t *cache = cdm_cache_get(); // violate abstraction barrier
+  config_line_t *lines = NULL;
+  char *mem_op_hex_tmp = NULL;
+  config_line_prepend(&lines, "good-sha",
+                      "F00DF00DF00DF00DF00DF00DF00DF00D"
+                      "F00DF00DF00DF00DF00DF00DF00DF00D");
+  config_line_prepend(&lines, "short-sha",
+                      "F00DF00DF00DF00DF00DF00DF00DF00D"
+                      "F00DF00DF00DF00DF00DF00DF00DF0");
+  config_line_prepend(&lines, "long-sha",
+                      "F00DF00DF00DF00DF00DF00DF00DF00D"
+                      "F00DF00DF00DF00DF00DF00DF00DF00DF00D");
+  config_line_prepend(&lines, "not-sha",
+                      "F00DF00DF00DF00DF00DF00DF00DF00D"
+                      "F00DF00DF00DF00DF00DF00DF00DXXXX");
+  consensus_cache_entry_t *ent =
+    consensus_cache_add(cache, lines, (const uint8_t *)"Hi there", 8);
+
+  uint8_t buf[DIGEST256_LEN];
+  tt_int_op(-1, OP_EQ, cdm_entry_get_sha3_value(buf, NULL, "good-sha"));
+  tt_int_op(0, OP_EQ, cdm_entry_get_sha3_value(buf, ent, "good-sha"));
+  test_memeq_hex(buf, "F00DF00DF00DF00DF00DF00DF00DF00D"
+                      "F00DF00DF00DF00DF00DF00DF00DF00D");
+
+  tt_int_op(-1, OP_EQ, cdm_entry_get_sha3_value(buf, ent, "missing-sha"));
+  tt_int_op(-2, OP_EQ, cdm_entry_get_sha3_value(buf, ent, "short-sha"));
+  tt_int_op(-2, OP_EQ, cdm_entry_get_sha3_value(buf, ent, "long-sha"));
+  tt_int_op(-2, OP_EQ, cdm_entry_get_sha3_value(buf, ent, "not-sha"));
+
+ done:
+  consensus_cache_entry_decref(ent);
+  config_free_lines(lines);
+  tor_free(mem_op_hex_tmp);
+}
+
+static void
 test_consdiffmgr_add(void *arg)
 {
   (void) arg;
@@ -713,6 +752,7 @@ struct testcase_t consdiffmgr_tests[] = {
 #if 0
   { "init_failure", test_consdiffmgr_init_failure, TT_FORK, NULL, NULL },
 #endif
+  TEST(sha3_helper),
   TEST(add),
   TEST(make_diffs),
   TEST(diff_rules),
@@ -724,7 +764,6 @@ struct testcase_t consdiffmgr_tests[] = {
 
   // XXXX Test: no duplicate diff job is launched when a job is pending.
   // XXXX Test: register status when no pending entry existed?? (bug)
-  // XXXX Test: cdm_entry_get_sha3_value cases.
   // XXXX Test: sha3 mismatch on validation
   // XXXX Test: non-cacheing cases of replyfn().
 





More information about the tor-commits mailing list