dufs/tests/tls.rs

56 lines
1.5 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;
/// 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> {
Command::cargo_bin("dufs")?
2022-11-10 10:38:35 +03:00
.args(["--tls-cert", "wrong", "--tls-key", "tests/data/key.pem"])
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> {
Command::cargo_bin("dufs")?
2022-11-10 10:38:35 +03:00
.args(["--tls-cert", "tests/data/cert.pem", "--tls-key", "wrong"])
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(())
}