summaryrefslogtreecommitdiff
path: root/tests/glibext
diff options
context:
space:
mode:
Diffstat (limited to 'tests/glibext')
-rw-r--r--tests/glibext/secstorage.py26
-rw-r--r--tests/glibext/storage.py74
2 files changed, 92 insertions, 8 deletions
diff --git a/tests/glibext/secstorage.py b/tests/glibext/secstorage.py
index 248b3e3..5b8f680 100644
--- a/tests/glibext/secstorage.py
+++ b/tests/glibext/secstorage.py
@@ -22,8 +22,6 @@ class TestSecretStorage(ChrysalideTestCase):
subprocess.run([ 'glib-compile-schemas', path ])
- os.environ['GSETTINGS_SCHEMA_DIR'] = path + ':' + os.environ['GSETTINGS_SCHEMA_DIR']
-
@classmethod
def tearDownClass(cls):
@@ -32,8 +30,6 @@ class TestSecretStorage(ChrysalideTestCase):
cls.log('Removing compiled GSettings schema...')
- os.environ['GSETTINGS_SCHEMA_DIR'] = ':'.join(os.environ['GSETTINGS_SCHEMA_DIR'].split(':')[1:])
-
path = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(path, 'gschemas.compiled')
@@ -42,10 +38,24 @@ class TestSecretStorage(ChrysalideTestCase):
os.remove(filename)
+ def _get_settings(self, sid):
+ """Provide local GSettings instance."""
+
+ path = os.path.dirname(os.path.realpath(__file__))
+
+ source = Gio.SettingsSchemaSource.new_from_directory(path, None, True)
+
+ schema = Gio.SettingsSchemaSource.lookup(source, sid, False)
+
+ settings = Gio.Settings.new_full(schema, None, None)
+
+ return settings
+
+
def testMasterKeyDefinition(self):
"""Check for cryptographic parameters for secret storage."""
- settings = Gio.Settings.new('re.chrysalide.tests.secstorage')
+ settings = self._get_settings('re.chrysalide.tests.secstorage')
storage = SecretStorage(settings)
@@ -67,7 +77,7 @@ class TestSecretStorage(ChrysalideTestCase):
def testMasterKeyCreation(self):
"""Create and update cryptographic parameters for secret storage."""
- settings = Gio.Settings.new('re.chrysalide.tests.secstorage')
+ settings = self._get_settings('re.chrysalide.tests.secstorage')
storage = SecretStorage(settings)
@@ -101,9 +111,9 @@ class TestSecretStorage(ChrysalideTestCase):
def testDataEncryption(self):
- """Create and update cryptographic parameters for secret storage."""
+ """Encrypt and decrypt data with the secret storage."""
- settings = Gio.Settings.new('re.chrysalide.tests.secstorage')
+ settings = self._get_settings('re.chrysalide.tests.secstorage')
storage = SecretStorage(settings)
diff --git a/tests/glibext/storage.py b/tests/glibext/storage.py
new file mode 100644
index 0000000..b60377a
--- /dev/null
+++ b/tests/glibext/storage.py
@@ -0,0 +1,74 @@
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.glibext import ObjectStorage, SerializableObject
+import gi
+import os
+import tempfile
+
+
+class TestObjectStorage(ChrysalideTestCase):
+ """TestCase for analysis.storage."""
+
+ @classmethod
+ def setUpClass(cls):
+
+ super(TestObjectStorage, cls).setUpClass()
+
+ _, cls._tmp_filename = tempfile.mkstemp()
+
+ cls.log('Using temporary filename "%s"' % cls._tmp_filename)
+
+
+ @classmethod
+ def tearDownClass(cls):
+
+ super(TestObjectStorage, cls).tearDownClass()
+
+ cls.log('Delete filename "%s"' % cls._tmp_filename)
+
+ os.unlink(cls._tmp_filename)
+
+
+ def testGenericStorage(self):
+ """Store and load basic objects."""
+
+
+ class SimpleObject(gi._gi.GObject, SerializableObject):
+
+ def __init__(self, b=None):
+ super().__init__()
+ self._b = b
+
+ def _load(self, storage, fd):
+ assert(self._b is None)
+ self._b = os.read(fd, 1)[0]
+ return True
+
+ def _store(self, storage, fd):
+ os.write(fd, bytes([ self._b ]))
+ return True
+
+ def __eq__(self, other):
+ return self._b == other._b
+
+
+ # Store
+
+ storage = ObjectStorage('TestStorage', 0, 'my-storage-hash')
+ self.assertIsNotNone(storage)
+
+ so = SimpleObject(0x23)
+
+ pos = storage.store_object('simple', so)
+ self.assertIsNotNone(pos)
+
+ status = storage.store(self._tmp_filename)
+ self.assertTrue(status)
+
+ # Reload
+
+ storage2 = ObjectStorage.load(self._tmp_filename)
+
+ so2 = storage2.load_object('simple', pos)
+
+ self.assertEqual(so, so2)