dufs/tests/symlink.rs

47 lines
1.7 KiB
Rust
Raw Normal View History

2022-06-12 00:43:50 +00:00
mod fixtures;
mod utils;
use assert_fs::fixture::TempDir;
use fixtures::{server, tmpdir, Error, TestServer};
use rstest::rstest;
#[cfg(unix)]
use std::os::unix::fs::symlink as symlink_dir;
#[cfg(windows)]
use std::os::windows::fs::symlink_dir;
#[rstest]
fn default_not_allow_symlink(server: TestServer, tmpdir: TempDir) -> Result<(), Error> {
// Create symlink directory "foo" to point outside the root
let dir = "foo";
symlink_dir(tmpdir.path(), server.path().join(dir)).expect("Couldn't create symlink");
let resp = reqwest::blocking::get(format!("{}{}", server.url(), dir))?;
assert_eq!(resp.status(), 404);
let resp = reqwest::blocking::get(format!("{}{}/index.html", server.url(), dir))?;
assert_eq!(resp.status(), 404);
let resp = reqwest::blocking::get(server.url())?;
2022-08-03 00:51:12 +00:00
let paths = utils::retrieve_index_paths(&resp.text()?);
2022-06-12 00:43:50 +00:00
assert!(!paths.is_empty());
assert!(!paths.contains(&format!("{dir}/")));
2022-06-12 00:43:50 +00:00
Ok(())
}
#[rstest]
fn allow_symlink(
#[with(&["--allow-symlink"])] server: TestServer,
tmpdir: TempDir,
) -> Result<(), Error> {
// Create symlink directory "foo" to point outside the root
let dir = "foo";
symlink_dir(tmpdir.path(), server.path().join(dir)).expect("Couldn't create symlink");
let resp = reqwest::blocking::get(format!("{}{}", server.url(), dir))?;
assert_eq!(resp.status(), 200);
let resp = reqwest::blocking::get(format!("{}{}/index.html", server.url(), dir))?;
assert_eq!(resp.status(), 200);
let resp = reqwest::blocking::get(server.url())?;
2022-08-03 00:51:12 +00:00
let paths = utils::retrieve_index_paths(&resp.text()?);
2022-06-12 00:43:50 +00:00
assert!(!paths.is_empty());
assert!(paths.contains(&format!("{dir}/")));
2022-06-12 00:43:50 +00:00
Ok(())
}