Skip to content

Commit 5d6912f

Browse files
Addresses latest review comments
1 parent ba72381 commit 5d6912f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/python_testing/TC_SC_4_3.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
#
1717

18+
import ipaddress
1819
import logging
1920
import re
2021

@@ -78,7 +79,7 @@ def get_operational_subtype(self) -> str:
7879
return service_name
7980

8081
@staticmethod
81-
def verify_decimal_value(input_value, comparison_value: int):
82+
def verify_decimal_value(input_value, max_value: int):
8283
try:
8384
input_float = float(input_value)
8485
input_int = int(input_float)
@@ -89,7 +90,7 @@ def verify_decimal_value(input_value, comparison_value: int):
8990
if input_float != input_int:
9091
return (False, f"Input ({input_value}) is not an integer.")
9192

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

118119
@staticmethod
119120
def contains_ipv6_address(addresses):
120-
# IPv6 pattern for basic validation
121-
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)
122-
123121
for address in addresses:
124-
if ipv6_pattern.match(address):
122+
try:
123+
# Attempt to create an IPv6 address object. If successful, this is an IPv6 address.
124+
ipaddress.IPv6Address(address)
125125
return True, "At least one IPv6 address is present."
126-
126+
except ipaddress.AddressValueError:
127+
# If an AddressValueError is raised, the current address is not a valid IPv6 address.
128+
# The loop will continue to the next address.
129+
continue
127130
return False, "No IPv6 addresses found."
128131

129132
@async_test_body

0 commit comments

Comments
 (0)