Skip to content

Commit

Permalink
Merge pull request #111 from mboutolleau/master
Browse files Browse the repository at this point in the history
Ensure that only bytes are written to the cache
  • Loading branch information
jaqx0r authored Dec 17, 2020
2 parents ce5ed08 + 12ec763 commit c2da65b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions nss_cache/caches/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _WriteData(self, target, entry):
Number of bytes written to the target.
"""
sshkey_entry = '%s:%s' % (entry.name, entry.sshkey)
target.write(sshkey_entry + '\n')
target.write(sshkey_entry.encode() + b'\n')
return len(sshkey_entry) + 1


Expand Down Expand Up @@ -459,7 +459,7 @@ def _WriteData(self, target, entry):
netgroup_entry = '%s %s' % (entry.name, entry.entries)
else:
netgroup_entry = entry.name
target.write(netgroup_entry + '\n')
target.write(netgroup_entry.encode() + b'\n')
return len(netgroup_entry) + 1


Expand Down Expand Up @@ -510,7 +510,7 @@ def _WriteData(self, target, entry):
entry.location)
else:
automount_entry = '%s %s' % (entry.key, entry.location)
target.write(automount_entry + '\n')
target.write(automount_entry.encode() + b'\n')
return len(automount_entry) + 1

def GetMapLocation(self):
Expand Down
6 changes: 3 additions & 3 deletions nss_cache/caches/files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def testWriteNetgroupEntry(self):
cache = files.FilesNetgroupMapHandler(self.config)
file_mock = self.mox.CreateMock(sys.stdout)
file_mock.write(
'administrators unix_admins noc_monkeys (-,zero_cool,)\n')
b'administrators unix_admins noc_monkeys (-,zero_cool,)\n')

map_entry = netgroup.NetgroupMapEntry()
map_entry.name = 'administrators'
Expand All @@ -143,7 +143,7 @@ def testWriteAutomountEntry(self):
"""We correctly write a typical entry in /etc/auto.* format."""
cache = files.FilesAutomountMapHandler(self.config)
file_mock = self.mox.CreateMock(sys.stdout)
file_mock.write('scratch -tcp,rw,intr,bg fileserver:/scratch\n')
file_mock.write(b'scratch -tcp,rw,intr,bg fileserver:/scratch\n')

map_entry = automount.AutomountMapEntry()
map_entry.key = 'scratch'
Expand All @@ -155,7 +155,7 @@ def testWriteAutomountEntry(self):
self.mox.VerifyAll()

file_mock = self.mox.CreateMock(sys.stdout)
file_mock.write('scratch fileserver:/scratch\n')
file_mock.write(b'scratch fileserver:/scratch\n')

map_entry = automount.AutomountMapEntry()
map_entry.key = 'scratch'
Expand Down

0 comments on commit c2da65b

Please sign in to comment.