Skip to content

Commit

Permalink
fix: redfish validation (#276)
Browse files Browse the repository at this point in the history
* fix: redfish validation

Skip redfish validation if either username or password is missing
fix: #270
  • Loading branch information
jneo8 authored Jul 9, 2024
1 parent e51d69b commit e46d08f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e46d08f

Please sign in to comment.