1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
from __future__ import print_function
import sys
import unittest
from keyrings.alt import Windows
from keyring.tests.test_backend import BackendBasicTests
from .test_file import FileKeyringTests
def is_win32_crypto_supported():
try:
__import__('keyrings.alt._win_crypto')
except ImportError:
return False
return sys.platform in ['win32'] and sys.getwindowsversion()[-2] == 2
def is_winvault_supported():
try:
__import__('win32cred')
has_pywin32 = True
except ImportError:
has_pywin32 = False
return (
sys.platform in ['win32'] and sys.getwindowsversion().major >= 6
and has_pywin32
)
@unittest.skipUnless(is_win32_crypto_supported(),
"Need Windows")
class Win32CryptoKeyringTestCase(FileKeyringTests, unittest.TestCase):
def init_keyring(self):
return Windows.EncryptedKeyring()
@unittest.skipUnless(Windows.RegistryKeyring.viable
and sys.version_info > (3,), "RegistryKeyring not viable")
class RegistryKeyringTestCase(BackendBasicTests, unittest.TestCase):
def tearDown(self):
# clean up any credentials created
for cred in self.credentials_created:
try:
self.keyring.delete_password(*cred)
except Exception as e:
print(e, file=sys.stderr)
def init_keyring(self):
return Windows.RegistryKeyring()
|