Skip to content

Commit 3f45cbe

Browse files
committed
Fix encoding-related issues in Name
There were a couple of bugs in the decoding logic for parts of the high-level Name class. This fixes them. Fixes #81
1 parent 89197da commit 3f45cbe

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

gssapi/names.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __str__(self):
112112

113113
def __unicode__(self):
114114
# Python 2 -- someone asked for unicode
115-
return self.__bytes__().encode(_utils._get_encoding())
115+
return self.__bytes__().decode(_utils._get_encoding())
116116

117117
def __bytes__(self):
118118
# Python 3 -- someone asked for bytes
@@ -142,8 +142,8 @@ def display_as(self, name_type):
142142
raise NotImplementedError("Your GSSAPI implementation does not "
143143
"support RFC 6680 (the GSSAPI naming "
144144
"extensions)")
145-
return rname_rfc6680.display_name_ext(self, name_type).encode(
146-
_utils.get_encoding())
145+
return rname_rfc6680.display_name_ext(self, name_type).decode(
146+
_utils._get_encoding())
147147

148148
@property
149149
def name_type(self):

gssapi/tests/test_high_level.py

+16
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,22 @@ def test_create_from_token(self):
396396
name2.shouldnt_be_none()
397397
name2.name_type.should_be(gb.NameType.kerberos_principal)
398398

399+
@_extension_test('rfc6680', 'RFC 6680')
400+
def test_display_as(self):
401+
name = gssnames.Name(TARGET_SERVICE_NAME,
402+
gb.NameType.hostbased_service)
403+
canonical_name = name.canonicalize(gb.MechType.kerberos)
404+
405+
# NB(directxman12): krb5 doesn't implement display_name_ext, so just
406+
# check to make sure we return the right types and a reasonable value
407+
krb_name = canonical_name.display_as(
408+
gb.NameType.hostbased_service)
409+
410+
princ_str = SERVICE_PRINCIPAL.decode('utf-8') + '@'
411+
six.text_type(canonical_name).should_be(princ_str)
412+
krb_name.should_be_a(six.text_type)
413+
krb_name.should_be(princ_str)
414+
399415
@_extension_test('rfc6680', 'RFC 6680')
400416
def test_create_from_composite_token_no_attrs(self):
401417
name1 = gssnames.Name(TARGET_SERVICE_NAME,

0 commit comments

Comments
 (0)