Skip to content

Commit

Permalink
Fix encoding-related issues in Name
Browse files Browse the repository at this point in the history
There were a couple of bugs in the decoding logic for parts of
the high-level Name class.  This fixes them.

Fixes #81
  • Loading branch information
DirectXMan12 committed Aug 25, 2015
1 parent 89197da commit 3f45cbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions gssapi/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __str__(self):

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

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

@property
def name_type(self):
Expand Down
16 changes: 16 additions & 0 deletions gssapi/tests/test_high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,22 @@ def test_create_from_token(self):
name2.shouldnt_be_none()
name2.name_type.should_be(gb.NameType.kerberos_principal)

@_extension_test('rfc6680', 'RFC 6680')
def test_display_as(self):
name = gssnames.Name(TARGET_SERVICE_NAME,
gb.NameType.hostbased_service)
canonical_name = name.canonicalize(gb.MechType.kerberos)

# NB(directxman12): krb5 doesn't implement display_name_ext, so just
# check to make sure we return the right types and a reasonable value
krb_name = canonical_name.display_as(
gb.NameType.hostbased_service)

princ_str = SERVICE_PRINCIPAL.decode('utf-8') + '@'
six.text_type(canonical_name).should_be(princ_str)
krb_name.should_be_a(six.text_type)
krb_name.should_be(princ_str)

@_extension_test('rfc6680', 'RFC 6680')
def test_create_from_composite_token_no_attrs(self):
name1 = gssnames.Name(TARGET_SERVICE_NAME,
Expand Down

0 comments on commit 3f45cbe

Please sign in to comment.