summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-03-20 23:21:04 +0000
committerVincent Sanders <vince@kyllikki.org>2017-03-20 23:21:26 +0000
commit399d19ce25fde72be62b843744cdc6ad2f70821c (patch)
tree9445f73fef8f1fc6f8f44d5cc85f76e317659393
parentcd39367ef41bed86c07b4e57f327baa3f5720fb6 (diff)
downloadnetsurf-399d19ce25fde72be62b843744cdc6ad2f70821c.tar.gz
netsurf-399d19ce25fde72be62b843744cdc6ad2f70821c.tar.bz2
extend mime sniff coverage with bad mp4 tests
-rw-r--r--test/mimesniff.c62
1 files changed, 51 insertions, 11 deletions
diff --git a/test/mimesniff.c b/test/mimesniff.c
index 20e6860ef..6a95823e3 100644
--- a/test/mimesniff.c
+++ b/test/mimesniff.c
@@ -192,8 +192,20 @@ static struct test_mimetype match_unknown_mp4_tests[] = {
SIG("\x00\x00\x00\040ftypmp41\x00\x00\x02\x00isomiso2avc1mp41", video_mp4, true),
};
+static struct test_mimetype match_unknown_bad_mp4_tests[] = {
+ SIG("\x00\x00\x00\044ftypisom\x00\x00\x02\x00isomiso2avc1mp41", application_octet_stream, true),
+ SIG("\x00\x00\x00\037ftypmp41\x00\x00\x02\x00isomiso2avc1mp41", application_octet_stream, true),
+ SIG("\x00\x00\x00\040atypmp41\x00\x00\x02\x00isomiso2avc1mp41", application_octet_stream, true),
+ SIG("\x00\x00\x00\040faypmp41\x00\x00\x02\x00isomiso2avc1mp41", application_octet_stream, true),
+ SIG("\x00\x00\x00\040ftapmp41\x00\x00\x02\x00isomiso2avc1mp41", application_octet_stream, true),
+ SIG("\x00\x00\x00\040ftyamp41\x00\x00\x02\x00isomiso2avc1mp41", application_octet_stream, true),
+ SIG("\x00\x00\x00\040ftypmp31\x00\x00\x02\x00isomiso2avc1mp31", application_octet_stream, true),
+ SIG("\x00\x00\x00\040ftypma41\x00\x00\x02\x00isomiso2avc1ma41", application_octet_stream, true),
+};
+
static struct test_mimetype match_unknown_txtbin_tests[] = {
SIG("a\nb\tc ", text_plain, true),
+ SIG("\x1b\r\f ", text_plain, true),
SIG("a\nb\tc \x01", application_octet_stream, true),
};
@@ -302,7 +314,7 @@ START_TEST(mimesniff_match_unknown_ws_test)
END_TEST
/**
- * ws test
+ * mp4 test
*/
START_TEST(mimesniff_match_unknown_mp4_test)
{
@@ -327,6 +339,31 @@ START_TEST(mimesniff_match_unknown_mp4_test)
END_TEST
/**
+ * mp4 test
+ */
+START_TEST(mimesniff_match_unknown_bad_mp4_test)
+{
+ nserror err;
+ const struct test_mimetype *tst = &match_unknown_bad_mp4_tests[_i];
+ lwc_string *effective_type;
+ bool match;
+
+ err = mimesniff_compute_effective_type(NULL,
+ tst->data,
+ tst->len,
+ true,
+ false,
+ &effective_type);
+ ck_assert(err == NSERROR_OK);
+
+ ck_assert(lwc_string_caseless_isequal(effective_type,
+ *(tst->mime_type),
+ &match) == lwc_error_ok && match);
+ lwc_string_unref(effective_type);
+}
+END_TEST
+
+/**
* unknown header text/binary test
*/
START_TEST(mimesniff_match_unknown_txtbin_test)
@@ -382,6 +419,10 @@ static TCase *mimesniff_match_unknown_case_create(void)
0, NELEMS(match_unknown_mp4_tests));
tcase_add_loop_test(tc,
+ mimesniff_match_unknown_bad_mp4_test,
+ 0, NELEMS(match_unknown_bad_mp4_tests));
+
+ tcase_add_loop_test(tc,
mimesniff_match_unknown_txtbin_test,
0, NELEMS(match_unknown_txtbin_tests));
@@ -477,11 +518,11 @@ START_TEST(mimesniff_image_header_sniff_imageonly_test)
/* svg header type, unsniffable data and sniffing allowed images only */
err = mimesniff_compute_effective_type("image/jpeg",
- "notsniffablejpeg",
- 12,
- true,
- true,
- &effective_type);
+ (const uint8_t*)"notsniffablejpeg",
+ 12,
+ true,
+ true,
+ &effective_type);
ck_assert_int_eq(err, NSERROR_OK);
ck_assert(lwc_string_caseless_isequal(effective_type,
@@ -491,7 +532,7 @@ START_TEST(mimesniff_image_header_sniff_imageonly_test)
/* svg header type, gif data and sniffing allowed images only */
err = mimesniff_compute_effective_type("image/jpeg",
- "GIF87a",
+ (const uint8_t*)"GIF87a",
6,
true,
true,
@@ -524,7 +565,7 @@ START_TEST(mimesniff_text_header_nodata_sniff_test)
/* svg header type, unsniffable data and sniffing allowed images only */
err = mimesniff_compute_effective_type("text/plain",
- "a\nb\tc \x01",
+ (const uint8_t*)"a\nb\tc \x01",
7,
true,
false,
@@ -556,8 +597,8 @@ START_TEST(mimesniff_text_header_sniff_test)
bool match;
- err = mimesniff_compute_effective_type(tst->data,
- "text",
+ err = mimesniff_compute_effective_type((const char*)tst->data,
+ (const uint8_t*)"text",
4,
true,
false,
@@ -716,7 +757,6 @@ START_TEST(mimesniff_html_header_sniff_test)
{
nserror err;
lwc_string *effective_type;
- bool match;
err = mimesniff_compute_effective_type("text/html",
NULL,