Skip to content

Commit

Permalink
Use package ipaddress for IP address validation in API tests
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Nov 15, 2023
1 parent a356cbd commit a691305
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions test/api/libs/responseVerifyer.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,21 @@ def verify_teleporter_zip(self, teleporter_archive: bytes):

# Check if a string is a valid IPv4 address
def valid_ipv4(self, addr: str) -> bool:
octets = addr.split(".") # type: list[str]
if len(octets) != 4:
return False
for octet in octets:
if not octet.isdigit():
return False
if int(octet) < 0 or int(octet) > 255:
return False
return True

try:
if type(ipaddress.ip_address(addr)) is ipaddress.IPv4Address:
return True
except ValueError:
pass
return False

# Check if a string is a valid IPv6 address
def valid_ipv6(self, addr: str) -> bool:
# Split the address into parts
parts = addr.split(":") # type: list[str]
# Check if the address is a valid IPv6 address
if len(parts) != 8:
return False
try:
if type(ipaddress.ip_address(addr)) is ipaddress.IPv6Address:
return True
except ValueError:
pass
return False


# Verify a single property's type
Expand Down

0 comments on commit a691305

Please sign in to comment.