aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_consdiffmgr.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-16 15:49:32 -0400
committerNick Mathewson <nickm@torproject.org>2017-04-24 11:01:40 -0400
commit2e9e2d023bfa7c524d82387d8d05427ab57f1fec (patch)
tree06d202b75880e609933ba345828dd3013742287c /src/test/test_consdiffmgr.c
parent6cc21aa89cc1b9dea6e5256722597e3bf07d1a20 (diff)
downloadtor-2e9e2d023bfa7c524d82387d8d05427ab57f1fec.tar.gz
tor-2e9e2d023bfa7c524d82387d8d05427ab57f1fec.zip
consdiffmgr: tests for consdiffmgr_validate()
Diffstat (limited to 'src/test/test_consdiffmgr.c')
-rw-r--r--src/test/test_consdiffmgr.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/src/test/test_consdiffmgr.c b/src/test/test_consdiffmgr.c
index 0035029a9b..eb2d20751d 100644
--- a/src/test/test_consdiffmgr.c
+++ b/src/test/test_consdiffmgr.c
@@ -745,6 +745,70 @@ test_consdiffmgr_cleanup_old_diffs(void *arg)
#undef N
}
+static void
+test_consdiffmgr_validate(void *arg)
+{
+ (void)arg;
+ config_line_t *lines = NULL;
+ consensus_cache_entry_t *ent = NULL;
+ consensus_cache_t *cache = cdm_cache_get(); // violate abstraction barrier
+ smartlist_t *vals = smartlist_new();
+
+ /* Put these: objects in the cache: one with a good sha3, one with bad sha3,
+ * one with a wrong sha3, and one with no sha3. */
+ config_line_prepend(&lines, "id", "wrong sha3");
+ config_line_prepend(&lines, "sha3-digest",
+ "F00DF00DF00DF00DF00DF00DF00DF00D"
+ "F00DF00DF00DF00DF00DF00DF00DF00D");
+ ent = consensus_cache_add(cache, lines, (const uint8_t *)"Hi there", 8);
+ consensus_cache_entry_decref(ent);
+ config_free_lines(lines);
+ lines = NULL;
+
+ config_line_prepend(&lines, "id", "bad sha3");
+ config_line_prepend(&lines, "sha3-digest",
+ "now is the winter of our dicotheque");
+ ent = consensus_cache_add(cache, lines, (const uint8_t *)"Hi there", 8);
+ consensus_cache_entry_decref(ent);
+ config_free_lines(lines);
+ lines = NULL;
+
+ config_line_prepend(&lines, "id", "no sha3");
+ ent = consensus_cache_add(cache, lines, (const uint8_t *)"Hi there", 8);
+ consensus_cache_entry_decref(ent);
+ config_free_lines(lines);
+ lines = NULL;
+
+ config_line_prepend(&lines, "id", "good sha3");
+ config_line_prepend(&lines, "sha3-digest",
+ "8d8b1998616cd6b4c4055da8d38728dc"
+ "93c758d4131a53c7d81aa6337dee1c05");
+ ent = consensus_cache_add(cache, lines, (const uint8_t *)"Hi there", 8);
+ consensus_cache_entry_decref(ent);
+ config_free_lines(lines);
+ lines = NULL;
+
+ cdm_reload();
+ cache = cdm_cache_get();
+ tt_int_op(1, OP_EQ, consdiffmgr_validate());
+
+ consensus_cache_find_all(vals, cache, "id", "good sha3");
+ tt_int_op(smartlist_len(vals), OP_EQ, 1);
+ smartlist_clear(vals);
+
+ consensus_cache_find_all(vals, cache, "id", "no sha3");
+ tt_int_op(smartlist_len(vals), OP_EQ, 1);
+ smartlist_clear(vals);
+
+ consensus_cache_find_all(vals, cache, "id", "wrong sha3");
+ tt_int_op(smartlist_len(vals), OP_EQ, 0);
+ consensus_cache_find_all(vals, cache, "id", "bad sha3");
+ tt_int_op(smartlist_len(vals), OP_EQ, 0);
+
+ done:
+ smartlist_free(vals);
+}
+
#define TEST(name) \
{ #name, test_consdiffmgr_ ## name , TT_FORK, &setup_diffmgr, NULL }
@@ -761,10 +825,10 @@ struct testcase_t consdiffmgr_tests[] = {
TEST(cleanup_bad_valid_after),
TEST(cleanup_no_valid_after),
TEST(cleanup_old_diffs),
+ TEST(validate),
// 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: sha3 mismatch on validation
// XXXX Test: non-cacheing cases of replyfn().
END_OF_TESTCASES