commit fec3050ea968ae913b108a4c48bce2293b92072c Author: Nick Mathewson nickm@torproject.org Date: Tue Apr 25 19:00:31 2017 -0400
Tests for parse_accept_encoding --- src/or/directory.c | 2 +- src/or/directory.h | 1 + src/test/test_dir_handle_get.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/src/or/directory.c b/src/or/directory.c index 8229279..95c3c84 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -2792,7 +2792,7 @@ write_http_response_header(dir_connection_t *conn, ssize_t length, /** Parse the compression methods listed in an Accept-Encoding header <b>h</b>, * and convert them to a bitfield where compression method x is supported if * and only if 1 << x is set in the bitfield. */ -static unsigned +STATIC unsigned parse_accept_encoding_header(const char *h) { unsigned result = (1u << NO_METHOD); diff --git a/src/or/directory.h b/src/or/directory.h index 4c52c24..dc02027 100644 --- a/src/or/directory.h +++ b/src/or/directory.h @@ -192,6 +192,7 @@ STATIC int next_random_exponential_delay(int delay, int max_delay); STATIC int parse_hs_version_from_post(const char *url, const char *prefix, const char **end_pos);
+STATIC unsigned parse_accept_encoding_header(const char *h); #endif
#endif diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c index 392fa4d..7794bd7 100644 --- a/src/test/test_dir_handle_get.c +++ b/src/test/test_dir_handle_get.c @@ -2497,6 +2497,52 @@ test_dir_handle_get_status_vote_current_authority(void* data) dirvote_free_all(); }
+static void +test_dir_handle_get_parse_accept_encoding(void *arg) +{ + (void)arg; + const unsigned B_NONE = 1u << NO_METHOD; + const unsigned B_ZLIB = 1u << ZLIB_METHOD; + const unsigned B_GZIP = 1u << GZIP_METHOD; + const unsigned B_LZMA = 1u << LZMA_METHOD; + const unsigned B_ZSTD = 1u << ZSTD_METHOD; + + unsigned encodings; + + encodings = parse_accept_encoding_header(""); + tt_uint_op(B_NONE, OP_EQ, encodings); + + encodings = parse_accept_encoding_header(" "); + tt_uint_op(B_NONE, OP_EQ, encodings); + + encodings = parse_accept_encoding_header("dewey, cheatham, and howe "); + tt_uint_op(B_NONE, OP_EQ, encodings); + + encodings = parse_accept_encoding_header("dewey, cheatham, and gzip"); + tt_uint_op(B_NONE, OP_EQ, encodings); + + encodings = parse_accept_encoding_header("dewey, cheatham, and, gzip"); + tt_uint_op(B_NONE|B_GZIP, OP_EQ, encodings); + + encodings = parse_accept_encoding_header(" gzip"); + tt_uint_op(B_NONE|B_GZIP, OP_EQ, encodings); + + encodings = parse_accept_encoding_header("gzip"); + tt_uint_op(B_NONE|B_GZIP, OP_EQ, encodings); + + encodings = parse_accept_encoding_header("x-zstd, deflate, x-lzma"); + tt_uint_op(B_NONE|B_ZLIB|B_ZSTD|B_LZMA, OP_EQ, encodings); + + encodings = parse_accept_encoding_header("x-zstd, deflate, x-lzma, gzip"); + tt_uint_op(B_NONE|B_ZLIB|B_ZSTD|B_LZMA|B_GZIP, OP_EQ, encodings); + + encodings = parse_accept_encoding_header("x-zstd,deflate,x-lzma,gzip"); + tt_uint_op(B_NONE|B_ZLIB|B_ZSTD|B_LZMA|B_GZIP, OP_EQ, encodings); + + done: + ; +} + #define DIR_HANDLE_CMD(name,flags) \ { #name, test_dir_handle_get_##name, (flags), NULL, NULL }
@@ -2555,6 +2601,7 @@ struct testcase_t dir_handle_get_tests[] = { DIR_HANDLE_CMD(status_vote_next_consensus_signatures_not_found, 0), DIR_HANDLE_CMD(status_vote_next_consensus_signatures_busy, 0), DIR_HANDLE_CMD(status_vote_next_consensus_signatures, 0), + DIR_HANDLE_CMD(parse_accept_encoding, 0), END_OF_TESTCASES };
tor-commits@lists.torproject.org