Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions msal_extensions/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ def __init__(self, location, entropy=''):
super(FilePersistenceWithDataProtection, self).__init__(location)

def save(self, content):
super(FilePersistenceWithDataProtection, self).save(
self._dp_agent.protect(content))
with open(self._location, 'wb+') as handle:
handle.write(self._dp_agent.protect(content))

def load(self):
return self._dp_agent.unprotect(
super(FilePersistenceWithDataProtection, self).load())
with open(self._location, 'rb') as handle:
return self._dp_agent.unprotect(
handle.read())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with open(self._location, 'rb') as handle:
return self._dp_agent.unprotect(
handle.read())
# type: () -> str
with open(self._location, 'rb') as handle:
return self._dp_agent.unprotect(handle.read())

Given that we are getting into the nasty difference of string and bytes anyway, let's also include a type hint here. Same suggestion for save() too. In the near future (but not in this PR), we will pick up another task for documentation, and describe this in details there.

Also, since this is not automated, please manually test this test case and that sample, on both Python 2.7 and one version of Python 3, we need to see all pass in such 2x2 matrix. Please ack.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually tested the test case and the sample on Python 2.7 and 3.7 and it works fine



class KeychainPersistence(BasePersistence):
Expand Down