summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-25 19:00:31 -0400
committerNick Mathewson <nickm@torproject.org>2017-04-25 19:01:05 -0400
commitfec3050ea968ae913b108a4c48bce2293b92072c (patch)
tree224bbcd5c61ba75d638c2609f156532af44afc66 /src
parentfd48b757d3a85099057d27a74555d87fcd33936e (diff)
downloadtor-fec3050ea968ae913b108a4c48bce2293b92072c.tar.gz
tor-fec3050ea968ae913b108a4c48bce2293b92072c.zip
Tests for parse_accept_encoding
Diffstat (limited to 'src')
-rw-r--r--src/or/directory.c2
-rw-r--r--src/or/directory.h1
-rw-r--r--src/test/test_dir_handle_get.c47
3 files changed, 49 insertions, 1 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 8229279a47..95c3c8481e 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 &lt;&lt; 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 4c52c24049..dc02027e99 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 392fa4dde0..7794bd7d65 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
};