From db19ecc9696ea0de2632cd1ae7d204d0b3e228ef Mon Sep 17 00:00:00 2001 From: Stanislav Laznicka Date: Oct 26 2017 11:58:54 +0000 Subject: parameters: relax type checks The type checks in ipalib.parameters were too strict. An object that inherits from a type should implement its public interface. This should allow us checking for types of objects whose class implementations are private to a module but they implement a certain public interface (which is typical for e.g. python-cryptography). https://pagure.io/freeipa/issue/7131 Reviewed-By: Florence Blanc-Renaud --- diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 81586e2..fa0c813 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -848,8 +848,10 @@ class Param(ReadOnly): """ Convert a single scalar value. """ - if type(value) in self.allowed_types: - return value + for t in self.allowed_types: + if isinstance(value, t): + return value + raise ConversionError(name=self.name, error=ugettext(self.type_error)) def validate(self, value, supplied=None): @@ -879,7 +881,10 @@ class Param(ReadOnly): self._validate_scalar(value) def _validate_scalar(self, value, index=None): - if type(value) not in self.allowed_types: + for t in self.allowed_types: + if isinstance(value, t): + break + else: raise TypeError( TYPE_ERROR % (self.name, self.type, value, type(value)) )