def test_config_migration(self): utilities.write_single_setting('CEPH_KEYRING_USER_FSID-WITH-MINUS', 'dummy') self.assertEqual( utilities.read_single_setting('CEPH_KEYRING_USER_FSID-WITH-MINUS'), 'dummy') utilities.write_single_setting('CEPH_KEYRING_USER_FSID_WITH_MINUS', '') obj = mock.Mock() ceph.librados._read_oa_settings( ConfigObj(ceph.librados.oa_settings.settings_file), obj) self.assertNotIn('CEPH_KEYRING_USER_FSID-WITH-MINUS', obj.__dict__) self.assertEqual(obj.CEPH_KEYRING_USER_FSID_WITH_MINUS, 'dummy') self.assertEqual( utilities.read_single_setting('CEPH_KEYRING_USER_FSID-WITH-MINUS'), 'dummy') ceph.librados._write_oa_setting('CEPH_KEYRING_USER_FSID_WITH_MINUS', 'dummy2') with self.assertRaises(KeyError): utilities.read_single_setting('CEPH_KEYRING_USER_FSID-WITH-MINUS') self.assertEqual( utilities.read_single_setting('CEPH_KEYRING_USER_FSID_WITH_MINUS'), 'dummy2')
def write_secret_to_config(secret): import dbus try: write_single_setting('DJANGO_SECRET', secret, set_in_django_settings=False) secret_file_name = join(PROJECT_ROOT, '.secret.txt') try: os.remove(secret_file_name) except OSError as e: logging.info('failed to delete {}: {}'.format(secret_file_name, str(e))) except dbus.DBusException: logging.exception('Failed to write secret key. Ignoring')
def test_new_secret(self): utilities.write_single_setting('DJANGO_SECRET', '') if exists(SettingsTest.secret_file_path): os.remove(SettingsTest.secret_file_path) secret_1, should_write_1 = settings.read_secret_from_config() self.assertTrue(should_write_1) settings.write_secret_to_config(secret_1) secret_2, should_write_2 = settings.read_secret_from_config() self.assertEqual(secret_1, secret_2) self.assertFalse(should_write_2) self.assertEqual(utilities.read_single_setting('DJANGO_SECRET'), secret_2)
def test_secret_migration_read(self): with open(SettingsTest.secret_file_path, 'w') as f: f.write('mysecret') utilities.write_single_setting('DJANGO_SECRET', '') secret, should_write_secret = settings.read_secret_from_config() self.assertTrue(should_write_secret) self.assertEqual(secret, 'mysecret') settings.write_secret_to_config('mysecret') self.assertEqual(utilities.read_single_setting('DJANGO_SECRET'), 'mysecret') self.assertFalse(exists(SettingsTest.secret_file_path))