dufs/tests/tls.rs

74 lines
1.8 KiB
Rust
Raw Normal View History

2022-06-12 03:43:50 +03:00
mod fixtures;
mod utils;
use assert_cmd::Command;
use fixtures::{server, Error, TestServer};
use predicates::str::contains;
use reqwest::blocking::ClientBuilder;
use rstest::rstest;
use crate::fixtures::port;
2022-06-12 03:43:50 +03:00
/// Can start the server with TLS and receive encrypted responses.
#[rstest]
#[case(server(&[
"--tls-cert", "tests/data/cert.pem",
"--tls-key", "tests/data/key_pkcs8.pem",
]))]
#[case(server(&[
"--tls-cert", "tests/data/cert.pem",
"--tls-key", "tests/data/key_pkcs1.pem",
]))]
2022-08-02 04:32:11 +03:00
#[case(server(&[
"--tls-cert", "tests/data/cert_ecdsa.pem",
"--tls-key", "tests/data/key_ecdsa.pem",
]))]
2022-06-12 03:43:50 +03:00
fn tls_works(#[case] server: TestServer) -> Result<(), Error> {
let client = ClientBuilder::new()
.danger_accept_invalid_certs(true)
.build()?;
let resp = client.get(server.url()).send()?.error_for_status()?;
assert_resp_paths!(resp);
2022-06-12 03:43:50 +03:00
Ok(())
}
/// Wrong path for cert throws error.
#[rstest]
fn wrong_path_cert() -> Result<(), Error> {
let port = port().to_string();
Command::cargo_bin("dufs")?
.args([
"--tls-cert",
"wrong",
"--tls-key",
"tests/data/key.pem",
"--port",
&port,
])
2022-06-12 03:43:50 +03:00
.assert()
.failure()
2023-03-12 10:20:40 +03:00
.stderr(contains("Failed to access `wrong`"));
2022-06-12 03:43:50 +03:00
Ok(())
}
/// Wrong paths for key throws errors.
#[rstest]
fn wrong_path_key() -> Result<(), Error> {
let port = port().to_string();
Command::cargo_bin("dufs")?
.args([
"--tls-cert",
"tests/data/cert.pem",
"--tls-key",
"wrong",
"--port",
&port,
])
2022-06-12 03:43:50 +03:00
.assert()
.failure()
2023-03-12 10:20:40 +03:00
.stderr(contains("Failed to access `wrong`"));
2022-06-12 03:43:50 +03:00
Ok(())
}