1 /* Copyright (c) 2014, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #define ROUTERLIST_PRIVATE
6 #include "routerlist.h"
10 /* 4 digests + 3 sep + pre + post + NULL */
11 static char output
[4*BASE64_DIGEST256_LEN
+3+2+2+1];
14 mock_get_from_dirserver(uint8_t dir_purpose
, uint8_t router_purpose
,
15 const char *resource
, int pds_flags
,
16 download_want_authority_t want_authority
)
23 strlcpy(output
, resource
, sizeof(output
));
29 test_routerlist_initiate_descriptor_downloads(void *arg
)
31 const char *prose
= "unhurried and wise, we perceive.";
32 smartlist_t
*digests
= smartlist_new();
35 for (int i
= 0; i
< 20; i
++) {
36 smartlist_add(digests
, (char*)prose
);
39 MOCK(directory_get_from_dirserver
, mock_get_from_dirserver
);
40 initiate_descriptor_downloads(NULL
, DIR_PURPOSE_FETCH_MICRODESC
,
42 UNMOCK(directory_get_from_dirserver
);
44 tt_str_op(output
, OP_EQ
, "d/"
45 "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
46 "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
47 "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
48 "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4"
52 smartlist_free(digests
);
58 mock_initiate_descriptor_downloads(const routerstatus_t
*source
,
59 int purpose
, smartlist_t
*digests
,
60 int lo
, int hi
, int pds_flags
)
72 test_routerlist_launch_descriptor_downloads(void *arg
)
74 smartlist_t
*downloadable
= smartlist_new();
75 time_t now
= time(NULL
);
79 for (int i
= 0; i
< 100; i
++) {
80 cp
= tor_malloc(DIGEST256_LEN
);
82 crypto_rand(cp
, DIGEST256_LEN
);
83 smartlist_add(downloadable
, cp
);
86 MOCK(initiate_descriptor_downloads
, mock_initiate_descriptor_downloads
);
87 launch_descriptor_downloads(DIR_PURPOSE_FETCH_MICRODESC
, downloadable
,
89 tt_int_op(3, ==, count
);
90 UNMOCK(initiate_descriptor_downloads
);
93 SMARTLIST_FOREACH(downloadable
, char *, cp1
, tor_free(cp1
));
94 smartlist_free(downloadable
);
97 #define NODE(name, flags) \
98 { #name, test_routerlist_##name, (flags), NULL, NULL }
100 struct testcase_t routerlist_tests
[] = {
101 NODE(initiate_descriptor_downloads
, 0),
102 NODE(launch_descriptor_downloads
, 0),