Start to write e2e tests

This commit is contained in:
2022-09-01 15:03:20 +02:00
parent caa62b8e49
commit 43a6d2c3a2
9 changed files with 369 additions and 29 deletions

View File

@ -2,7 +2,7 @@ use bytes::BufMut;
use clap::Parser;
/// TCP relay client
#[derive(Parser, Debug, Clone)]
#[derive(Parser, Debug, Clone, Default)]
#[clap(author, version, about, long_about = None)]
pub struct ClientConfig {
/// Access token
@ -21,20 +21,24 @@ pub struct ClientConfig {
#[clap(short = 'c', long)]
pub root_certificate: Option<String>,
#[clap(skip)]
_root_certificate_cache: Option<Vec<u8>>,
/// TLS certificate for TLS authentication.
#[clap(long)]
pub tls_cert: Option<String>,
#[clap(skip)]
_tls_cert_cache: Option<Vec<u8>>,
/// TLS key for TLS authentication.
#[clap(long)]
pub tls_key: Option<String>,
#[clap(skip)]
pub _keys_cache: KeysCache,
}
#[derive(Parser, Debug, Clone, Default)]
pub struct KeysCache {
#[clap(skip)]
_root_certificate_cache: Option<Vec<u8>>,
#[clap(skip)]
_tls_cert_cache: Option<Vec<u8>>,
#[clap(skip)]
_tls_key_cache: Option<Vec<u8>>,
}
@ -42,20 +46,20 @@ pub struct ClientConfig {
impl ClientConfig {
/// Load certificates and put them in cache
pub fn load_certificates(&mut self) {
self._root_certificate_cache = self
.root_certificate
.as_ref()
.map(|c| std::fs::read(c).expect("Failed to read root certificate!"));
self._tls_cert_cache = self
.tls_cert
.as_ref()
.map(|c| std::fs::read(c).expect("Failed to read client certificate!"));
self._tls_key_cache = self
.tls_key
.as_ref()
.map(|c| std::fs::read(c).expect("Failed to read client key!"));
self._keys_cache = KeysCache {
_root_certificate_cache: self
.root_certificate
.as_ref()
.map(|c| std::fs::read(c).expect("Failed to read root certificate!")),
_tls_cert_cache: self
.tls_cert
.as_ref()
.map(|c| std::fs::read(c).expect("Failed to read client certificate!")),
_tls_key_cache: self
.tls_key
.as_ref()
.map(|c| std::fs::read(c).expect("Failed to read client key!")),
};
}
/// Get client token, returning a dummy token if none was specified
@ -65,12 +69,15 @@ impl ClientConfig {
/// Get root certificate content
pub fn get_root_certificate(&self) -> Option<Vec<u8>> {
self._root_certificate_cache.clone()
self._keys_cache._root_certificate_cache.clone()
}
/// Get client certificate & key pair, if available
pub fn get_client_keypair(&self) -> Option<(&Vec<u8>, &Vec<u8>)> {
if let (Some(cert), Some(key)) = (&self._tls_cert_cache, &self._tls_key_cache) {
if let (Some(cert), Some(key)) = (
&self._keys_cache._tls_cert_cache,
&self._keys_cache._tls_key_cache,
) {
Some((cert, key))
} else {
None
@ -90,7 +97,7 @@ impl ClientConfig {
#[cfg(test)]
mod test {
use crate::client_config::ClientConfig;
use crate::tcp_relay_client::client_config::ClientConfig;
#[test]
fn verify_cli() {