mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 07:07:52 +01:00
consdiffmgr: add tests for cdm_entry_get_sha3_value
This commit is contained in:
parent
bb38657b77
commit
6cc21aa89c
3 changed files with 44 additions and 2 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -220,6 +220,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)
|
||||
{
|
||||
|
@ -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().
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue