From c1be8f9d574dace9941c532ce5d612c315bc74c7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 19 Aug 2016 18:04:02 -0400 Subject: Basic backend for the protocol-versions voting algorithm. [This is a brute-force method that potentially uses way too much RAM. Need to rethink this a little. Right now you can DOS an authority by saying "Foo=1-4294967295".] --- src/test/test_protover.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/test') diff --git a/src/test/test_protover.c b/src/test/test_protover.c index 606ca57b1b..2c72282a5c 100644 --- a/src/test/test_protover.c +++ b/src/test/test_protover.c @@ -80,12 +80,43 @@ test_protover_parse(void *arg) tor_free(re_encoded); } +static void +test_protover_vote(void *arg) +{ + (void) arg; + + smartlist_t *lst = smartlist_new(); + char *result = compute_protover_vote(lst, 1); + + tt_str_op(result, OP_EQ, ""); + tor_free(result); + + smartlist_add(lst, (void*) "Foo=1-10,500 Bar=1,3-7,8"); + result = compute_protover_vote(lst, 1); + tt_str_op(result, OP_EQ, "Bar=1,3-8 Foo=1-10,500"); + tor_free(result); + + smartlist_add(lst, (void*) "Quux=123-456,78 Bar=2-6,8 Foo=9"); + result = compute_protover_vote(lst, 1); + tt_str_op(result, OP_EQ, "Bar=1-8 Foo=1-10,500 Quux=78,123-456"); + tor_free(result); + + result = compute_protover_vote(lst, 2); + tt_str_op(result, OP_EQ, "Bar=3-6,8 Foo=9"); + tor_free(result); + + done: + tor_free(result); + smartlist_free(lst); +} + #define PV_TEST(name, flags) \ { #name, test_protover_ ##name, (flags), NULL, NULL } struct testcase_t protover_tests[] = { PV_TEST(parse, 0), + PV_TEST(vote, 0), END_OF_TESTCASES }; -- cgit v1.2.3-54-g00ecf