81 lines
2.5 KiB
Rust
81 lines
2.5 KiB
Rust
/*
|
|
* Copyright (C) 2026 Mateusz Gruszczyński @linuxiarz.pl
|
|
* Source-Available Code / Dual-Licensed.
|
|
*
|
|
* Free for non-commercial and evaluation use under terms of BSL/GPLv3.
|
|
* Commercial or production use requires a valid paid license.
|
|
* See LICENSE file in repository root for details.
|
|
*/
|
|
|
|
use super::{
|
|
content_references_file, content_references_stored_file, is_safe_inline_image_mime,
|
|
is_safe_inline_video_mime, parse_byte_range,
|
|
};
|
|
|
|
#[test]
|
|
fn only_raster_images_are_inline() {
|
|
assert!(is_safe_inline_image_mime("image/png"));
|
|
assert!(is_safe_inline_image_mime("image/jpeg"));
|
|
assert!(!is_safe_inline_image_mime("image/svg+xml"));
|
|
assert!(!is_safe_inline_image_mime("text/html"));
|
|
assert!(!is_safe_inline_image_mime("application/xml"));
|
|
}
|
|
|
|
#[test]
|
|
fn extended_image_alias_is_still_attached() {
|
|
assert!(content_references_file(
|
|
"[image=photo.jpg,Photo,a=left,size=640x400]",
|
|
"photo.jpg",
|
|
"/f/token/photo.jpg",
|
|
));
|
|
assert!(content_references_file(
|
|
"[file=report.pdf,Quarterly report]",
|
|
"report.pdf",
|
|
"/f/token/report.pdf",
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn attachment_references_survive_origin_changes() {
|
|
let stored = "/f/token/image.png";
|
|
assert!(content_references_stored_file(
|
|
"",
|
|
"image.png",
|
|
stored,
|
|
None,
|
|
));
|
|
assert!(content_references_stored_file(
|
|
"",
|
|
"image.png",
|
|
"https://old-files.example.com/f/token/image.png",
|
|
Some("https://new-files.example.com"),
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn common_video_formats_are_inline() {
|
|
assert!(is_safe_inline_video_mime("video/mp4"));
|
|
assert!(is_safe_inline_video_mime("video/webm"));
|
|
assert!(!is_safe_inline_video_mime("text/html"));
|
|
assert!(!is_safe_inline_video_mime("application/javascript"));
|
|
}
|
|
|
|
#[test]
|
|
fn video_alias_is_still_attached() {
|
|
assert!(content_references_file(
|
|
"[video=clip.mp4,Product demo]",
|
|
"clip.mp4",
|
|
"/f/token/clip.mp4",
|
|
));
|
|
}
|
|
|
|
#[test]
|
|
fn byte_ranges_support_video_seeking() {
|
|
assert_eq!(parse_byte_range("bytes=0-99", 1_000), Ok(Some((0, 100))));
|
|
assert_eq!(parse_byte_range("bytes=500-", 1_000), Ok(Some((500, 1_000))));
|
|
assert_eq!(parse_byte_range("bytes=-100", 1_000), Ok(Some((900, 1_000))));
|
|
assert_eq!(parse_byte_range("bytes=900-2000", 1_000), Ok(Some((900, 1_000))));
|
|
assert_eq!(parse_byte_range("bytes=1000-", 1_000), Err(()));
|
|
assert_eq!(parse_byte_range("bytes=0-1,4-5", 1_000), Err(()));
|
|
}
|