Skip to content

Commit

Permalink
Addresses latest review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-marquez-csa committed Feb 7, 2024
1 parent ba72381 commit 5d6912f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/python_testing/TC_SC_4_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import ipaddress
import logging
import re

Expand Down Expand Up @@ -78,7 +79,7 @@ def get_operational_subtype(self) -> str:
return service_name

@staticmethod
def verify_decimal_value(input_value, comparison_value: int):
def verify_decimal_value(input_value, max_value: int):
try:
input_float = float(input_value)
input_int = int(input_float)
Expand All @@ -89,7 +90,7 @@ def verify_decimal_value(input_value, comparison_value: int):
if input_float != input_int:
return (False, f"Input ({input_value}) is not an integer.")

if input_int <= comparison_value:
if input_int <= max_value:
return (True, f"Input ({input_value}) is valid.")
else:
return (False, f"Input ({input_value}) exceeds the allowed value {comparison_value}.")
Expand Down Expand Up @@ -117,13 +118,15 @@ def verify_t_value(self, t_value):

@staticmethod
def contains_ipv6_address(addresses):
# IPv6 pattern for basic validation
ipv6_pattern = re.compile(r'(?:(?:[0-9a-fA-F]{1,4}:){7}(?:[0-9a-fA-F]{1,4}|:))|(?:[0-9a-fA-F]{1,4}:){6}(?::[0-9a-fA-F]{1,4}|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){5}(?:(?::[0-9a-fA-F]{1,4}){1,2}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){4}(?:(?::[0-9a-fA-F]{1,4}){1,3}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){3}(?:(?::[0-9a-fA-F]{1,4}){1,4}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){2}(?:(?::[0-9a-fA-F]{1,4}){1,5}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?:[0-9a-fA-F]{1,4}:){1}(?:(?::[0-9a-fA-F]{1,4}){1,6}|:((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|:)|(?::(?::[0-9a-fA-F]{1,4}){1,7}|:)', re.VERBOSE)

for address in addresses:
if ipv6_pattern.match(address):
try:
# Attempt to create an IPv6 address object. If successful, this is an IPv6 address.
ipaddress.IPv6Address(address)
return True, "At least one IPv6 address is present."

except ipaddress.AddressValueError:
# If an AddressValueError is raised, the current address is not a valid IPv6 address.
# The loop will continue to the next address.
continue
return False, "No IPv6 addresses found."

@async_test_body
Expand Down

0 comments on commit 5d6912f

Please sign in to comment.