dufs/tests/args.rs
sigoden fd73f144aa
fix: require path separator boundary when stripping --path-prefix (#725)
The resolve_path function used str::strip_prefix which accepted
same-component prefix matches (e.g. prefix "pfx" matched both
"/pfx/file" and "/pfxfile"). Now requires the prefix to be
followed by "/" or be an exact match to serve the root.
2026-06-29 19:55:36 +08:00

51 lines
1.5 KiB
Rust

//! Run file server with different args
mod fixtures;
mod utils;
use fixtures::{server, Error, TestServer};
use rstest::rstest;
#[rstest]
fn path_prefix_index(#[with(&["--path-prefix", "xyz"])] server: TestServer) -> Result<(), Error> {
let resp = reqwest::blocking::get(format!("{}{}", server.url(), "xyz"))?;
assert_resp_paths!(resp);
Ok(())
}
#[rstest]
fn path_prefix_file(#[with(&["--path-prefix", "xyz"])] server: TestServer) -> Result<(), Error> {
let resp = reqwest::blocking::get(format!("{}{}/index.html", server.url(), "xyz"))?;
assert_eq!(resp.status(), 200);
assert_eq!(resp.text()?, "This is index.html");
Ok(())
}
#[rstest]
fn path_prefix_reject_same_component(
#[with(&["--path-prefix", "xyz"])] server: TestServer,
) -> Result<(), Error> {
let resp = reqwest::blocking::get(format!("{}xyzpublic.txt", server.url()))?;
assert_eq!(resp.status(), 400);
Ok(())
}
#[rstest]
fn path_prefix_reject_extra_component_text(
#[with(&["--path-prefix", "xyz"])] server: TestServer,
) -> Result<(), Error> {
let resp = reqwest::blocking::get(format!("{}xyzevil/public.txt", server.url()))?;
assert_eq!(resp.status(), 400);
Ok(())
}
#[rstest]
fn path_prefix_propfind(
#[with(&["--path-prefix", "xyz"])] server: TestServer,
) -> Result<(), Error> {
let resp = fetch!(b"PROPFIND", format!("{}{}", server.url(), "xyz")).send()?;
let text = resp.text()?;
assert!(text.contains("<D:href>/xyz/</D:href>"));
Ok(())
}