firewall: raise ValueError on invalid hostname in dsthost=

...instead of AssertionError
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-25 14:19:29 +02:00
parent 625c94d1f6
commit 214c646417
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 2 additions and 2 deletions

View File

@ -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)

View File

@ -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')