diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2021-08-27 02:11:10 +0000 |
---|---|---|
committer | Sven-Hendrik Haase <svenstaro@gmail.com> | 2021-08-27 02:11:10 +0000 |
commit | aad1c0ae685865e7e65ef194f49d6020c5e9e65f (patch) | |
tree | e49a7a0930778acd38e19f2b716d2254336be4ea /tests/fixtures/mod.rs | |
parent | Golf tests a bit more (diff) | |
download | miniserve-aad1c0ae685865e7e65ef194f49d6020c5e9e65f.tar.gz miniserve-aad1c0ae685865e7e65ef194f49d6020c5e9e65f.zip |
Add TLS support via rustls (fixes #18)
Diffstat (limited to '')
-rw-r--r-- | tests/fixtures/mod.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index a227f84..9f3560d 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -88,7 +88,7 @@ pub fn port() -> u16 { #[allow(dead_code)] pub fn server<I>(#[default(&[] as &[&str])] args: I) -> TestServer where - I: IntoIterator, + I: IntoIterator + Clone, I::Item: AsRef<std::ffi::OsStr>, { let port = port(); @@ -98,13 +98,16 @@ where .arg(tmpdir.path()) .arg("-p") .arg(port.to_string()) - .args(args) + .args(args.clone()) .stdout(Stdio::null()) .spawn() .expect("Couldn't run test binary"); + let is_tls = args + .into_iter() + .any(|x| x.as_ref().to_str().unwrap().contains("tls")); wait_for_port(port); - TestServer::new(port, tmpdir, child) + TestServer::new(port, tmpdir, child, is_tls) } /// Same as `server()` but ignore stderr @@ -112,7 +115,7 @@ where #[allow(dead_code)] pub fn server_no_stderr<I>(#[default(&[] as &[&str])] args: I) -> TestServer where - I: IntoIterator, + I: IntoIterator + Clone, I::Item: AsRef<std::ffi::OsStr>, { let port = port(); @@ -122,14 +125,17 @@ where .arg(tmpdir.path()) .arg("-p") .arg(port.to_string()) - .args(args) + .args(args.clone()) .stdout(Stdio::null()) .stderr(Stdio::null()) .spawn() .expect("Couldn't run test binary"); + let is_tls = args + .into_iter() + .any(|x| x.as_ref().to_str().unwrap().contains("tls")); wait_for_port(port); - TestServer::new(port, tmpdir, child) + TestServer::new(port, tmpdir, child, is_tls) } /// Wait a max of 1s for the port to become available. @@ -150,23 +156,29 @@ pub struct TestServer { port: u16, tmpdir: TempDir, child: Child, + is_tls: bool, } #[allow(dead_code)] impl TestServer { - pub fn new(port: u16, tmpdir: TempDir, child: Child) -> Self { + pub fn new(port: u16, tmpdir: TempDir, child: Child, is_tls: bool) -> Self { Self { port, tmpdir, child, + is_tls, } } + pub fn url(&self) -> Url { - Url::parse(&format!("http://localhost:{}", self.port)).unwrap() + let protocol = if self.is_tls { "https" } else { "http" }; + Url::parse(&format!("{}://localhost:{}", protocol, self.port)).unwrap() } + pub fn path(&self) -> &std::path::Path { self.tmpdir.path() } + pub fn port(&self) -> u16 { self.port } |