From 92862de071a229f957c644489d5d7187220b30fb Mon Sep 17 00:00:00 2001 From: Colton Allen Date: Wed, 7 Dec 2022 11:50:17 -0600 Subject: [PATCH] Add more coverage --- relay-replays/src/recording.rs | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/relay-replays/src/recording.rs b/relay-replays/src/recording.rs index efe8a799f1..1a92a08ac1 100644 --- a/relay-replays/src/recording.rs +++ b/relay-replays/src/recording.rs @@ -596,6 +596,63 @@ mod tests { } } + #[test] + fn test_process_recording_no_body_data() { + // Empty bodies can not be decompressed and fail. + let payload: [u8; 17] = [ + 123, 34, 115, 101, 103, 109, 101, 110, 116, 95, 105, 100, 34, 58, 51, 125, 10, + ]; + + let result = recording::process_recording(&payload); + match result { + Ok(_) => unreachable!(), + Err(e) => match e { + recording::RecordingParseError::IoError(er) => { + assert_eq!(er.to_string(), "corrupt deflate stream".to_string()) + } + _ => unreachable!(), + }, + } + } + + #[test] + fn test_process_recording_bad_body_data() { + // Invalid gzip body contents. Can not deflate. + let payload: [u8; 18] = [ + 123, 34, 115, 101, 103, 109, 101, 110, 116, 95, 105, 100, 34, 58, 51, 125, 10, 22, + ]; + + let result = recording::process_recording(&payload); + match result { + Ok(_) => unreachable!(), + Err(e) => match e { + recording::RecordingParseError::IoError(er) => { + assert_eq!(er.to_string(), "corrupt deflate stream".to_string()) + } + _ => unreachable!(), + }, + } + } + + #[test] + fn test_process_recording_no_headers() { + // No header delimiter. Entire payload is consumed as headers. The empty body fails. + let payload: [u8; 16] = [ + 123, 34, 115, 101, 103, 109, 101, 110, 116, 95, 105, 100, 34, 58, 51, 125, + ]; + + let result = recording::process_recording(&payload); + match result { + Ok(_) => unreachable!(), + Err(e) => match e { + recording::RecordingParseError::IoError(er) => { + assert_eq!(er.to_string(), "corrupt deflate stream".to_string()) + } + _ => unreachable!(), + }, + } + } + // RRWeb Payload Coverage #[test]