From 9598077a85568b5771e331e637d363f0463646c6 Mon Sep 17 00:00:00 2001 From: Dariusz Smigiel Date: Wed, 8 Jun 2016 11:07:49 -0500 Subject: [PATCH] Allow assigning "0" to port Function for port validation doesn't validate "0" as a proper port number, althought IANA RFC 6335 [1] describes as valid 0-65535. Add missing "0" to function. [1] https://tools.ietf.org/html/rfc6335#section-8.1.2 Change-Id: I088add52cf454e5df503ecb5d6551724fb5ddaf4 Closes-Bug: #1590485 --- oslo_utils/netutils.py | 4 ++-- oslo_utils/tests/test_netutils.py | 4 ++-- releasenotes/notes/bump-up-port-range-f774a16336158339.yaml | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/bump-up-port-range-f774a16336158339.yaml diff --git a/oslo_utils/netutils.py b/oslo_utils/netutils.py index 0ad02fd..f452470 100644 --- a/oslo_utils/netutils.py +++ b/oslo_utils/netutils.py @@ -222,12 +222,12 @@ def _is_int_in_range(value, start, end): def is_valid_port(port): """Verify that port represents a valid port number. - Port can be valid integer having a value of 1 up to and + Port can be valid integer having a value of 0 up to and including 65535. .. versionadded:: 1.1.1 """ - return _is_int_in_range(port, 1, 65535) + return _is_int_in_range(port, 0, 65535) def is_valid_icmp_type(type): diff --git a/oslo_utils/tests/test_netutils.py b/oslo_utils/tests/test_netutils.py index 9b15d61..823c502 100644 --- a/oslo_utils/tests/test_netutils.py +++ b/oslo_utils/tests/test_netutils.py @@ -193,13 +193,13 @@ class NetworkUtilsTest(test_base.BaseTestCase): self.assertFalse(netutils.is_valid_cidr(10)) def test_valid_port(self): - valid_inputs = [1, '1', 2, '3', '5', 8, 13, 21, + valid_inputs = [0, '0', 1, '1', 2, '3', '5', 8, 13, 21, '80', '3246', '65535'] for input_str in valid_inputs: self.assertTrue(netutils.is_valid_port(input_str)) def test_valid_port_fail(self): - invalid_inputs = ['-32768', '0', 0, '65536', 528491, '528491', + invalid_inputs = ['-32768', '65536', 528491, '528491', '528.491', 'thirty-seven', None] for input_str in invalid_inputs: self.assertFalse(netutils.is_valid_port(input_str)) diff --git a/releasenotes/notes/bump-up-port-range-f774a16336158339.yaml b/releasenotes/notes/bump-up-port-range-f774a16336158339.yaml new file mode 100644 index 0000000..5e7e9aa --- /dev/null +++ b/releasenotes/notes/bump-up-port-range-f774a16336158339.yaml @@ -0,0 +1,3 @@ +--- +fixes: + - Expanded range of allowed ports by adding 0 to valid number.