From 214c64641777bd807437e0fb891a7b4a4bce7eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 25 Jul 2017 14:19:29 +0200 Subject: [PATCH] firewall: raise ValueError on invalid hostname in dsthost= ...instead of AssertionError --- qubes/firewall.py | 3 ++- qubes/tests/firewall.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qubes/firewall.py b/qubes/firewall.py index a9d195e8..86397802 100644 --- a/qubes/firewall.py +++ b/qubes/firewall.py @@ -123,7 +123,8 @@ class DstHost(RuleOption): self.type = 'dsthost' self.prefixlen = 0 safe_set = string.ascii_lowercase + string.digits + '-._' - assert all(c in safe_set for c in untrusted_value) + if not all(c in safe_set for c in untrusted_value): + raise ValueError('Invalid hostname') value = untrusted_value else: untrusted_host, untrusted_prefixlen = untrusted_value.split('/', 1) diff --git a/qubes/tests/firewall.py b/qubes/tests/firewall.py index f4594d45..f70bbef3 100644 --- a/qubes/tests/firewall.py +++ b/qubes/tests/firewall.py @@ -202,7 +202,6 @@ class TC_02_DstHost(qubes.tests.QubesTestCase): with self.assertRaises(ValueError): qubes.firewall.DstHost('2001:abcd:efab::3/64') - @unittest.expectedFailure def test_020_invalid_hostname(self): with self.assertRaises(ValueError): qubes.firewall.DstHost('www qubes-os.org')