From daf308322829b6fba163875581bb626a4d5b96b7 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Fri, 5 May 2017 11:01:27 +0100 Subject: [PATCH] Improve driver_info/redfish_system_id value validation This patch making sure that the value passed to driver_info/redfish_system_id is a string. The value of that property should be a canonical path to the System resource (in RedFish) that Ironic will manage. Change-Id: Ifb9e6e0cdb2b32370068fcee78edd136ff5ed7ce Closes-Bug: #1687658 --- ironic/drivers/modules/redfish/utils.py | 12 +++++++++++- .../tests/unit/drivers/modules/redfish/test_utils.py | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py index 276da6e43e..df2870e504 100644 --- a/ironic/drivers/modules/redfish/utils.py +++ b/ironic/drivers/modules/redfish/utils.py @@ -21,6 +21,7 @@ from oslo_utils import importutils import retrying import rfc3986 import six +from six.moves import urllib from ironic.common import exception from ironic.common.i18n import _ @@ -102,7 +103,16 @@ def parse_driver_info(node): 'driver_info/redfish_address on node %(node)s') % {'address': address, 'node': node.uuid}) - system_id = driver_info['redfish_system_id'] + try: + system_id = urllib.parse.quote(driver_info['redfish_system_id']) + except (TypeError, AttributeError): + raise exception.InvalidParameterValue( + _('Invalid value "%(value)s" set in ' + 'driver_info/redfish_system_id on node %(node)s. ' + 'The value should be a path (string) to the resource ' + 'that the driver will interact with. For example: ' + '/redfish/v1/Systems/1') % + {'value': driver_info['redfish_system_id'], 'node': node.uuid}) # Check if verify_ca is a Boolean or a file/directory in the file-system verify_ca = driver_info.get('redfish_verify_ca', True) diff --git a/ironic/tests/unit/drivers/modules/redfish/test_utils.py b/ironic/tests/unit/drivers/modules/redfish/test_utils.py index d9b6fcc2c5..4769aa995d 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_utils.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_utils.py @@ -115,6 +115,13 @@ class RedfishUtilsTestCase(db_base.DbTestCase): 'Invalid value type', redfish_utils.parse_driver_info, self.node) + def test_parse_driver_info_invalid_system_id(self): + # Integers are not supported + self.node.driver_info['redfish_system_id'] = 123 + self.assertRaisesRegex(exception.InvalidParameterValue, + 'The value should be a path', + redfish_utils.parse_driver_info, self.node) + @mock.patch('ironic.drivers.modules.redfish.utils.sushy') def test_get_system(self, mock_sushy): fake_conn = mock_sushy.Sushy.return_value