diff options
author | William Wennerström <william@wstrm.dev> | 2020-07-05 18:28:23 +0200 |
---|---|---|
committer | William Wennerström <william@wstrm.dev> | 2020-11-16 21:58:09 +0100 |
commit | a0cf0844abeeffe83a13e438eff3c309bc9887e9 (patch) | |
tree | 7b43f43cc16ad94a8b8319f51910514f5067481d /tests/unittests | |
parent | eebf54c8596abd5c28b405d8860c173207bbec64 (diff) | |
download | profani-tty-a0cf0844abeeffe83a13e438eff3c309bc9887e9.tar.gz |
Remove unsafe Conent-Disposition inferring
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_http_download.c | 113 | ||||
-rw-r--r-- | tests/unittests/test_http_download.h | 3 | ||||
-rw-r--r-- | tests/unittests/unittests.c | 3 |
3 files changed, 35 insertions, 84 deletions
diff --git a/tests/unittests/test_http_download.c b/tests/unittests/test_http_download.c index 181fc78d..c0516a66 100644 --- a/tests/unittests/test_http_download.c +++ b/tests/unittests/test_http_download.c @@ -12,108 +12,61 @@ typedef struct { char *url; - char *filename; + char *basename; } url_test_t; -typedef struct { - char *header; - char *filename; -} header_test_t; - -void http_filename_from_url_td(void **state) { - int num_tests = 5; +void http_basename_from_url_td(void **state) { + int num_tests = 11; url_test_t tests[] = { (url_test_t){ .url = "https://host.test/image.jpeg", - .filename = "image.jpeg", + .basename = "image.jpeg", }, (url_test_t){ - .url = "https://host.test/images/", - .filename = "images", + .url = "https://host.test/image.jpeg#somefragment", + .basename = "image.jpeg", }, (url_test_t){ - .url = "https://host.test/", - .filename = "index.html", + .url = "https://host.test/image.jpeg?query=param", + .basename = "image.jpeg", }, (url_test_t){ - .url = "https://host.test", - .filename = "index.html", + .url = "https://host.test/image.jpeg?query=param&another=one", + .basename = "image.jpeg", }, (url_test_t){ - .url = "aesgcm://host.test", - .filename = "index.html", - }, - }; - - char *filename; - for(int i = 0; i < num_tests; i++) { - filename = http_filename_from_url(tests[i].url); - assert_string_equal(filename, tests[i].filename); - } -} - -void http_filename_from_header_td(void **state) { - int num_tests = 11; - header_test_t tests[] = { - (header_test_t){ - .header = "Content-Disposition: filename=image.jpeg", - .filename = "image.jpeg", - }, - (header_test_t){ - .header = "Content-Disposition:filename=image.jpeg", - .filename = "image.jpeg", - }, - (header_test_t){ - .header = "CoNteNt-DiSpoSItioN: filename=image.jpeg", - .filename = "image.jpeg", - }, - (header_test_t){ - .header = "Content-Disposition: attachment; filename=image.jpeg", - .filename = "image.jpeg", - }, - (header_test_t){ - .header = "Content-Disposition: filename=", - .filename = NULL, + .url = "https://host.test/images/", + .basename = "images", }, - (header_test_t){ - .header = "Content-Disposition: filename=;", - .filename = NULL, + (url_test_t){ + .url = "https://host.test/images/../../file", + .basename = "file", }, - (header_test_t){ - .header = "Content-Disposition: inline", - .filename = NULL, + (url_test_t){ + .url = "https://host.test/images/../../file/..", + .basename = "index.html", }, - (header_test_t){ - .header = "Content-Disposition:", - .filename = NULL, + (url_test_t){ + .url = "https://host.test/images/..//", + .basename = "index.html", }, - (header_test_t){ - .header = "Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT ", - .filename = NULL, + (url_test_t){ + .url = "https://host.test/", + .basename = "index.html", }, - (header_test_t){ - .header = "", - .filename = NULL, + (url_test_t){ + .url = "https://host.test", + .basename = "index.html", }, - (header_test_t){ - .header = NULL, - .filename = NULL, + (url_test_t){ + .url = "aesgcm://host.test", + .basename = "index.html", }, }; - char *got_filename; - char *exp_filename; - char *header; + char *basename; for(int i = 0; i < num_tests; i++) { - header = tests[i].header; - exp_filename = tests[i].filename; - - got_filename = http_filename_from_header(header); - - if (exp_filename == NULL) { - assert_null(got_filename); - } else { - assert_string_equal(got_filename, exp_filename); - } + basename = http_basename_from_url(tests[i].url); + assert_string_equal(basename, tests[i].basename); } } diff --git a/tests/unittests/test_http_download.h b/tests/unittests/test_http_download.h index c8c333ee..ce8913eb 100644 --- a/tests/unittests/test_http_download.h +++ b/tests/unittests/test_http_download.h @@ -1,2 +1 @@ -void http_filename_from_url_td(void **state); -void http_filename_from_header_td(void **state); +void http_basename_from_url_td(void **state); diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index 9e9833bc..06c1b307 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -628,8 +628,7 @@ main(int argc, char* argv[]) unit_test(removes_plugin_features), unit_test(does_not_remove_feature_when_more_than_one_reference), - unit_test(http_filename_from_url_td), - unit_test(http_filename_from_header_td), + unit_test(http_basename_from_url_td), }; return run_tests(all_tests); |