FIX: TLS options

This commit is contained in:
2026-03-10 16:52:13 +00:00
parent 67547d677c
commit b7bbaa2d33
8 changed files with 291 additions and 34 deletions

View File

@@ -246,3 +246,6 @@ impl FurumiClient {
Ok(stream)
}
}
#[cfg(test)]
mod tests;

View File

@@ -0,0 +1,66 @@
use crate::client::AuthInterceptor;
use tonic::{Request, service::Interceptor};
#[test]
fn test_auth_interceptor_with_token() {
let mut interceptor = AuthInterceptor {
token: "my-secret-token".to_string(),
};
let req = Request::new(());
let res = interceptor.call(req).expect("Failed to intercept");
let auth_header = res.metadata().get("authorization").expect("Missing auth header");
assert_eq!(auth_header.to_str().unwrap(), "Bearer my-secret-token");
}
#[test]
fn test_auth_interceptor_empty_token() {
let mut interceptor = AuthInterceptor {
token: "".to_string(),
};
let req = Request::new(());
let res = interceptor.call(req).expect("Failed to intercept");
assert!(res.metadata().get("authorization").is_none(), "Auth header should not be set for empty token");
}
#[test]
fn test_auth_interceptor_invalid_chars() {
let mut interceptor = AuthInterceptor {
// ASCII control characters are invalid in Metadata values
token: "token\nwith\nnewlines".to_string(),
};
let req = Request::new(());
let res = interceptor.call(req);
assert!(res.is_err(), "Interceptor should fail on invalid token characters");
assert_eq!(res.unwrap_err().code(), tonic::Code::InvalidArgument);
}
use furumi_common::proto::AttrResponse;
#[tokio::test]
async fn test_client_caching_logic() {
let cache = moka::future::Cache::builder()
.max_capacity(100)
.build();
let path = "/test/file.txt";
let attr = AttrResponse {
size: 1024,
mode: 0o644,
mtime: 1234567890,
};
cache.insert(path.to_string(), attr.clone()).await;
let cached_attr = cache.get(path).await.expect("Item should be in cache");
assert_eq!(cached_attr.size, attr.size);
assert_eq!(cached_attr.mode, attr.mode);
assert_eq!(cached_attr.mtime, attr.mtime);
assert!(cache.get("/non/existent").await.is_none());
}