/usr/lib/python2.7/dist-packages/keyring/tests/backends/test_pyfs.py is in python-keyring 7.3-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | from __future__ import unicode_literals
import os
import tempfile
import textwrap
import unittest
import keyring.backend
from keyring.backends import pyfs
from ..test_backend import BackendBasicTests, random_string
class ReverseCrypter(keyring.backend.Crypter):
"""Very silly crypter class"""
def encrypt(self, value):
return value[::-1]
def decrypt(self, value):
return value[::-1]
class PyfilesystemKeyringTests(BackendBasicTests):
"""Base class for Pyfilesystem tests"""
def setUp(self):
super(PyfilesystemKeyringTests, self).setUp()
self.keyring = self.init_keyring()
def tearDown(self):
del self.keyring
def test_encrypt_decrypt(self):
password = random_string(20)
encrypted = self.keyring.encrypt(password)
self.assertEqual(password, self.keyring.decrypt(encrypted))
@unittest.skipUnless(pyfs.BasicKeyring.viable, "Need Pyfilesystem")
class UnencryptedMemoryPyfilesystemKeyringNoSubDirTestCase(
PyfilesystemKeyringTests, unittest.TestCase):
"""Test in memory with no encryption"""
keyring_filename = 'mem://unencrypted'
def init_keyring(self):
return keyring.backends.pyfs.PlaintextKeyring(
filename=self.keyring_filename)
@unittest.skipUnless(pyfs.BasicKeyring.viable, "Need Pyfilesystem")
class UnencryptedMemoryPyfilesystemKeyringSubDirTestCase(
PyfilesystemKeyringTests, unittest.TestCase):
"""Test in memory with no encryption"""
keyring_filename = 'mem://some/sub/dir/unencrypted'
def init_keyring(self):
return keyring.backends.pyfs.PlaintextKeyring(
filename=self.keyring_filename)
@unittest.skipUnless(pyfs.BasicKeyring.viable, "Need Pyfilesystem")
class UnencryptedLocalPyfilesystemKeyringNoSubDirTestCase(
PyfilesystemKeyringTests, unittest.TestCase):
"""Test using local temp files with no encryption"""
keyring_filename = '%s/keyring.cfg' %tempfile.mkdtemp()
def init_keyring(self):
return keyring.backends.pyfs.PlaintextKeyring(
filename=self.keyring_filename)
def test_handles_preexisting_keyring(self):
from fs.opener import opener
fs, path = opener.parse(self.keyring_filename, writeable=True)
keyring_file = fs.open(path, 'w')
file_data = textwrap.dedent("""
[svc1]
user1 = cHdkMQ==
""").lstrip()
keyring_file.write(file_data)
keyring_file.close()
pyf_keyring = keyring.backends.pyfs.PlaintextKeyring(
filename=self.keyring_filename)
self.assertEquals('pwd1', pyf_keyring.get_password('svc1', 'user1'))
def tearDown(self):
del self.keyring
if os.path.exists(self.keyring_filename):
os.remove(self.keyring_filename)
@unittest.skipUnless(pyfs.BasicKeyring.viable, "Need Pyfilesystem")
class UnencryptedLocalPyfilesystemKeyringSubDirTestCase(
PyfilesystemKeyringTests, unittest.TestCase):
"""Test using local temp files with no encryption"""
keyring_dir = os.path.join(tempfile.mkdtemp(), 'more', 'sub', 'dirs')
keyring_filename = os.path.join(keyring_dir, 'keyring.cfg')
def init_keyring(self):
if not os.path.exists(self.keyring_dir):
os.makedirs(self.keyring_dir)
return keyring.backends.pyfs.PlaintextKeyring(
filename=self.keyring_filename)
@unittest.skipUnless(pyfs.BasicKeyring.viable, "Need Pyfilesystem")
class EncryptedMemoryPyfilesystemKeyringTestCase(PyfilesystemKeyringTests,
unittest.TestCase):
"""Test in memory with encryption"""
def init_keyring(self):
return keyring.backends.pyfs.EncryptedKeyring(
ReverseCrypter(),
filename='mem://encrypted/keyring.cfg')
@unittest.skipUnless(pyfs.BasicKeyring.viable, "Need Pyfilesystem")
class EncryptedLocalPyfilesystemKeyringNoSubDirTestCase(
PyfilesystemKeyringTests, unittest.TestCase):
"""Test using local temp files with encryption"""
def init_keyring(self):
return keyring.backends.pyfs.EncryptedKeyring(
ReverseCrypter(),
filename='temp://keyring.cfg')
@unittest.skipUnless(pyfs.BasicKeyring.viable, "Need Pyfilesystem")
class EncryptedLocalPyfilesystemKeyringSubDirTestCase(
PyfilesystemKeyringTests, unittest.TestCase):
"""Test using local temp files with encryption"""
def init_keyring(self):
return keyring.backends.pyfs.EncryptedKeyring(
ReverseCrypter(),
filename='temp://a/sub/dir/hierarchy/keyring.cfg')
|