aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2021-03-20 22:20:51 +0000
committerSven-Hendrik Haase <svenstaro@gmail.com>2021-03-20 22:20:51 +0000
commita9b343069db6618650a943303a96a933fcaeeafb (patch)
treeba407f64efc1ade54195a0dad47a03775c0aa26e
parentFinish up --hidden feature (diff)
downloadminiserve-a9b343069db6618650a943303a96a933fcaeeafb.tar.gz
miniserve-a9b343069db6618650a943303a96a933fcaeeafb.zip
Add negative test for hidden directories
Diffstat (limited to '')
-rw-r--r--tests/serve_request.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/serve_request.rs b/tests/serve_request.rs
index 7201e26..95449f5 100644
--- a/tests/serve_request.rs
+++ b/tests/serve_request.rs
@@ -3,6 +3,7 @@ mod fixtures;
use assert_cmd::prelude::*;
use assert_fs::fixture::TempDir;
use fixtures::{port, tmpdir, Error, DIRECTORIES, FILES, HIDDEN_DIRECTORIES, HIDDEN_FILES};
+use http::StatusCode;
use regex::Regex;
use rstest::rstest;
use select::document::Document;
@@ -123,6 +124,36 @@ fn serves_requests_hidden_files(tmpdir: TempDir, port: u16) -> Result<(), Error>
}
#[rstest]
+fn serves_requests_no_hidden_files_without_flag(tmpdir: TempDir, port: u16) -> Result<(), Error> {
+ let mut child = Command::cargo_bin("miniserve")?
+ .arg(tmpdir.path())
+ .arg("-p")
+ .arg(port.to_string())
+ .stdout(Stdio::null())
+ .spawn()?;
+
+ sleep(Duration::from_secs(1));
+
+ let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?
+ .error_for_status()?;
+ let parsed = Document::from_read(body)?;
+
+ for &hidden_item in HIDDEN_FILES.into_iter().chain(HIDDEN_DIRECTORIES) {
+ assert!(parsed
+ .find(|x: &Node| x.text() == hidden_item)
+ .next()
+ .is_none());
+ let resp =
+ reqwest::blocking::get(format!("http://localhost:{}/{}", port, hidden_item).as_str())?;
+ assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
+ }
+
+ child.kill()?;
+
+ Ok(())
+}
+
+#[rstest]
fn serves_requests_with_randomly_assigned_port(tmpdir: TempDir) -> Result<(), Error> {
let mut child = Command::cargo_bin("miniserve")?
.arg(tmpdir.path())