Merge "Change ports range in validators and test function"

This commit is contained in:
Jenkins 2015-10-21 08:18:51 +00:00 committed by Gerrit Code Review
commit e62cdfaadb
2 changed files with 12 additions and 13 deletions

View File

@ -195,8 +195,8 @@ class ValidatorsTests(test.TestCase):
self.assertRaises(ValidationError, ip.validate, cidr)
def test_port_validator(self):
VALID_PORTS = (-1, 65535)
INVALID_PORTS = (-2, 65536)
VALID_PORTS = (1, 65535)
INVALID_PORTS = (-1, 0, 65536)
for port in VALID_PORTS:
self.assertIsNone(validators.validate_port_range(port))
@ -207,8 +207,8 @@ class ValidatorsTests(test.TestCase):
port)
def test_ip_proto_validator(self):
VALID_PROTO = (-1, 255)
INVALID_PROTO = (-2, 256)
VALID_PROTO = (0, 255)
INVALID_PROTO = (-1, 256)
for proto in VALID_PROTO:
self.assertIsNone(validators.validate_ip_protocol(proto))
@ -220,9 +220,10 @@ class ValidatorsTests(test.TestCase):
def test_port_range_validator(self):
VALID_RANGE = ('1:65535',
'-1:-1')
'1:1')
INVALID_RANGE = ('22:22:22:22',
'-1:65536')
'1:-1',
'0:65535')
test_call = validators.validate_port_or_colon_separated_port_range
for prange in VALID_RANGE:

View File

@ -14,6 +14,8 @@
import re
from oslo_utils import netutils
from django.core.exceptions import ValidationError # noqa
from django.core import validators # noqa
from django.utils.translation import ugettext_lazy as _
@ -22,12 +24,12 @@ from horizon import conf
def validate_port_range(port):
if port not in range(-1, 65536):
if not netutils.is_valid_port(port):
raise ValidationError(_("Not a valid port number"))
def validate_ip_protocol(ip_proto):
if ip_proto not in range(-1, 256):
if ip_proto not in range(0, 256):
raise ValidationError(_("Not a valid IP protocol number"))
@ -45,11 +47,7 @@ def validate_port_or_colon_separated_port_range(port_range):
raise ValidationError(_("One colon allowed in port range"))
ports = port_range.split(':')
for port in ports:
try:
if int(port) not in range(-1, 65536):
raise ValidationError(_("Not a valid port number"))
except ValueError:
raise ValidationError(_("Port number must be integer"))
validate_port_range(port)
def validate_metadata(value):