From 0f3bef9da71696cd25144eaebd137a30e796d6cf Mon Sep 17 00:00:00 2001 From: Ben Grande Date: Fri, 7 Jun 2024 11:11:59 +0200 Subject: [PATCH] Add os-release ID_LIKE to features For: https://github.com/QubesOS/qubes-core-agent-linux/pull/504 --- qubes/ext/core_features.py | 5 +++++ qubes/tests/ext.py | 7 +++++++ qubes/tests/integ/basic.py | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/qubes/ext/core_features.py b/qubes/ext/core_features.py index a728e21f2..622c3091d 100644 --- a/qubes/ext/core_features.py +++ b/qubes/ext/core_features.py @@ -41,6 +41,11 @@ async def qubes_features_request(self, vm, event, untrusted_features): # entry point already validates values for safe characters vm.features["os-distribution"] = \ untrusted_features["os-distribution"] + if "os-distribution-like" in untrusted_features \ + and untrusted_features["os-distribution-like"]: + # entry point already validates values for safe characters + vm.features["os-distribution-like"] = \ + untrusted_features["os-distribution-like"] if "os-version" in untrusted_features \ and untrusted_features["os-version"]: # no letters in versions please diff --git a/qubes/tests/ext.py b/qubes/tests/ext.py index 49c37df63..0efe8e1cc 100644 --- a/qubes/tests/ext.py +++ b/qubes/tests/ext.py @@ -267,11 +267,13 @@ def test_031_distro_meta_ubuntu(self): untrusted_features={ 'os': 'Linux', 'os-distribution': 'ubuntu', + 'os-distribution-like': 'debian', 'os-version': '22.04', 'os-eol': '2027-06-01', })) self.assertListEqual(self.vm.mock_calls, [ ('features.__setitem__', ('os-distribution', 'ubuntu'), {}), + ('features.__setitem__', ('os-distribution-like', 'debian'), {}), ('features.__setitem__', ('os-version', '22.04'), {}), ('features.__setitem__', ('os-eol', '2027-06-01'), {}), ('features.get', ('qrexec', False), {}), @@ -285,11 +287,13 @@ def test_032_distro_meta_invalid(self): untrusted_features={ 'os': 'Linux', 'os-distribution': 'ubuntu', + 'os-distribution-like': 'debian', 'os-version': '123aaa', 'os-eol': '20270601', })) self.assertListEqual(self.vm.mock_calls, [ ('features.__setitem__', ('os-distribution', 'ubuntu'), {}), + ('features.__setitem__', ('os-distribution-like', 'debian'), {}), ('log.warning', unittest.mock.ANY, {}), ('log.warning', unittest.mock.ANY, {}), ('features.get', ('qrexec', False), {}), @@ -303,11 +307,13 @@ def test_033_distro_meta_invalid2(self): untrusted_features={ 'os': 'Linux', 'os-distribution': 'ubuntu', + 'os-distribution-like': 'debian', 'os-version': 'a123', 'os-eol': '2027-06-40', })) self.assertListEqual(self.vm.mock_calls, [ ('features.__setitem__', ('os-distribution', 'ubuntu'), {}), + ('features.__setitem__', ('os-distribution-like', 'debian'), {}), ('log.warning', unittest.mock.ANY, {}), ('log.warning', unittest.mock.ANY, {}), ('features.get', ('qrexec', False), {}), @@ -321,6 +327,7 @@ def test_034_distro_meta_empty(self): untrusted_features={ 'os': '', 'os-distribution': '', + 'os-distribution-like': '', 'os-version': '', 'os-eol': '', })) diff --git a/qubes/tests/integ/basic.py b/qubes/tests/integ/basic.py index 0115be87a..47517267f 100644 --- a/qubes/tests/integ/basic.py +++ b/qubes/tests/integ/basic.py @@ -623,8 +623,12 @@ def test_010_os_metadata(self): self.assertIsNotNone(tpl.features.get('os-eol')) elif self.template.startswith('whonix-'): self.assertEqual(tpl.features.get('os-distribution'), 'whonix') + self.assertEqual(tpl.features.get('os-distribution-like'), 'debian') version = self.template.split('-')[2] self.assertEqual(tpl.features.get('os-version'), version) + elif self.template.startswith('kali-core'): + self.assertEqual(tpl.features.get('os-distribution'), 'kali') + self.assertEqual(tpl.features.get('os-distribution-like'), 'debian') @unittest.skipUnless( spawn.find_executable('xdotool'), "xdotool not installed")