From 19186f78402af325bbe4f702976465a9022564e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 28 Jul 2019 22:06:30 +0200 Subject: [PATCH] tests: check importing empty data into ThinVolume Verify if it really discards old content. QubesOS/qubes-issues#5192 --- qubes/tests/storage_lvm.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/qubes/tests/storage_lvm.py b/qubes/tests/storage_lvm.py index 665bbafa..5837395c 100644 --- a/qubes/tests/storage_lvm.py +++ b/qubes/tests/storage_lvm.py @@ -843,6 +843,37 @@ class TC_00_ThinPool(ThinPoolBase): self.loop.run_until_complete(volume.remove()) + def test_034_import_data_empty(self): + config = { + 'name': 'root', + 'pool': self.pool.name, + 'save_on_stop': True, + 'rw': True, + 'size': 1024 * 1024, + } + vm = qubes.tests.storage.TestVM(self) + volume = self.app.get_pool(self.pool.name).init_volume(vm, config) + with unittest.mock.patch('time.time') as mock_time: + mock_time.side_effect = [1521065905] + self.loop.run_until_complete(volume.create()) + p = self.loop.run_until_complete(asyncio.create_subprocess_exec( + 'sudo', 'dd', 'if=/dev/urandom', 'of=' + volume.path, 'count=1', 'bs=1M' + )) + self.loop.run_until_complete(p.wait()) + import_path = self.loop.run_until_complete(volume.import_data()) + self.assertNotEqual(volume.path, import_path) + p = self.loop.run_until_complete(asyncio.create_subprocess_exec( + 'sudo', 'touch', import_path)) + self.loop.run_until_complete(p.wait()) + self.loop.run_until_complete(volume.import_data_end(True)) + self.assertFalse(os.path.exists(import_path), import_path) + p = self.loop.run_until_complete(asyncio.create_subprocess_exec( + 'sudo', 'cat', volume.path, + stdout=subprocess.PIPE + )) + volume_data, _ = self.loop.run_until_complete(p.communicate()) + self.assertEqual(volume_data.strip(b'\0'), b'') + def test_040_volatile(self): '''Volatile volume test''' config = {