mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-19 02:12:10 +08:00
test: trim redundant test coverage
This commit is contained in:
@@ -173,103 +173,3 @@ pub async fn copy_icon_file(path: String, icon_info: IconInfo) -> CmdResult<Stri
|
||||
Err("file not found".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn normalize_icon_segment_accepts_single_name() {
|
||||
assert!(normalize_icon_segment("group-icon.png").is_ok());
|
||||
assert!(normalize_icon_segment("alpha_1.webp").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_icon_segment_rejects_traversal_and_separators() {
|
||||
for name in ["../x", "..\\x", "a/b", "a\\b", "..", "a..b"] {
|
||||
assert!(normalize_icon_segment(name).is_err(), "name should be rejected: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normalize_icon_segment_rejects_empty() {
|
||||
assert!(normalize_icon_segment("").is_err());
|
||||
assert!(normalize_icon_segment(" ").is_err());
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn normalize_icon_segment_rejects_windows_absolute_names() {
|
||||
for name in [r"C:\temp\icon.png", r"\\server\share\icon.png"] {
|
||||
assert!(normalize_icon_segment(name).is_err(), "name should be rejected: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[test]
|
||||
fn normalize_icon_segment_rejects_unix_absolute_names() {
|
||||
assert!(normalize_icon_segment("/tmp/icon.png").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ensure_icon_cache_target_accepts_direct_child_only() {
|
||||
let base = PathBuf::from("icons").join("cache");
|
||||
let valid = ensure_icon_cache_target(&base, "ok.png");
|
||||
assert_eq!(valid.unwrap(), base.join("ok.png"));
|
||||
|
||||
let nested = base.join("nested").join("ok.png");
|
||||
assert!(ensure_icon_cache_target(&base, nested.to_string_lossy().as_ref()).is_err());
|
||||
assert!(ensure_icon_cache_target(&base, "../ok.png").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn looks_like_svg_accepts_plain_svg() {
|
||||
assert!(looks_like_svg(br#"<svg xmlns="http://www.w3.org/2000/svg"></svg>"#));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn looks_like_svg_accepts_xml_prefixed_svg() {
|
||||
assert!(looks_like_svg(
|
||||
br#"<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg"></svg>"#
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn looks_like_svg_accepts_doctype_svg() {
|
||||
assert!(looks_like_svg(
|
||||
br#"<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"><svg xmlns="http://www.w3.org/2000/svg"></svg>"#
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn looks_like_svg_accepts_bom_and_leading_whitespace() {
|
||||
assert!(looks_like_svg(
|
||||
b"\xEF\xBB\xBF \n\t<svg xmlns=\"http://www.w3.org/2000/svg\"></svg>"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn looks_like_svg_rejects_non_svg_payloads() {
|
||||
assert!(!looks_like_svg(br#"{"status":"ok"}"#));
|
||||
assert!(!looks_like_svg(br"text/plain"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn looks_like_html_detects_common_html_prefixes() {
|
||||
assert!(looks_like_html(br"<!DOCTYPE html><html></html>"));
|
||||
assert!(looks_like_html(br"<html><body>oops</body></html>"));
|
||||
assert!(looks_like_html(br"<head><title>oops</title></head>"));
|
||||
assert!(looks_like_html(
|
||||
b"\xEF\xBB\xBF \n\t<!DOCTYPE HTML><html><body>oops</body></html>"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_supported_icon_content_rejects_html_and_accepts_svg() {
|
||||
assert!(!is_supported_icon_content(br"<!DOCTYPE html><html></html>"));
|
||||
assert!(is_supported_icon_content(
|
||||
br#"<svg xmlns="http://www.w3.org/2000/svg"></svg>"#
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,15 +137,3 @@ pub async fn copy_clash_env() {
|
||||
logging!(error, Type::ProxyMode, "Failed to write to clipboard");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::toggle_operation;
|
||||
use crate::core::notification::FailedOperation;
|
||||
|
||||
#[test]
|
||||
fn a_failed_toggle_records_which_way_the_user_was_asking() {
|
||||
assert_eq!(toggle_operation(true), FailedOperation::SystemProxyEnable);
|
||||
assert_eq!(toggle_operation(false), FailedOperation::SystemProxyDisable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user