Improve SDL API set() function argument validation to cover also dictionary items.
Issue-ID: RIC-379.
Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
Change-Id: I006ec530e0127a731f96154088e29b3b9d0e49c6
Version history
---------------
Version history
---------------
+[2.0.4] - 2020-05-13
+
+* Enhance SDL API set() function argument validation to cover also dictionary items.
+
[2.0.3] - 2020-01-22
* Add a new SDL storage API function `is_active()` to check healthiness of SDL instance.
[2.0.3] - 2020-01-22
* Add a new SDL storage API function `is_active()` to check healthiness of SDL instance.
@func_arg_checker(SdlTypeError, 1, ns=str, data_map=dict)
def set(self, ns: str, data_map: Dict[str, bytes]) -> None:
@func_arg_checker(SdlTypeError, 1, ns=str, data_map=dict)
def set(self, ns: str, data_map: Dict[str, bytes]) -> None:
+ self._validate_key_value_dict(data_map)
self.__dbbackend.set(ns, data_map)
@func_arg_checker(SdlTypeError, 1, ns=str, key=str, old_data=bytes, new_data=bytes)
self.__dbbackend.set(ns, data_map)
@func_arg_checker(SdlTypeError, 1, ns=str, key=str, old_data=bytes, new_data=bytes)
def get_configuration(self) -> _Configuration:
"""Return configuration what was valid when the SDL instance was initiated."""
return self.__configuration
def get_configuration(self) -> _Configuration:
"""Return configuration what was valid when the SDL instance was initiated."""
return self.__configuration
+
+ @classmethod
+ def _validate_key_value_dict(cls, kv):
+ for k, v in kv.items():
+ if not isinstance(k, str):
+ raise SdlTypeError(r"Wrong dict key type: {}={}. Must be: str".format(k, type(k)))
+ if not isinstance(v, bytes):
+ raise SdlTypeError(r"Wrong dict value type: {}={}. Must be: bytes".format(v, type(v)))
self.storage.set(123, {'a': b'v1'})
with pytest.raises(SdlTypeError):
self.storage.set('ns', [1, 2])
self.storage.set(123, {'a': b'v1'})
with pytest.raises(SdlTypeError):
self.storage.set('ns', [1, 2])
+ with pytest.raises(SdlTypeError):
+ self.storage.set('ns', {0xbad: b'v1'})
+ with pytest.raises(SdlTypeError):
+ self.storage.set('ns', {'a': 0xbad})
def test_set_if_function_success(self):
self.mock_db_backend.set_if.return_value = True
def test_set_if_function_success(self):
self.mock_db_backend.set_if.return_value = True