forked from p34709852/monkey
Common: Allow 0 for NetworkPort
While TCP port 0 is reserved and you're not supposed to use it, it is a valid port.
This commit is contained in:
parent
9f3aaf970f
commit
5fc4d52d9f
|
@ -26,7 +26,7 @@ class NetworkPort(ConstrainedInt):
|
||||||
port: NetworkPort = typing.cast(NetworkPort, 1000)
|
port: NetworkPort = typing.cast(NetworkPort, 1000)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ge = 1
|
ge = 0
|
||||||
le = 65535
|
le = 65535
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,15 @@ from common.types import SocketAddress
|
||||||
|
|
||||||
GOOD_IP = "192.168.1.1"
|
GOOD_IP = "192.168.1.1"
|
||||||
BAD_IP = "192.168.1.999"
|
BAD_IP = "192.168.1.999"
|
||||||
GOOD_PORT = 1234
|
GOOD_PORTS = [0, 1, 1234, 65535]
|
||||||
BAD_PORTS = [99999, 0, -1]
|
BAD_PORTS = [99999, 65536, -1]
|
||||||
|
|
||||||
|
|
||||||
def test_socket_address__from_string():
|
@pytest.mark.parametrize("good_port", GOOD_PORTS)
|
||||||
expected = SocketAddress(ip=GOOD_IP, port=GOOD_PORT)
|
def test_socket_address__from_string(good_port):
|
||||||
|
expected = SocketAddress(ip=GOOD_IP, port=good_port)
|
||||||
|
|
||||||
address = SocketAddress.from_string(f"{GOOD_IP}:{GOOD_PORT}")
|
address = SocketAddress.from_string(f"{GOOD_IP}:{good_port}")
|
||||||
|
|
||||||
assert address == expected
|
assert address == expected
|
||||||
|
|
||||||
|
@ -22,10 +23,10 @@ def test_socket_address__from_string():
|
||||||
"not an address",
|
"not an address",
|
||||||
":",
|
":",
|
||||||
GOOD_IP,
|
GOOD_IP,
|
||||||
str(GOOD_PORT),
|
|
||||||
f"{GOOD_IP}:",
|
f"{GOOD_IP}:",
|
||||||
f":{GOOD_PORT}",
|
"25",
|
||||||
f"{BAD_IP}:{GOOD_PORT}",
|
":22",
|
||||||
|
*[f"{BAD_IP}:{p}" for p in GOOD_PORTS],
|
||||||
*[f"{GOOD_IP}:{bad_port}" for bad_port in BAD_PORTS],
|
*[f"{GOOD_IP}:{bad_port}" for bad_port in BAD_PORTS],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue