cfg_if::cfg_if! {
if #[cfg(any(feature = "tls-with-openssl", feature = "tls-with-openssl-vendored"))] {
use crate::net::tls::openssl::connect_with_tcpstream_factory;
} else if #[cfg(feature = "tls-with-rustls")] {
use crate::net::tls::rustls::connect_with_tcpstream_factory;
}
}
#[test]
#[cfg(any(
feature = "tls-with-openssl",
feature = "tls-with-openssl-vendored",
feature = "tls-with-rustls"
))]
fn parse_pem_files_correctly() {
use crate::net::{ConnectionSettings, NetError, TlsClientAuth, TlsServerAuth};
static ERR_MSG: &str = "configured but will not connect due to being a test";
let server_cert = std::fs::read("test-data/cert.pem").unwrap();
let ca_cert = std::fs::read("test-data/root-ca.pem").unwrap();
let client_cert = std::fs::read("test-data/client-cert.pem").unwrap();
let client_key = std::fs::read("test-data/client-cert.key.pem").unwrap();
let tls_client_auth = Some(TlsClientAuth {
cert_bytes: client_cert,
private_key_bytes: client_key,
});
for tls_server_auth in [
TlsServerAuth::TrustCertificate(server_cert),
TlsServerAuth::TrustCertificate(ca_cert),
] {
let conn_settings = ConnectionSettings {
host: "localhost".to_string(),
port: 12345,
username: None,
password: None,
connect_timeout: None,
read_timeout: None,
write_timeout: None,
max_response_bytes: None,
tls_client_auth: tls_client_auth.clone(),
tls_server_auth,
tls_server_name: None,
};
let res = connect_with_tcpstream_factory(&conn_settings, |_addr, _settings| {
Err(NetError::InternalError(ERR_MSG.to_string()))
});
assert!(matches!(res.unwrap_err(), NetError::InternalError(msg) if msg == ERR_MSG));
}
}