/usr/lib/python2.7/dist-packages/keyring/tests/backends/test_file.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 | import os
import tempfile
import sys
import errno
import unittest
from ..test_backend import BackendBasicTests
from ..util import random_string
from keyring.backends import file
class FileKeyringTests(BackendBasicTests):
def setUp(self):
super(FileKeyringTests, self).setUp()
self.keyring = self.init_keyring()
self.keyring.file_path = self.tmp_keyring_file = tempfile.mktemp()
def tearDown(self):
try:
os.unlink(self.tmp_keyring_file)
except (OSError,):
e = sys.exc_info()[1]
if e.errno != errno.ENOENT: # No such file or directory
raise
def test_encrypt_decrypt(self):
password = random_string(20)
# keyring.encrypt expects bytes
password = password.encode('utf-8')
encrypted = self.keyring.encrypt(password)
self.assertEqual(password, self.keyring.decrypt(encrypted))
class UncryptedFileKeyringTestCase(FileKeyringTests, unittest.TestCase):
def init_keyring(self):
return file.PlaintextKeyring()
@unittest.skipIf(sys.platform == 'win32',
"Group/World permissions aren't meaningful on Windows")
def test_keyring_not_created_world_writable(self):
"""
Ensure that when keyring creates the file that it's not overly-
permissive.
"""
self.keyring.set_password('system', 'user', 'password')
self.assertTrue(os.path.exists(self.keyring.file_path))
group_other_perms = os.stat(self.keyring.file_path).st_mode & 0o077
self.assertEqual(group_other_perms, 0)
|