diff --git a/pyproject.toml b/pyproject.toml index 28174475..fd556aea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "sap-cloud-sdk" -version = "0.45.2" +version = "0.45.3" description = "SAP Cloud SDK for Python" readme = "README.md" license = "Apache-2.0" diff --git a/src/sap_cloud_sdk/agentgateway/_lob.py b/src/sap_cloud_sdk/agentgateway/_lob.py index 0c46124c..6a199b82 100644 --- a/src/sap_cloud_sdk/agentgateway/_lob.py +++ b/src/sap_cloud_sdk/agentgateway/_lob.py @@ -151,7 +151,12 @@ def get_ias_client_id_lob() -> str: ) if not dest: raise AgentGatewaySDKError(f"IAS destination '{dest_name}' not found") - return dest.properties.get("clientId", "") + client_id = dest.properties.get("clientId", "") + if not client_id: + raise AgentGatewaySDKError( + f"IAS destination '{dest_name}' does not contain a 'clientId' property" + ) + return client_id async def fetch_system_auth( diff --git a/src/sap_cloud_sdk/agentgateway/agw_client.py b/src/sap_cloud_sdk/agentgateway/agw_client.py index 6ee67458..6f353de6 100644 --- a/src/sap_cloud_sdk/agentgateway/agw_client.py +++ b/src/sap_cloud_sdk/agentgateway/agw_client.py @@ -347,6 +347,10 @@ def get_ias_client_id(self) -> str: "Customer agent credentials detected at '%s'", credentials_path ) credentials = load_customer_credentials(credentials_path) + if not credentials.client_id: + raise AgentGatewaySDKError( + "Customer agent credentials file does not contain a 'client_id'" + ) return credentials.client_id # LoB flow — read clientId from the IAS destination properties diff --git a/tests/agentgateway/unit/test_agw_client.py b/tests/agentgateway/unit/test_agw_client.py index 714c3ec9..207deb9d 100644 --- a/tests/agentgateway/unit/test_agw_client.py +++ b/tests/agentgateway/unit/test_agw_client.py @@ -1209,6 +1209,17 @@ def test_customer_raises_on_load_failure(self): with pytest.raises(AgentGatewaySDKError, match="Could not resolve IAS client ID"): create_client().get_ias_client_id() + def test_customer_raises_when_client_id_empty(self): + mock_creds = MagicMock() + mock_creds.client_id = "" + + with ( + patch(_DETECT_CREDS_PATCH, return_value="/etc/ums/credentials/credentials"), + patch(_LOAD_CREDS_PATCH, return_value=mock_creds), + ): + with pytest.raises(AgentGatewaySDKError, match="client_id"): + create_client().get_ias_client_id() + # --- LoB flow --- @_NO_CUSTOMER_CREDS @@ -1225,11 +1236,10 @@ def test_lob_raises_when_destination_not_found(self, _mock_detect): create_client(tenant_subdomain="my-tenant").get_ias_client_id() @_NO_CUSTOMER_CREDS - def test_lob_returns_empty_string_when_property_absent(self, _mock_detect): - with patch(_GET_IAS_CLIENT_ID_LOB_PATCH, return_value=""): - result = create_client(tenant_subdomain="my-tenant").get_ias_client_id() - - assert result == "" + def test_lob_raises_when_client_id_property_absent(self, _mock_detect): + with patch(_GET_IAS_CLIENT_ID_LOB_PATCH, side_effect=AgentGatewaySDKError("does not contain a 'clientId' property")): + with pytest.raises(AgentGatewaySDKError, match="clientId"): + create_client(tenant_subdomain="my-tenant").get_ias_client_id() @_NO_CUSTOMER_CREDS def test_lob_raises_on_exception(self, _mock_detect): diff --git a/tests/agentgateway/unit/test_lob.py b/tests/agentgateway/unit/test_lob.py index 6d972b8d..98c6ce02 100644 --- a/tests/agentgateway/unit/test_lob.py +++ b/tests/agentgateway/unit/test_lob.py @@ -1252,7 +1252,7 @@ def test_raises_when_destination_not_found(self): with pytest.raises(AgentGatewaySDKError, match="sap-managed-runtime-ias-eu10"): get_ias_client_id_lob() - def test_returns_empty_string_when_property_absent(self): + def test_raises_when_client_id_property_absent(self): mock_dest = MagicMock() mock_dest.properties = {} mock_dest_client = MagicMock() @@ -1262,9 +1262,8 @@ def test_returns_empty_string_when_property_absent(self): patch("sap_cloud_sdk.agentgateway._lob._ias_dest_name", return_value="sap-managed-runtime-ias-eu10"), patch("sap_cloud_sdk.agentgateway._lob.create_destination_client", return_value=mock_dest_client), ): - result = get_ias_client_id_lob() - - assert result == "" + with pytest.raises(AgentGatewaySDKError, match="clientId"): + get_ias_client_id_lob() def test_raises_when_landscape_env_not_set(self): with patch("sap_cloud_sdk.agentgateway._lob._ias_dest_name", side_effect=EnvironmentError("APPFND_CONHOS_LANDSCAPE not set")):