(sap) fix validate credentials, add negative tests for credential fetching

This commit is contained in:
Vasilisa Parshikova 2026-03-23 15:59:17 +04:00
parent 4ea62d5fdf
commit b1633852b8
2 changed files with 22 additions and 1 deletions

View file

@ -312,7 +312,7 @@ def validate_credentials(
)
modes = [
client_secret is not None,
bool(client_secret),
(cert_str is not None and key_str is not None),
(cert_file_path is not None and key_file_path is not None),
]

View file

@ -1,4 +1,5 @@
import json
import pytest
import litellm.llms.sap.credentials as sap_credentials
mock_sap_service_key_dict = {
@ -85,3 +86,23 @@ def test_creds_priority_order(monkeypatch):
creds = sap_credentials.fetch_credentials(service_key=json.dumps(mock_sap_service_key_dict))
assert creds['client_id'] == "mockclientid"
assert creds['resource_group'] == "env-resource-group"
def test_no_credentials_configured(monkeypatch):
_prep_env(monkeypatch)
with pytest.raises(ValueError, match="No credentials found in any source"):
sap_credentials.fetch_credentials()
def test_partial_credentials_missing_auth_url(monkeypatch):
_prep_env(monkeypatch)
# Set only client_id and base_url, missing auth_url
monkeypatch.setenv("AICORE_CLIENT_ID", "test-client-id")
monkeypatch.setenv("AICORE_BASE_URL", "test-base-url")
# fetch_credentials should succeed (it returns whatever it finds)
creds = sap_credentials.fetch_credentials()
creds.pop('resource_group')
with pytest.raises(ValueError, match="SAP AI Core credentials not found."):
sap_credentials.validate_credentials(**creds)