From 4e6ac58d0cbd35b9dd2c36bea30198d6a5048d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 17 Nov 2021 19:22:28 +0200 Subject: [PATCH] Add tests for parsing non-playlist text and binary data These should fail to parse (and not panic), but previously the non-playlist text succeeded. --- tests/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/lib.rs b/tests/lib.rs index 02982bd..c67b062 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -501,3 +501,29 @@ fn parsing_write_to_should_produce_the_same_structure() { ); } } + +// Failure on arbitrary text files that don't start with #EXTM3U8 + +#[test] +fn parsing_text_file_should_fail() { + let s = " +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in +reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia +deserunt mollit anim id est laborum. + "; + let res = parse_master_playlist_res(s.as_bytes()); + + assert!(res.is_err()); +} + +#[test] +fn parsing_binary_data_should_fail_cleanly() { + let data = (0..1024).map(|i| (i % 255) as u8).collect::>(); + let res = parse_master_playlist_res(&data); + + assert!(res.is_err()); +}