From b50658608934629c2dde417e7b7f2b885553e496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Thu, 13 Aug 2020 19:16:52 +0200 Subject: [PATCH] Fixed grey label color value causing accidental green icons fixes QubesOS/qubes-issues#3471 --- qubes/app.py | 14 +++++++++++++- qubes/tests/app.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/qubes/app.py b/qubes/app.py index d2197fb5..f22037d1 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -981,6 +981,16 @@ class Qubes(qubes.PropertyHolder): pass node_default_fw_netvm.getparent().remove(node_default_fw_netvm) + def _migrate_labels(self): + """Migrate changed labels""" + if self.xml is None: + return + + # fix grey being green + grey_label = self.xml.find('./labels/label[@color=\'0x555753\']') + if grey_label is not None: + grey_label.set('color', '0x555555') + def load(self, lock=False): """Open qubes.xml @@ -992,6 +1002,8 @@ class Qubes(qubes.PropertyHolder): fh = self._acquire_lock() self.xml = lxml.etree.parse(fh) + self._migrate_labels() + # stage 1: load labels and pools for node in self.xml.xpath('./labels/label'): label = qubes.Label.fromxml(node) @@ -1211,7 +1223,7 @@ class Qubes(qubes.PropertyHolder): 2: qubes.Label(2, '0xf57900', 'orange'), 3: qubes.Label(3, '0xedd400', 'yellow'), 4: qubes.Label(4, '0x73d216', 'green'), - 5: qubes.Label(5, '0x555753', 'gray'), + 5: qubes.Label(5, '0x555555', 'gray'), 6: qubes.Label(6, '0x3465a4', 'blue'), 7: qubes.Label(7, '0x75507b', 'purple'), 8: qubes.Label(8, '0x000000', 'black'), diff --git a/qubes/tests/app.py b/qubes/tests/app.py index a9c47ce0..5463eb94 100644 --- a/qubes/tests/app.py +++ b/qubes/tests/app.py @@ -508,6 +508,49 @@ class TC_89_QubesEmpty(qubes.tests.QubesTestCase): self.app.close() del self.app + def test_101_property_migrate_label(self): + xml_template = """ + + + + + + + + + + + 1 + sys-net + True + + + 2fcfc1f4-b2fe-4361-931a-c5294b35edfa + + + + + + + """ + with self.subTest('replace_label'): + with open('/tmp/qubestest.xml', 'w') as xml_file: + xml_file.write(xml_template.format(old_gray='0x555753')) + self.app = qubes.Qubes('/tmp/qubestest.xml', offline_mode=True) + self.assertEqual( + self.app.get_label('gray').color, '0x555555') + self.app.close() + del self.app + + with self.subTest('dont_replace_label'): + with open('/tmp/qubestest.xml', 'w') as xml_file: + xml_file.write(xml_template.format(old_gray='0x123456')) + self.app = qubes.Qubes('/tmp/qubestest.xml', offline_mode=True) + self.assertEqual( + self.app.get_label('gray').color, '0x123456') + self.app.close() + del self.app + class TC_90_Qubes(qubes.tests.QubesTestCase): def tearDown(self):