2022-06-12 03:43:50 +03: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 03:51:12 +03:00
|
|
|
let paths = utils::retrieve_index_paths(&resp.text()?);
|
2022-06-12 03:43:50 +03:00
|
|
|
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())?;
|
2022-08-03 03:51:12 +03:00
|
|
|
let paths = utils::retrieve_index_paths(&resp.text()?);
|
2022-06-12 03:43:50 +03:00
|
|
|
assert!(!paths.is_empty());
|
|
|
|
assert!(paths.contains(&format!("{}/", dir)));
|
|
|
|
Ok(())
|
|
|
|
}
|