aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2019-05-06 14:17:05 +0000
committerGitHub <noreply@github.com>2019-05-06 14:17:05 +0000
commit01fa168786ca99fc3ee2af0f8bfb58300dedf90e (patch)
treecd0b53840174ee511885f1d17b8b4a1b67a167a3
parentMerge pull request #105 from svenstaro/dependabot/cargo/rstest-833bca6 (diff)
parentUse constant for assertion (diff)
downloadminiserve-01fa168786ca99fc3ee2af0f8bfb58300dedf90e.tar.gz
miniserve-01fa168786ca99fc3ee2af0f8bfb58300dedf90e.zip
Merge pull request #102 from KSXGitHub/test-auth-rejects
Add integration test where it rejects authentication
-rw-r--r--tests/auth.rs60
1 files changed, 59 insertions, 1 deletions
diff --git a/tests/auth.rs b/tests/auth.rs
index f43553b..96cdcb5 100644
--- a/tests/auth.rs
+++ b/tests/auth.rs
@@ -9,6 +9,7 @@ use select::predicate::Text;
use std::process::{Command, Stdio};
use std::thread::sleep;
use std::time::Duration;
+use reqwest::StatusCode;
#[rstest_parametrize(
cli_auth_arg, client_username, client_password,
@@ -24,7 +25,7 @@ use std::time::Duration;
"testpassword"
),
)]
-fn auth_works(
+fn auth_accepts(
tmpdir: TempDir,
port: u16,
cli_auth_arg: &str,
@@ -57,3 +58,60 @@ fn auth_works(
Ok(())
}
+
+#[rstest_parametrize(
+ cli_auth_arg, client_username, client_password,
+ case("rightuser:rightpassword", "wronguser", "rightpassword"),
+ case(
+ "rightuser:sha256:314eee236177a721d0e58d3ca4ff01795cdcad1e8478ba8183a2e58d69c648c0",
+ "wronguser",
+ "rightpassword"
+ ),
+ case(
+ "rightuser:sha512:84ec4056571afeec9f5b59453305877e9a66c3f9a1d91733fde759b370c1d540b9dc58bfc88c5980ad2d020c3a8ee84f21314a180856f5a82ba29ecba29e2cab",
+ "wronguser",
+ "rightpassword"
+ ),
+ case("rightuser:rightpassword", "rightuser", "wrongpassword"),
+ case(
+ "rightuser:sha256:314eee236177a721d0e58d3ca4ff01795cdcad1e8478ba8183a2e58d69c648c0",
+ "rightuser",
+ "wrongpassword"
+ ),
+ case(
+ "rightuser:sha512:84ec4056571afeec9f5b59453305877e9a66c3f9a1d91733fde759b370c1d540b9dc58bfc88c5980ad2d020c3a8ee84f21314a180856f5a82ba29ecba29e2cab",
+ "rightuser",
+ "wrongpassword"
+ ),
+)]
+fn auth_rejects(
+ tmpdir: TempDir,
+ port: u16,
+ cli_auth_arg: &str,
+ client_username: &str,
+ client_password: &str,
+) -> Result<(), Error> {
+ let mut child = Command::cargo_bin("miniserve")?
+ .arg(tmpdir.path())
+ .arg("-p")
+ .arg(port.to_string())
+ .arg("-a")
+ .arg(cli_auth_arg)
+ .stdout(Stdio::null())
+ .spawn()?;
+
+ sleep(Duration::from_secs(1));
+
+ let client = reqwest::Client::new();
+ let status = client
+ .get(format!("http://localhost:{}", port).as_str())
+ .basic_auth(client_username, Some(client_password))
+ .send()?
+ .status();
+
+ assert_eq!(status, StatusCode::UNAUTHORIZED);
+
+ child.kill()?;
+
+ Ok(())
+}