diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-08-23 14:02:48 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-09-26 10:56:50 -0700 |
commit | a232161f7beeecebf31b2259a571e8b26cb0b541 (patch) | |
tree | 6624b80816c112523b64b2cd8a49129a4ae30dbd /src/test/test_protover.c | |
parent | 0697e413efa32b71d080353e5151beee117fca04 (diff) | |
download | tor-a232161f7beeecebf31b2259a571e8b26cb0b541.tar.gz tor-a232161f7beeecebf31b2259a571e8b26cb0b541.zip |
Cover the error cases of parsing protocol versions
Also, detect an additional failure type. Thanks, tests!
(How distinctly I recall thee)
Diffstat (limited to 'src/test/test_protover.c')
-rw-r--r-- | src/test/test_protover.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/test_protover.c b/src/test/test_protover.c index 651d2fd52d..c86c3b2f69 100644 --- a/src/test/test_protover.c +++ b/src/test/test_protover.c @@ -81,6 +81,41 @@ test_protover_parse(void *arg) } static void +test_protover_parse_fail(void *arg) +{ + (void)arg; + smartlist_t *elts; + + /* random junk */ + elts = parse_protocol_list("!!3@*"); + tt_assert(elts == NULL); + + /* Missing equals sign in an entry */ + elts = parse_protocol_list("Link=4 Haprauxymatyve Desc=9"); + tt_assert(elts == NULL); + + /* Missing word. */ + elts = parse_protocol_list("Link=4 =3 Desc=9"); + tt_assert(elts == NULL); + + /* Broken numbers */ + elts = parse_protocol_list("Link=fred"); + tt_assert(elts == NULL); + elts = parse_protocol_list("Link=1,fred"); + tt_assert(elts == NULL); + elts = parse_protocol_list("Link=1,fred,3"); + tt_assert(elts == NULL); + + /* Broken range */ + elts = parse_protocol_list("Link=1,9-8,3"); + tt_assert(elts == NULL); + + done: + ; +} + + +static void test_protover_vote(void *arg) { (void) arg; @@ -154,6 +189,7 @@ test_protover_all_supported(void *arg) struct testcase_t protover_tests[] = { PV_TEST(parse, 0), + PV_TEST(parse_fail, 0), PV_TEST(vote, 0), PV_TEST(all_supported, 0), END_OF_TESTCASES |