From dfb28f07a6770126283430d6dd828b6913ee7926 Mon Sep 17 00:00:00 2001 From: Abhidnya Patil Date: Fri, 24 Apr 2020 13:27:33 -0700 Subject: [PATCH 1/4] Changing test skip condition --- tests/test_persistence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 0ec369b..f7f155a 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -30,7 +30,7 @@ def test_file_persistence(temp_location): _test_persistence_roundtrip(FilePersistence(temp_location)) @pytest.mark.skipif( - is_running_on_travis_ci or not sys.platform.startswith('win'), + not sys.platform.startswith('win'), reason="Requires Windows Desktop") def test_file_persistence_with_data_protection(temp_location): _test_persistence_roundtrip(FilePersistenceWithDataProtection(temp_location)) From 266c058e058b9f750957ca4b1ce02e7f11cbb64f Mon Sep 17 00:00:00 2001 From: Abhidnya Patil Date: Fri, 24 Apr 2020 15:24:25 -0700 Subject: [PATCH 2/4] Opening file in byte mode --- msal_extensions/persistence.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/msal_extensions/persistence.py b/msal_extensions/persistence.py index 2ddf432..b73be81 100644 --- a/msal_extensions/persistence.py +++ b/msal_extensions/persistence.py @@ -9,12 +9,12 @@ import abc import os import errno + try: from pathlib import Path # Built-in in Python 3 except: from pathlib2 import Path # An extra lib for Python 2 - try: ABC = abc.ABC except AttributeError: # Python 2.7, abc exists, but not ABC @@ -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()) class KeychainPersistence(BasePersistence): From faf6136d95800618ebf9f2ac3c0011b33f18d9f4 Mon Sep 17 00:00:00 2001 From: Abhidnya Patil Date: Fri, 24 Apr 2020 15:50:21 -0700 Subject: [PATCH 3/4] Disabling test related to dpapi --- msal_extensions/persistence.py | 2 +- tests/test_persistence.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/msal_extensions/persistence.py b/msal_extensions/persistence.py index b73be81..3351eb1 100644 --- a/msal_extensions/persistence.py +++ b/msal_extensions/persistence.py @@ -9,12 +9,12 @@ import abc import os import errno - try: from pathlib import Path # Built-in in Python 3 except: from pathlib2 import Path # An extra lib for Python 2 + try: ABC = abc.ABC except AttributeError: # Python 2.7, abc exists, but not ABC diff --git a/tests/test_persistence.py b/tests/test_persistence.py index f7f155a..0ec369b 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -30,7 +30,7 @@ def test_file_persistence(temp_location): _test_persistence_roundtrip(FilePersistence(temp_location)) @pytest.mark.skipif( - not sys.platform.startswith('win'), + is_running_on_travis_ci or not sys.platform.startswith('win'), reason="Requires Windows Desktop") def test_file_persistence_with_data_protection(temp_location): _test_persistence_roundtrip(FilePersistenceWithDataProtection(temp_location)) From 2f5e9bc763976419c728c908c5f9cf191d4966d7 Mon Sep 17 00:00:00 2001 From: Abhidnya Patil Date: Fri, 24 Apr 2020 18:39:15 -0700 Subject: [PATCH 4/4] Adding type hints --- msal_extensions/persistence.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/msal_extensions/persistence.py b/msal_extensions/persistence.py index 3351eb1..ef27d55 100644 --- a/msal_extensions/persistence.py +++ b/msal_extensions/persistence.py @@ -114,13 +114,14 @@ def __init__(self, location, entropy=''): super(FilePersistenceWithDataProtection, self).__init__(location) def save(self, content): + # type: (str) -> None with open(self._location, 'wb+') as handle: handle.write(self._dp_agent.protect(content)) def load(self): + # type: () -> str with open(self._location, 'rb') as handle: - return self._dp_agent.unprotect( - handle.read()) + return self._dp_agent.unprotect(handle.read()) class KeychainPersistence(BasePersistence):