mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-27 01:22:18 +00:00
* fix(secrets): verify provider API request and payload contracts * wip * fix(secrets): unify backend reads and route secret resolution * feat(secrets): bind built-in managers to retained Rust backends * refactor(secrets): centralize catalog dispatch and native binding * test(secrets): split provider integration tests * refactor(secrets): enforce cache and rotation contracts * test(secrets): stub parent packages in failing resolver fixture Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(secrets): pass manager settings through the interop boundary Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(secrets): align cloud KMS auth and harden provider reads * ci(rust): raise native wheel size gate to 40 MB for secrets backends Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(proxy): treat unset google kms flag as disabled like the old loader Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(secrets): preserve certificate credentials and disabled KMS flags * test(secrets): cover certificate validation and bounded auth retries * test(secrets): cover Python dispatch without the native extension * test(proxy): skip legacy secret manager cases when the optional SDK is missing Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(secrets): port Python parity tests and preserve provider behavior * fix(secrets): store the captured native config without setattr to satisfy the strict lint budget Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(secrets): preserve missing Azure manager values Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(secrets): pin typed values and recovery failure precedence * refactor(secrets): organize provider internals and behavioral test suites * refactor(secrets): simplify recovery and isolate Python compatibility * fix(secrets): distinguish Azure callback absence from HTTP not found * fix(secrets): preserve Python AWS read results at the bridge * fix(secrets): route public reads through the native catalog bridge * fix(secrets): keep JSON selection outside the bridge Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(secrets): preserve provider JSON reads at the bridge Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(secrets): preserve Python primary JSON semantics Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(secrets): preserve CyberArk mutation behavior through the native bridge * docs(secrets): record public API replacement gaps * refactor(secrets): share Vault write payload preparation * feat(secrets): route Vault mutations through the native bridge * fix(secrets): preserve typed Vault rotation failures * refactor(secrets): move Python dispatch into bridge * refactor(secrets): move CyberArk Python policy into bridge * refactor(secrets): move Vault Python policy into bridge * test(secrets): assert Vault rotation request paths * fix(secrets): keep bridge JSON interop centralized Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
117 lines
4 KiB
Rust
117 lines
4 KiB
Rust
#![cfg(feature = "google")]
|
|
|
|
use std::sync::Arc;
|
|
|
|
#[rstest::rstest]
|
|
#[case::missing(404)]
|
|
#[case::failure(503)]
|
|
#[tokio::test]
|
|
async fn google_resolver_distinguishes_absence_from_failure(#[case] status: u16) {
|
|
use litellm_secrets::{
|
|
Error, FailurePolicy, KeyManagementSettings, OidcResolver, SecretManager,
|
|
SecretManagerState, SecretResolver, SecretValue, google::GoogleSecretManager,
|
|
};
|
|
use wiremock::{Mock, MockServer, ResponseTemplate, matchers::method};
|
|
let server = MockServer::start().await;
|
|
Mock::given(method("GET"))
|
|
.respond_with(ResponseTemplate::new(status))
|
|
.expect(1)
|
|
.mount(&server)
|
|
.await;
|
|
let environment: Arc<dyn litellm_core_utils::settings::Lookup + Send + Sync> =
|
|
Arc::new(|name: &str| match name {
|
|
"VERTEX_AI_API_KEY" => Some("token".into()),
|
|
"KEY" => Some("environment".into()),
|
|
_ => None,
|
|
});
|
|
let manager = GoogleSecretManager::with_client(
|
|
reqwest::Client::new(),
|
|
server.uri().parse().unwrap(),
|
|
"project".into(),
|
|
environment.clone(),
|
|
None,
|
|
false,
|
|
)
|
|
.unwrap();
|
|
let state = SecretManagerState::new(
|
|
SecretManager::GoogleSecretManager(manager),
|
|
KeyManagementSettings::default(),
|
|
);
|
|
let resolver = SecretResolver::new_python_compatible(
|
|
Arc::new(state),
|
|
environment,
|
|
OidcResolver::default(),
|
|
)
|
|
.with_failure_policy(FailurePolicy::Propagate);
|
|
let result = resolver.get_secret_str("KEY", None).await;
|
|
if status == 404 {
|
|
assert!(matches!(result, Err(Error::ManagedSecretMissing)));
|
|
} else {
|
|
assert!(
|
|
matches!(result, Err(Error::Google(litellm_secrets::google::Error::Status(actual))) if actual == status)
|
|
);
|
|
}
|
|
let fallback = resolver
|
|
.with_failure_policy(FailurePolicy::EnvironmentFallback)
|
|
.get_secret_str("KEY", None)
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(
|
|
fallback.as_ref().map(SecretValue::expose),
|
|
Some("environment")
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn google_handler_requires_canonical_base64_and_preserves_plaintext_whitespace() {
|
|
use base64::{Engine, engine::general_purpose::STANDARD};
|
|
use google_cloud_kms_v1::client::KeyManagementService;
|
|
use litellm_secrets::{
|
|
Error, KeyManagementSettings, SecretManager, get_secret_from_manager, google::GoogleKms,
|
|
};
|
|
use wiremock::{
|
|
Mock, MockServer, ResponseTemplate,
|
|
matchers::{body_json, path},
|
|
};
|
|
|
|
let server = MockServer::start().await;
|
|
let resource = "projects/project/locations/global/keyRings/ring/cryptoKeys/key";
|
|
Mock::given(path(format!("/v1/{resource}:decrypt")))
|
|
.and(body_json(
|
|
serde_json::json!({"ciphertext":STANDARD.encode("encrypted")}),
|
|
))
|
|
.respond_with(
|
|
ResponseTemplate::new(200)
|
|
.set_body_json(serde_json::json!({"plaintext":STANDARD.encode(" value\n")})),
|
|
)
|
|
.expect(1)
|
|
.mount(&server)
|
|
.await;
|
|
let client = KeyManagementService::builder()
|
|
.with_endpoint(server.uri())
|
|
.with_credentials(google_cloud_auth::credentials::anonymous::Builder::new().build())
|
|
.build()
|
|
.await
|
|
.unwrap();
|
|
let manager = SecretManager::GoogleKms(GoogleKms::new(client, resource.into()));
|
|
let settings = KeyManagementSettings::default();
|
|
let value = get_secret_from_manager(&manager, "KEY", &settings, &|_: &str| {
|
|
Some(STANDARD.encode("encrypted"))
|
|
})
|
|
.await
|
|
.unwrap()
|
|
.unwrap();
|
|
assert_eq!(value.as_str(), Some(" value\n"));
|
|
assert!(matches!(
|
|
get_secret_from_manager(&manager, "KEY", &settings, &|_: &str| Some(format!(
|
|
" {}",
|
|
STANDARD.encode("encrypted")
|
|
)))
|
|
.await,
|
|
Err(Error::InvalidCiphertext)
|
|
));
|
|
assert!(matches!(
|
|
get_secret_from_manager(&manager, "KEY", &settings, &|_: &str| None).await,
|
|
Err(Error::MissingCiphertext)
|
|
));
|
|
}
|