Skip to content

Commit

Permalink
Merge pull request #22 from PressLabs/fix-unicode-hasing-errors
Browse files Browse the repository at this point in the history
Encode keys before hashing them.
  • Loading branch information
bogdanpetrea committed Oct 13, 2017
2 parents 491aaed + ba53036 commit 1844454
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pyolite/models/lists/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def append(self, key):
with open(str(key_path)) as f:
key = f.read()

if not isinstance(key, bytes):
key = key.encode('utf-8')

if key in self:
return

Expand All @@ -26,14 +29,17 @@ def append(self, key):
if key_file.exists() and key_file.read_file() == key:
return

key_file.write_file(str(key))
key_file.write_file(key, mode='wb')

self.user.git.commit(['keydir'],
'Added new key for user %s' % self.user.name)

super(ListKeys, self).append(key)

def remove(self, key):
if not isinstance(key, bytes):
key = key.encode('utf-8')

directory = Path(self.user.path, 'keydir', self.user.name,
hashlib.md5(key.strip().split()[1]).hexdigest())
key_file = Path(directory, "%s.pub" % self.user.name)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'six==1.6.1', 'spec==0.11.1']

setup(name="pyolite",
version='1.5.8',
version='1.5.9',
platforms='any',
packages=find_packages(),
include_package_data=True,
Expand Down
2 changes: 1 addition & 1 deletion tests/lists/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_if_we_commit_after_a_key_append():
assert mock_file.isfile.call_count == 1
assert mock_file.mkdir.call_count == 1

mock_file.write_file.assert_called_once_with('nothing to see here\n')
mock_file.write_file.assert_called_once_with(b'nothing to see here\n', mode='wb')


def test_list_addition():
Expand Down

0 comments on commit 1844454

Please sign in to comment.