diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-01-30 07:36:55 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-01-30 07:36:55 -0500 |
commit | fac8d40886a03d442ed9f8c18df5ed017b1e6dd0 (patch) | |
tree | ebaa6185038792b896ce0f7fc147ef1a67f08599 /src/test | |
parent | d1e52d9a2a26c1bf9f80b237e692c72517c30495 (diff) | |
parent | b4a8fd895802801198229574c55b3df975aa2244 (diff) | |
download | tor-fac8d40886a03d442ed9f8c18df5ed017b1e6dd0.tar.gz tor-fac8d40886a03d442ed9f8c18df5ed017b1e6dd0.zip |
Merge remote-tracking branch 'public/prop227_v2'
Conflicts:
src/test/test_dir.c
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_dir.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 991e613cb6..84e80ea760 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -2954,6 +2954,152 @@ test_dir_fetch_type(void *arg) done: ; } +static void +test_dir_packages(void *arg) +{ + smartlist_t *votes = smartlist_new(); + char *res = NULL; + (void)arg; + +#define BAD(s) \ + tt_int_op(0, ==, validate_recommended_package_line(s)); +#define GOOD(s) \ + tt_int_op(1, ==, validate_recommended_package_line(s)); + GOOD("tor 0.2.6.3-alpha " + "http://torproject.example.com/dist/tor-0.2.6.3-alpha.tar.gz " + "sha256=sssdlkfjdsklfjdskfljasdklfj"); + GOOD("tor 0.2.6.3-alpha " + "http://torproject.example.com/dist/tor-0.2.6.3-alpha.tar.gz " + "sha256=sssdlkfjdsklfjdskfljasdklfj blake2b=fred"); + BAD("tor 0.2.6.3-alpha " + "http://torproject.example.com/dist/tor-0.2.6.3-alpha.tar.gz " + "sha256=sssdlkfjdsklfjdskfljasdklfj="); + BAD("tor 0.2.6.3-alpha " + "http://torproject.example.com/dist/tor-0.2.6.3-alpha.tar.gz " + "sha256=sssdlkfjdsklfjdskfljasdklfj blake2b"); + BAD("tor 0.2.6.3-alpha " + "http://torproject.example.com/dist/tor-0.2.6.3-alpha.tar.gz "); + BAD("tor 0.2.6.3-alpha " + "http://torproject.example.com/dist/tor-0.2.6.3-alpha.tar.gz"); + BAD("tor 0.2.6.3-alpha "); + BAD("tor 0.2.6.3-alpha"); + BAD("tor "); + BAD("tor"); + BAD(""); + BAD("=foobar sha256=" + "3c179f46ca77069a6a0bac70212a9b3b838b2f66129cb52d568837fc79d8fcc7"); + BAD("= = sha256=" + "3c179f46ca77069a6a0bac70212a9b3b838b2f66129cb52d568837fc79d8fcc7"); + + BAD("sha512= sha256=" + "3c179f46ca77069a6a0bac70212a9b3b838b2f66129cb52d568837fc79d8fcc7"); + + votes = smartlist_new(); + smartlist_add(votes, tor_malloc_zero(sizeof(networkstatus_t))); + smartlist_add(votes, tor_malloc_zero(sizeof(networkstatus_t))); + smartlist_add(votes, tor_malloc_zero(sizeof(networkstatus_t))); + smartlist_add(votes, tor_malloc_zero(sizeof(networkstatus_t))); + smartlist_add(votes, tor_malloc_zero(sizeof(networkstatus_t))); + smartlist_add(votes, tor_malloc_zero(sizeof(networkstatus_t))); + SMARTLIST_FOREACH(votes, networkstatus_t *, ns, + ns->package_lines = smartlist_new()); + +#define ADD(i, s) \ + smartlist_add(((networkstatus_t*)smartlist_get(votes, (i)))->package_lines, \ + (void*)(s)); + + /* Only one vote for this one. */ + ADD(4, "cisco 99z http://foobar.example.com/ sha256=blahblah"); + + /* Only two matching entries for this one, but 3 voters */ + ADD(1, "mystic 99y http://barfoo.example.com/ sha256=blahblah"); + ADD(3, "mystic 99y http://foobar.example.com/ sha256=blahblah"); + ADD(4, "mystic 99y http://foobar.example.com/ sha256=blahblah"); + + /* Only two matching entries for this one, but at least 4 voters */ + ADD(1, "mystic 99p http://barfoo.example.com/ sha256=ggggggg"); + ADD(3, "mystic 99p http://foobar.example.com/ sha256=blahblah"); + ADD(4, "mystic 99p http://foobar.example.com/ sha256=blahblah"); + ADD(5, "mystic 99p http://foobar.example.com/ sha256=ggggggg"); + + /* This one has only invalid votes. */ + ADD(0, "haffenreffer 1.2 http://foobar.example.com/ sha256"); + ADD(1, "haffenreffer 1.2 http://foobar.example.com/ "); + ADD(2, "haffenreffer 1.2 "); + ADD(3, "haffenreffer "); + ADD(4, "haffenreffer"); + + /* Three matching votes for this; it should actually go in! */ + ADD(2, "element 0.66.1 http://quux.example.com/ sha256=abcdef"); + ADD(3, "element 0.66.1 http://quux.example.com/ sha256=abcdef"); + ADD(4, "element 0.66.1 http://quux.example.com/ sha256=abcdef"); + ADD(1, "element 0.66.1 http://quum.example.com/ sha256=abcdef"); + ADD(0, "element 0.66.1 http://quux.example.com/ sha256=abcde"); + + /* Three votes for A, three votes for B */ + ADD(0, "clownshoes 22alpha1 http://quumble.example.com/ blake2=foob"); + ADD(1, "clownshoes 22alpha1 http://quumble.example.com/ blake2=foob"); + ADD(2, "clownshoes 22alpha1 http://quumble.example.com/ blake2=foob"); + ADD(3, "clownshoes 22alpha1 http://quumble.example.com/ blake2=fooz"); + ADD(4, "clownshoes 22alpha1 http://quumble.example.com/ blake2=fooz"); + ADD(5, "clownshoes 22alpha1 http://quumble.example.com/ blake2=fooz"); + + /* Three votes for A, two votes for B */ + ADD(1, "clownshoes 22alpha3 http://quumble.example.com/ blake2=foob"); + ADD(2, "clownshoes 22alpha3 http://quumble.example.com/ blake2=foob"); + ADD(3, "clownshoes 22alpha3 http://quumble.example.com/ blake2=fooz"); + ADD(4, "clownshoes 22alpha3 http://quumble.example.com/ blake2=fooz"); + ADD(5, "clownshoes 22alpha3 http://quumble.example.com/ blake2=fooz"); + + /* Four votes for A, two for B. */ + ADD(0, "clownshoes 22alpha4 http://quumble.example.com/ blake2=foob"); + ADD(1, "clownshoes 22alpha4 http://quumble.example.com/ blake2=foob"); + ADD(2, "clownshoes 22alpha4 http://quumble.example.cam/ blake2=fooa"); + ADD(3, "clownshoes 22alpha4 http://quumble.example.cam/ blake2=fooa"); + ADD(4, "clownshoes 22alpha4 http://quumble.example.cam/ blake2=fooa"); + ADD(5, "clownshoes 22alpha4 http://quumble.example.cam/ blake2=fooa"); + + /* Five votes for A ... all from the same guy. Three for B. */ + ADD(0, "cbc 99.1.11.1.1 http://example.com/cbc/ cubehash=ahooy sha512=m"); + ADD(1, "cbc 99.1.11.1.1 http://example.com/cbc/ cubehash=ahooy sha512=m"); + ADD(3, "cbc 99.1.11.1.1 http://example.com/cbc/ cubehash=ahooy sha512=m"); + ADD(2, "cbc 99.1.11.1.1 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.1 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.1 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.1 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.1 http://example.com/ cubehash=ahooy"); + + /* As above but new replaces old: no two match. */ + ADD(0, "cbc 99.1.11.1.2 http://example.com/cbc/ cubehash=ahooy sha512=m"); + ADD(1, "cbc 99.1.11.1.2 http://example.com/cbc/ cubehash=ahooy sha512=m"); + ADD(1, "cbc 99.1.11.1.2 http://example.com/cbc/x cubehash=ahooy sha512=m"); + ADD(2, "cbc 99.1.11.1.2 http://example.com/cbc/ cubehash=ahooy sha512=m"); + ADD(2, "cbc 99.1.11.1.2 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.2 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.2 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.2 http://example.com/ cubehash=ahooy"); + ADD(2, "cbc 99.1.11.1.2 http://example.com/ cubehash=ahooy"); + + + res = compute_consensus_package_lines(votes); + tt_assert(res); + tt_str_op(res, ==, + "package cbc 99.1.11.1.1 http://example.com/cbc/ cubehash=ahooy sha512=m\n" + "package clownshoes 22alpha3 http://quumble.example.com/ blake2=fooz\n" + "package clownshoes 22alpha4 http://quumble.example.cam/ blake2=fooa\n" + "package element 0.66.1 http://quux.example.com/ sha256=abcdef\n" + "package mystic 99y http://foobar.example.com/ sha256=blahblah\n" + ); + +#undef ADD +#undef BAD +#undef GOOD + done: + SMARTLIST_FOREACH(votes, networkstatus_t *, ns, + { smartlist_free(ns->package_lines); tor_free(ns); }); + tor_free(res); +} + #define DIR_LEGACY(name) \ { #name, test_dir_ ## name , TT_FORK, NULL, NULL } @@ -2983,6 +3129,7 @@ struct testcase_t dir_tests[] = { DIR(http_handling, 0), DIR(purpose_needs_anonymity, 0), DIR(fetch_type, 0), + DIR(packages, 0), END_OF_TESTCASES }; |