From e8a92e0b9dd1ecc7887eced522578258e69e9ff3 Mon Sep 17 00:00:00 2001 From: "Sean M. Collins" Date: Tue, 1 Sep 2015 04:43:30 -0400 Subject: [PATCH] Do not accept abbreviated CIDRs This is a special netaddr behavior that we wish to prevent. http://lists.openstack.org/pipermail/openstack-dev/2015-August/072610.html APIImpact Change-Id: I94a059cee396e183bffd4a064709bb83504bf983 Closes-Bug: #1490885 --- neutron/api/v2/attributes.py | 2 +- neutron/tests/unit/api/v2/test_attributes.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/neutron/api/v2/attributes.py b/neutron/api/v2/attributes.py index 56beac9f4..6b3577427 100644 --- a/neutron/api/v2/attributes.py +++ b/neutron/api/v2/attributes.py @@ -320,7 +320,7 @@ def _validate_subnet(data, valid_values=None): msg = None try: net = netaddr.IPNetwork(_validate_no_whitespace(data)) - if '/' not in data: + if '/' not in data or (net.version == 4 and str(net) != data): msg = _("'%(data)s' isn't a recognized IP subnet cidr," " '%(cidr)s' is recommended") % {"data": data, "cidr": net.cidr} diff --git a/neutron/tests/unit/api/v2/test_attributes.py b/neutron/tests/unit/api/v2/test_attributes.py index df20fe14a..4c4a95d1b 100644 --- a/neutron/tests/unit/api/v2/test_attributes.py +++ b/neutron/tests/unit/api/v2/test_attributes.py @@ -496,10 +496,13 @@ class TestAttributes(base.BaseTestCase): msg = validator(cidr, None) self.assertIsNone(msg) - # Valid - abbreviated ipv4 address + # Invalid - abbreviated ipv4 address cidr = "10/24" msg = validator(cidr, None) - self.assertIsNone(msg) + error = _("'%(data)s' isn't a recognized IP subnet cidr," + " '%(cidr)s' is recommended") % {"data": cidr, + "cidr": "10.0.0.0/24"} + self.assertEqual(error, msg) # Invalid - IPv4 missing mask cidr = "10.0.2.0" -- 2.45.2