Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix excluded port number 65535 #1164

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ldap3/utils/port_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def check_port(port):
""" Check if a port is valid. Return an error message indicating what is invalid if something isn't valid. """
if isinstance(port, int):
if port not in range(0, 65535):
if port not in range(0, 65536):
return 'Source port must in range from 0 to 65535'
else:
return 'Source port must be an integer'
Expand All @@ -20,7 +20,7 @@ def check_port_and_port_list(port, port_list):
return 'Cannot specify both a source port and a source port list'
elif port is not None:
if isinstance(port, int):
if port not in range(0, 65535):
if port not in range(0, 65536):
return 'Source port must in range from 0 to 65535'
else:
return 'Source port must be an integer'
Expand Down
16 changes: 16 additions & 0 deletions test/testValidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from ldap3.protocol.formatters.validators import validate_integer, validate_boolean, validate_bytes, validate_generic_single_value, validate_time, validate_zero_and_minus_one_and_positive_int
from ldap3.core.timezone import OffsetTzInfo
from ldap3.utils.port_validators import check_port, check_port_and_port_list


class Test(unittest.TestCase):
def test_int_validator_valid_number(self):
Expand Down Expand Up @@ -202,3 +204,17 @@ def test_validate_minus_one_zero_greater_than_zero(self):
self.assertTrue(validated)
validated = validate_zero_and_minus_one_and_positive_int('-2')
self.assertFalse(validated)

def test_check_port(self):
assert check_port("0") == 'Source port must be an integer'
assert check_port(0) is None
assert check_port(65535) is None
assert check_port(-1) == 'Source port must in range from 0 to 65535'
assert check_port(65536) == 'Source port must in range from 0 to 65535'

def test_check_port_and_port_list(self):
assert check_port_and_port_list("0", None) == 'Source port must be an integer'
assert check_port_and_port_list(0, None) is None
assert check_port_and_port_list(65535, None) is None
assert check_port_and_port_list(-1, None) == 'Source port must in range from 0 to 65535'
assert check_port_and_port_list(65536, None) == 'Source port must in range from 0 to 65535'