dufs/tests/symlink.rs
sigoden 7d6d7d49ca
feat: API to search and list directories (#177)
use `?simple` to output path name only.
use `?json` to output paths in json format.
By default, output html page.

close #166
2023-02-20 11:05:53 +08:00

47 lines
1.7 KiB
Rust

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())?;
let paths = utils::retrieve_index_paths(&resp.text()?);
assert!(!paths.is_empty());
assert!(!paths.contains(&format!("{dir}/")));
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())?;
let paths = utils::retrieve_index_paths(&resp.text()?);
assert!(!paths.is_empty());
assert!(paths.contains(&format!("{dir}/")));
Ok(())
}