diff --git a/litellm/llms/sap/credentials.py b/litellm/llms/sap/credentials.py index 11a455b6373..1ecdf09fc4f 100644 --- a/litellm/llms/sap/credentials.py +++ b/litellm/llms/sap/credentials.py @@ -286,8 +286,7 @@ def fetch_credentials( resource_group = resolve_resource_group(sources) - if resource_group is not None: - credentials["resource_group"] = resource_group + credentials["resource_group"] = resource_group if "cert_url" in credentials: credentials["auth_url"] = credentials.pop("cert_url") @@ -313,8 +312,8 @@ def validate_credentials( modes = [ 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), + bool(cert_str) and bool(key_str), + bool(cert_file_path) and bool(key_file_path), ] if sum(bool(m) for m in modes) != 1: raise ValueError( diff --git a/tests/test_litellm/llms/sap/test_sap_fetch_creds.py b/tests/test_litellm/llms/sap/test_sap_fetch_creds.py index be9721512db..77e2848f737 100644 --- a/tests/test_litellm/llms/sap/test_sap_fetch_creds.py +++ b/tests/test_litellm/llms/sap/test_sap_fetch_creds.py @@ -105,4 +105,19 @@ def test_partial_credentials_missing_auth_url(monkeypatch): creds.pop('resource_group') with pytest.raises(ValueError, match="SAP AI Core credentials not found."): - sap_credentials.validate_credentials(**creds) \ No newline at end of file + sap_credentials.validate_credentials(**creds) + +def test_credentials_without_authentication_mode(monkeypatch): + _prep_env(monkeypatch) + + # Set all required fields but no authentication mode (no client_secret, no certs) + monkeypatch.setenv("AICORE_CLIENT_ID", "test-client-id") + monkeypatch.setenv("AICORE_AUTH_URL", "test-auth-url") + monkeypatch.setenv("AICORE_BASE_URL", "test-base-url") + + creds = sap_credentials.fetch_credentials() + creds.pop('resource_group') + + # validate_credentials should raise because no authentication mode is provided + with pytest.raises(ValueError, match="SAP AI Core credentials are incomplete."): + sap_credentials.validate_credentials(**creds)