1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

test(test_util/lsp): add tests for invalid content-length (#12971)

This commit is contained in:
Hirotaka Tagawa / wafuwafu13 2021-12-21 23:14:49 +09:00 committed by GitHub
parent b5fdfb9d25
commit 9825c876b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -337,8 +337,20 @@ mod tests {
#[test]
fn test_read_message() {
let msg = b"content-length: 11\r\n\r\nhello world";
let mut reader = std::io::Cursor::new(msg);
assert_eq!(read_message(&mut reader).unwrap(), b"hello world");
let msg1 = b"content-length: 11\r\n\r\nhello world";
let mut reader1 = std::io::Cursor::new(msg1);
assert_eq!(read_message(&mut reader1).unwrap(), b"hello world");
let msg2 = b"content-length: 5\r\n\r\nhello world";
let mut reader2 = std::io::Cursor::new(msg2);
assert_eq!(read_message(&mut reader2).unwrap(), b"hello");
}
#[test]
#[should_panic(expected = "failed to fill whole buffer")]
fn test_invalid_read_message() {
let msg1 = b"content-length: 12\r\n\r\nhello world";
let mut reader1 = std::io::Cursor::new(msg1);
read_message(&mut reader1).unwrap();
}
}