aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auth.rs
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2019-05-01 05:56:35 +0000
committerGitHub <noreply@github.com>2019-05-01 05:56:35 +0000
commitf099134d2b86924fad0ddc615e5fecfb716c7ee0 (patch)
treed1142b0fd13b2ed92f1216b0672df8befc81d928 /tests/auth.rs
parentMerge pull request #96 from svenstaro/dependabot/cargo/reqwest-0.9.16 (diff)
parentAllow dead code to fix false negative warnings (diff)
downloadminiserve-f099134d2b86924fad0ddc615e5fecfb716c7ee0.tar.gz
miniserve-f099134d2b86924fad0ddc615e5fecfb716c7ee0.zip
Merge pull request #91 from KSXGitHub/split-integration-test
Split integration test into multiple files
Diffstat (limited to '')
-rw-r--r--tests/auth.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auth.rs b/tests/auth.rs
new file mode 100644
index 0000000..48f070e
--- /dev/null
+++ b/tests/auth.rs
@@ -0,0 +1,50 @@
+mod fixtures;
+use fixtures::*;
+
+#[rstest_parametrize(
+ cli_auth_arg, client_username, client_password,
+ case("testuser:testpassword", "testuser", "testpassword"),
+ case(
+ "testuser:sha256:9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05",
+ "testuser",
+ "testpassword"
+ ),
+ case(
+ "testuser:sha512:e9e633097ab9ceb3e48ec3f70ee2beba41d05d5420efee5da85f97d97005727587fda33ef4ff2322088f4c79e8133cc9cd9f3512f4d3a303cbdb5bc585415a00",
+ "testuser",
+ "testpassword"
+ ),
+)]
+fn auth_works(
+ 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 body = client
+ .get(format!("http://localhost:{}", port).as_str())
+ .basic_auth(client_username, Some(client_password))
+ .send()?
+ .error_for_status()?;
+ let parsed = Document::from_read(body)?;
+ for &file in FILES {
+ assert!(parsed.find(Text).any(|x| x.text() == file));
+ }
+
+ child.kill()?;
+
+ Ok(())
+}