Principal: validate type of input parameter

Bytes are unsupported and we should raise a TypeError from Principal
__init__ method otherwise we get hard to debug result

Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
Martin Basti committed 2017-01-31 18:33:27 +01:00
1 parent deaf9ae247
commit 1023cfebff
1 file changed
+6 -1
+6 -1
View File
@@ -66,7 +66,12 @@ class Principal(object):
Container for the principal name and realm according to RFC 1510
"""
def __init__(self, components, realm=None):
if isinstance(components, six.string_types):
if isinstance(components, six.binary_type):
raise TypeError(
"Cannot create a principal object from bytes: {!r}".format(
components)
)
elif isinstance(components, six.string_types):
# parse principal components from realm
self.components, self.realm = self._parse_from_text(
components, realm)