Tests for parse_accept_encoding

This commit is contained in:
Nick Mathewson 2017-04-25 19:00:31 -04:00
parent fd48b757d3
commit fec3050ea9
3 changed files with 49 additions and 1 deletions

View File

@ -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 &lt;&lt; x is set in the bitfield. */
static unsigned
STATIC unsigned
parse_accept_encoding_header(const char *h)
{
unsigned result = (1u << NO_METHOD);

View File

@ -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

View File

@ -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
};