commit
25eb3bdb0c
|
@ -1117,6 +1117,20 @@ def test_network_traffic_socket_example():
|
||||||
assert nt.extensions['socket-ext'].socket_type == "SOCK_STREAM"
|
assert nt.extensions['socket-ext'].socket_type == "SOCK_STREAM"
|
||||||
|
|
||||||
|
|
||||||
|
def test_correct_socket_options():
|
||||||
|
se1 = stix2.v21.SocketExt(
|
||||||
|
is_listening=True,
|
||||||
|
address_family="AF_INET",
|
||||||
|
protocol_family="PF_INET",
|
||||||
|
socket_type="SOCK_STREAM",
|
||||||
|
options={"ICMP6_RCVTIMEO": 100},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert se1.address_family == "AF_INET"
|
||||||
|
assert se1.socket_type == "SOCK_STREAM"
|
||||||
|
assert se1.options == {"ICMP6_RCVTIMEO": 100}
|
||||||
|
|
||||||
|
|
||||||
def test_incorrect_socket_options():
|
def test_incorrect_socket_options():
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
stix2.v21.SocketExt(
|
stix2.v21.SocketExt(
|
||||||
|
|
|
@ -598,8 +598,9 @@ class SocketExt(_Extension):
|
||||||
options = self.get('options')
|
options = self.get('options')
|
||||||
|
|
||||||
if options is not None:
|
if options is not None:
|
||||||
|
acceptable_prefixes = ["SO_", "ICMP_", "ICMP6_", "IP_", "IPV6_", "MCAST_", "TCP_", "IRLMP_"]
|
||||||
for key, val in options.items():
|
for key, val in options.items():
|
||||||
if key[:3] != "SO_":
|
if key[:key.find('_') + 1] not in acceptable_prefixes:
|
||||||
raise ValueError("Incorrect options key")
|
raise ValueError("Incorrect options key")
|
||||||
if not isinstance(val, int):
|
if not isinstance(val, int):
|
||||||
raise ValueError("Options value must be an integer")
|
raise ValueError("Options value must be an integer")
|
||||||
|
|
Loading…
Reference in New Issue