diff --git a/src/service.py b/src/service.py index f93971c0..1d5a01bf 100644 --- a/src/service.py +++ b/src/service.py @@ -397,6 +397,13 @@ def redfish_conn_params_valid(self, redfish_conn_params: Dict[str, str]) -> Opti if not redfish_conn_params: return None + # Skip redfish validation if either username/password is empty. + if not ( + redfish_conn_params.get("username", "") and redfish_conn_params.get("password", "") + ): + logger.warning("Empty redfish username/password, skip validation.") + return False + redfish_obj = None try: redfish_obj = redfish_client( diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index 2fecfb11..64b5279f 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -563,6 +563,39 @@ def test_redfish_conn_params_valid_failed_exception(self, mock_redfish_client): self.assertFalse(result) mock_redfish_client.return_value.login.assert_not_called() + @parameterized.expand( + [ + ( + "missing username", + { + "host": "hosta", + "username": "", + "password": "passwordc", + "timeout": "timeoutd", + }, + ), + ( + "missing password", + { + "host": "hosta", + "username": "usernameb", + "password": "", + "timeout": "timeoutd", + }, + ), + ] + ) + @mock.patch("service.redfish_client") + def test_redfish_conn_params_valid_failed_missing_credentials( + self, + _, + redfish_conn_params, + mock_redfish_client, + ): + result = self.exporter.redfish_conn_params_valid(redfish_conn_params) + self.assertEqual(result, False) + mock_redfish_client.assert_not_called() + def test_hw_tools(self): self.assertEqual( self.exporter.hw_tools(),