]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not accept abbreviated CIDRs
authorSean M. Collins <sean@coreitpro.com>
Tue, 1 Sep 2015 08:43:30 +0000 (04:43 -0400)
committerSean M. Collins <sean@coreitpro.com>
Thu, 15 Oct 2015 22:38:19 +0000 (18:38 -0400)
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
neutron/tests/unit/api/v2/test_attributes.py

index 56beac9f459e7c5bead7660baa91532b698fcd81..6b35774272a969bfe60e1737340445c8a55ce4b0 100644 (file)
@@ -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}
index df20fe14aed96f4c7bff5fc0a6e660564181f3c5..4c4a95d1b93504182cd0d79658ba9fb4e408989a 100644 (file)
@@ -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"