diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2025-03-07 11:38:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-07 11:38:10 +0000 |
commit | 419204c291273e073cb4e1049655bea848dbc441 (patch) | |
tree | 341cb7ac4bd5915deb8fe58947b3cc352687556d /tests/api.rs | |
parent | Reformat style.scss (diff) | |
parent | Add asynchronous directory size counting (diff) | |
download | miniserve-419204c291273e073cb4e1049655bea848dbc441.tar.gz miniserve-419204c291273e073cb4e1049655bea848dbc441.zip |
Merge pull request #1482 from svenstaro/add-asynchronous-directory-size-loading
Add asynchronous directory size counting
Diffstat (limited to 'tests/api.rs')
-rw-r--r-- | tests/api.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/api.rs b/tests/api.rs new file mode 100644 index 0000000..32d6cef --- /dev/null +++ b/tests/api.rs @@ -0,0 +1,53 @@ +use std::collections::HashMap; + +use reqwest::{StatusCode, blocking::Client}; +use rstest::rstest; + +mod fixtures; + +use crate::fixtures::{DIRECTORIES, Error, TestServer, server}; + +#[rstest] +fn api_dir_size(server: TestServer) -> Result<(), Error> { + let mut command = HashMap::new(); + command.insert("DirSize", DIRECTORIES[0]); + + let resp = Client::new() + .post(server.url().join(&format!("__miniserve_internal/api"))?) + .json(&command) + .send()? + .error_for_status()?; + + assert_eq!(resp.status(), StatusCode::OK); + assert_ne!(resp.text()?, "0 B"); + + Ok(()) +} + +/// Test for path traversal vulnerability (CWE-22) in DirSize parameter. +#[rstest] +#[case("/tmp")] // Not CWE-22, but `foo` isn't a directory +#[case("/../foo")] +#[case("../foo")] +#[case("../tmp")] +#[case("/tmp")] +#[case("/foo")] +#[case("C:/foo")] +#[case(r"C:\foo")] +#[case(r"\foo")] +fn api_dir_size_prevent_path_transversal_attacks( + server: TestServer, + #[case] path: &str, +) -> Result<(), Error> { + let mut command = HashMap::new(); + command.insert("DirSize", path); + + let resp = Client::new() + .post(server.url().join(&format!("__miniserve_internal/api"))?) + .json(&command) + .send()?; + + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + + Ok(()) +} |