mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 00:59:02 +03:00
test: add integration tests (#36)
This commit is contained in:
46
tests/symlink.rs
Normal file
46
tests/symlink.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
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::retrive_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::retrive_index_paths(&resp.text()?);
|
||||
assert!(!paths.is_empty());
|
||||
assert!(paths.contains(&format!("{}/", dir)));
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user