litellm/litellm-rust/crates/secrets/tests/source.rs
Yujong Lee b61449e35d
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
fix(gateway): read boot, OCR and config env settings through one injected Env
The gateway takes one Env snapshot, overlays config environment_variables on it and injects it into every reader, so OCR REQUEST_TIMEOUT, Vertex credentials, Messages thinking budgets and AWS credentials now see config env vars. Boot and UI settings move to Layered and envy is dropped. clippy.toml bans std::env::var

ProcessEnvironment is private to python-bridge, so library constructors take the lookup as a required argument instead of defaulting to the process (MessagesTransformContext, RedisCache, EnvironmentSecrets, OcrConnection). auth-aws reads every env-backed credential source through the lookup before handing the rest to the SDK chain, so the assume-role shortcut and the credentials it returns agree

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 10:02:00 -07:00

63 lines
2.1 KiB
Rust

#[cfg(test)]
mod tests {
use rstest::rstest;
use litellm_secrets::source::{EnvironmentSecrets, SecretSource};
#[rstest]
#[case::lowercase_true("LITELLM_ENVIRONMENT_SECRETS_TRUE", "true", None)]
#[case::padded_false("LITELLM_ENVIRONMENT_SECRETS_FALSE", " FALSE ", None)]
#[case::text("LITELLM_ENVIRONMENT_SECRETS_TEXT", "secret", Some("secret"))]
#[tokio::test]
async fn python_environment_values_are_absent_like_get_secret_str(
#[case] name: &'static str,
#[case] value: &'static str,
#[case] expected: Option<&str>,
) {
let secret = EnvironmentSecrets::python_compatible(
litellm_http::Client::plain_for_test(),
std::sync::Arc::new(move |key: &str| (key == name).then(|| value.to_owned())),
)
.resolve(&[name])
.await
.unwrap()
.get(name);
assert_eq!(secret.as_deref(), expected);
}
}
#[tokio::test]
async fn dynamic_names_use_the_same_resolver_and_snapshots_never_do_fresh_lookups() {
use litellm_secrets::source::SecretSource;
use litellm_secrets::{OidcResolver, SecretManagerState, SecretResolver};
use std::sync::{
Arc,
atomic::{AtomicUsize, Ordering},
};
let calls = Arc::new(AtomicUsize::new(0));
let reads = calls.clone();
let source = SecretResolver::new(
Arc::new(SecretManagerState::default()),
Arc::new(move |name: &str| {
reads.fetch_add(1, Ordering::SeqCst);
(name != "missing").then(|| name.to_owned())
}),
OidcResolver::new(litellm_http::Client::plain_for_test()),
);
let snapshot = source.resolve(&["declared", "missing"]).await.unwrap();
let name = format!("runtime-{}", "key");
assert_eq!(snapshot.get("declared").as_deref(), Some("declared"));
assert_eq!(snapshot.get("missing"), None);
assert_eq!(snapshot.get(&name), None);
assert_eq!(calls.load(Ordering::SeqCst), 2);
assert_eq!(
SecretSource::get_secret_str(&source, &name)
.await
.unwrap()
.unwrap()
.expose(),
name
);
assert_eq!(calls.load(Ordering::SeqCst), 3);
}