From 63364e9570d29c83269b64212492102515342ad7 Mon Sep 17 00:00:00 2001 From: Marcin Godzina Date: Mon, 10 Jan 2022 14:05:13 +0100 Subject: [PATCH 1/7] adding user-context tests --- .../leases_cmds/test_lease_user_context.py | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py diff --git a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py new file mode 100644 index 00000000..04a60030 --- /dev/null +++ b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py @@ -0,0 +1,82 @@ +"""Kea add valid tests""" + +# pylint: disable=invalid-name,unused-argument +import pytest + +import misc +import srv_msg +import srv_control + + +def ordered(obj): + """ + Helper function to sort JSON for ease of comparison. + :param obj: json as dictionary + :return: Sorted json dictionary + """ + if isinstance(obj, dict): + return sorted((k, ordered(v)) for k, v in obj.items()) + if isinstance(obj, list): + return sorted(ordered(x) for x in obj) + return obj + + +@pytest.mark.v4 +@pytest.mark.kea_only +@pytest.mark.controlchannel +@pytest.mark.hook +@pytest.mark.lease_cmds +@pytest.mark.parametrize('backend', ['memfile', 'mysql', 'postgresql']) +def test_hook_v4_user_context_add(backend): + """ + Test adding and getting user-context by lease4 commands. + @param backend: database backends as test parameter + """ + misc.test_setup() + srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') + srv_control.define_temporary_lease_db_backend(backend) + srv_control.open_control_channel() + srv_control.agent_control_channel() + srv_control.add_hooks('libdhcp_lease_cmds.so') + srv_control.build_and_send_config_files() + + srv_control.start_srv('DHCP', 'started') + + # prepare user-context JSON + user_context = {"version": [{"number": 1, "rev": 2}, {"id": 1, "no": 2}], + "class": "!@#$%^&*(`)'_+=-?|\"\\\b\f\n\r\t", + "tre,e": {"bra,nch1": {"treehouse": 1}, "bra,nch2": 2, + "bra,nch3": {"leaf1": 1, + "leaf2": ["vein1", "vein2"]}}} + # add lease with user-context + cmd = {"command": "lease4-add", + "arguments": {"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.5", + "user-context": user_context}} + resp = srv_msg.send_ctrl_cmd(cmd) + assert resp["text"] == "Lease for address 192.168.50.5, subnet-id 1 added." + + # get the lease with lease4-get + cmd = {"command": "lease4-get", + "arguments": {"identifier-type": "hw-address", "identifier": "ff:01:02:03:ff:04", + "subnet-id": 1}} + + resp = srv_msg.send_ctrl_cmd(cmd) + assert resp["text"] == "IPv4 lease found." + + resp = resp["arguments"] # drop unnecessary info for comparison + + # compare sorted JSON prepared on start with sorted returned one + assert ordered(user_context) == ordered(resp["user-context"]) + + del resp["user-context"] # We already checked it + del resp["cltt"] # this value is dynamic + + # check the rest of the response + assert resp == {"fqdn-fwd": False, + "fqdn-rev": False, + "hostname": "", + "hw-address": "ff:01:02:03:ff:04", + "ip-address": "192.168.50.5", + "state": 0, + "subnet-id": 1, + "valid-lft": 4000} -- GitLab From e32cfee75106ca0c752327983c080c0999a158a1 Mon Sep 17 00:00:00 2001 From: Marcin Godzina Date: Tue, 11 Jan 2022 13:23:14 +0100 Subject: [PATCH 2/7] added tests for v6 --- .../leases_cmds/test_lease_user_context.py | 54 ++++++- .../leases_cmds/test_lease_user_context.py | 143 ++++++++++++++++++ 2 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py diff --git a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py index 04a60030..15a74490 100644 --- a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py @@ -1,4 +1,4 @@ -"""Kea add valid tests""" +"""Kea API user context tests for v4""" # pylint: disable=invalid-name,unused-argument import pytest @@ -27,10 +27,12 @@ def ordered(obj): @pytest.mark.hook @pytest.mark.lease_cmds @pytest.mark.parametrize('backend', ['memfile', 'mysql', 'postgresql']) -def test_hook_v4_user_context_add(backend): +@pytest.mark.parametrize("channel", ['socket', 'http']) +def test_hook_v4_lease_user_context(backend, channel): """ Test adding and getting user-context by lease4 commands. - @param backend: database backends as test parameter + :param backend: database backends as test parameter + :param channel: communication channel as test parameter """ misc.test_setup() srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') @@ -52,7 +54,7 @@ def test_hook_v4_user_context_add(backend): cmd = {"command": "lease4-add", "arguments": {"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.5", "user-context": user_context}} - resp = srv_msg.send_ctrl_cmd(cmd) + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel) assert resp["text"] == "Lease for address 192.168.50.5, subnet-id 1 added." # get the lease with lease4-get @@ -60,7 +62,7 @@ def test_hook_v4_user_context_add(backend): "arguments": {"identifier-type": "hw-address", "identifier": "ff:01:02:03:ff:04", "subnet-id": 1}} - resp = srv_msg.send_ctrl_cmd(cmd) + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel) assert resp["text"] == "IPv4 lease found." resp = resp["arguments"] # drop unnecessary info for comparison @@ -80,3 +82,45 @@ def test_hook_v4_user_context_add(backend): "state": 0, "subnet-id": 1, "valid-lft": 4000} + + +@pytest.mark.v4 +@pytest.mark.kea_only +@pytest.mark.controlchannel +@pytest.mark.hook +@pytest.mark.lease_cmds +@pytest.mark.parametrize("channel", ['socket', 'http']) +def test_hook_v4_lease_user_context_negative(channel): + """ + Test invalid values send as user context by lease4-add and lease4-update + :param channel: communication channel as test parameter + """ + misc.test_setup() + srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.5-192.168.50.5') + srv_control.open_control_channel() + srv_control.agent_control_channel() + srv_control.add_hooks('libdhcp_lease_cmds.so') + srv_control.build_and_send_config_files() + + srv_control.start_srv('DHCP', 'started') + + # add lease with invalid user-context + cmd = {"command": "lease4-add", + "arguments": {"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.5", + "user-context": 1}} + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) + assert resp["text"] == "Invalid user context '1' is not a JSON map." + + # add lease with invalid user-context + cmd = {"command": "lease4-add", + "arguments": {"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.5", + "user-context": True}} + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) + assert resp["text"] == "Invalid user context 'true' is not a JSON map." + + # add lease with invalid user-context + cmd = {"command": "lease4-add", + "arguments": {"hw-address": "ff:01:02:03:ff:04", "ip-address": "192.168.50.5", + "user-context": "test"}} + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) + assert resp["text"] == "Invalid user context '\"test\"' is not a JSON map." diff --git a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py new file mode 100644 index 00000000..01b06cc5 --- /dev/null +++ b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py @@ -0,0 +1,143 @@ +"""Kea API user context tests for v4""" + +# pylint: disable=invalid-name,unused-argument +import pytest + +import misc +import srv_msg +import srv_control + + +def ordered(obj): + """ + Helper function to sort JSON for ease of comparison. + :param obj: json as dictionary + :return: Sorted json dictionary + """ + if isinstance(obj, dict): + return sorted((k, ordered(v)) for k, v in obj.items()) + if isinstance(obj, list): + return sorted(ordered(x) for x in obj) + return obj + + +@pytest.mark.v6 +@pytest.mark.kea_only +@pytest.mark.controlchannel +@pytest.mark.hook +@pytest.mark.lease_cmds +@pytest.mark.parametrize('backend', ['memfile', 'mysql', 'postgresql']) +@pytest.mark.parametrize("channel", ['socket', 'http']) +def test_hook_v6_lease_user_context(backend, channel): + """ + Test adding and getting user-context by lease6 commands. + :param backend: database backends as test parameter + :param channel: communication channel as test parameter + """ + misc.test_setup() + srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::1') + srv_control.define_temporary_lease_db_backend(backend) + srv_control.open_control_channel() + srv_control.agent_control_channel() + srv_control.add_hooks('libdhcp_lease_cmds.so') + srv_control.build_and_send_config_files() + + srv_control.start_srv('DHCP', 'started') + + # prepare user-context JSON + user_context = {"version": [{"number": 1, "rev": 2}, {"id": 1, "no": 2}], + "class": "!@#$%^&*(`)'_+=-?|\"\\\b\f\n\r\t", + "tre,e": {"bra,nch1": {"treehouse": 1}, "bra,nch2": 2, + "bra,nch3": {"leaf1": 1, + "leaf2": ["vein1", "vein2"]}}} + # add lease with user-context + cmd = {"command": "lease6-add", + "arguments": {"subnet-id": 1, + "ip-address": "2001:db8:1::1", + "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", + "iaid": 1234, + "user-context": user_context}} + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel) + assert resp["text"] == "Lease for address 2001:db8:1::1, subnet-id 1 added." + + # get the lease with lease6-get + cmd = {"command": "lease6-get", + "arguments": {"subnet-id": 1, + "ip-address": "2001:db8:1::1", + "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", + "iaid": 1234}} + + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel) + assert resp["text"] == "IPv6 lease found." + + resp = resp["arguments"] # drop unnecessary info for comparison + + # compare sorted JSON prepared on start with sorted returned one + assert ordered(user_context) == ordered(resp["user-context"]) + + del resp["user-context"] # We already checked it + del resp["cltt"] # this value is dynamic + + # check the rest of the response + assert resp == {"duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", + "fqdn-fwd": False, + "fqdn-rev": False, + "hostname": "", + "iaid": 1234, + "ip-address": "2001:db8:1::1", + "preferred-lft": 4000, + "state": 0, + "subnet-id": 1, + "type": "IA_NA", + "valid-lft": 4000} + + +@pytest.mark.v6 +@pytest.mark.kea_only +@pytest.mark.controlchannel +@pytest.mark.hook +@pytest.mark.lease_cmds +@pytest.mark.parametrize("channel", ['socket', 'http']) +def test_hook_v6_lease_user_context_negative(channel): + """ + Test invalid values send as user context by lease6-add and lease4-update + :param channel: communication channel as test parameter + """ + misc.test_setup() + srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::1') + srv_control.open_control_channel() + srv_control.agent_control_channel() + srv_control.add_hooks('libdhcp_lease_cmds.so') + srv_control.build_and_send_config_files() + + srv_control.start_srv('DHCP', 'started') + + # add lease with invalid user-context + cmd = {"command": "lease6-add", + "arguments": {"subnet-id": 1, + "ip-address": "2001:db8:1::1", + "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", + "iaid": 1234, + "user-context": 1}} + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) + assert resp["text"] == "Invalid user context '1' is not a JSON map." + + # add lease with invalid user-context + cmd = {"command": "lease6-add", + "arguments": {"subnet-id": 1, + "ip-address": "2001:db8:1::1", + "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", + "iaid": 1234, + "user-context": True}} + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) + assert resp["text"] == "Invalid user context 'true' is not a JSON map." + + # add lease with invalid user-context + cmd = {"command": "lease6-add", + "arguments": {"subnet-id": 1, + "ip-address": "2001:db8:1::1", + "duid": "1a:1b:1c:1d:1e:1f:20:21:22:23:24", + "iaid": 1234, + "user-context": "test"}} + resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) + assert resp["text"] == "Invalid user context '\"test\"' is not a JSON map." -- GitLab From 619a15e92404551b9e4dd4bebaefe1cf052357f8 Mon Sep 17 00:00:00 2001 From: Marcin Godzina Date: Wed, 12 Jan 2022 13:06:21 +0100 Subject: [PATCH 3/7] added tests for v4 and v6 of relay-agent-info and relays in user-context --- .../leases_cmds/test_lease_user_context.py | 73 +++++++++++- .../leases_cmds/test_lease_user_context.py | 109 +++++++++++++++++- 2 files changed, 174 insertions(+), 8 deletions(-) diff --git a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py index 15a74490..3feb347f 100644 --- a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py @@ -6,18 +6,19 @@ import pytest import misc import srv_msg import srv_control +from forge_cfg import world -def ordered(obj): +def _ordered(obj): """ Helper function to sort JSON for ease of comparison. :param obj: json as dictionary :return: Sorted json dictionary """ if isinstance(obj, dict): - return sorted((k, ordered(v)) for k, v in obj.items()) + return sorted((k, _ordered(v)) for k, v in obj.items()) if isinstance(obj, list): - return sorted(ordered(x) for x in obj) + return sorted(_ordered(x) for x in obj) return obj @@ -68,7 +69,7 @@ def test_hook_v4_lease_user_context(backend, channel): resp = resp["arguments"] # drop unnecessary info for comparison # compare sorted JSON prepared on start with sorted returned one - assert ordered(user_context) == ordered(resp["user-context"]) + assert _ordered(user_context) == _ordered(resp["user-context"]) del resp["user-context"] # We already checked it del resp["cltt"] # this value is dynamic @@ -124,3 +125,67 @@ def test_hook_v4_lease_user_context_negative(channel): "user-context": "test"}} resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) assert resp["text"] == "Invalid user context '\"test\"' is not a JSON map." + + +@pytest.mark.v4 +@pytest.mark.kea_only +@pytest.mark.controlchannel +@pytest.mark.hook +@pytest.mark.lease_cmds +@pytest.mark.parametrize('backend', ['memfile', 'mysql', 'postgresql']) +def test_hook_v4_lease_extended_info(backend): + """ + Test storing extended info of acquired lease and retrieving it by lease4-get + :param backend: database backends as test parameter + """ + misc.test_setup() + world.dhcp_cfg['store-extended-info'] = True + srv_control.config_srv_subnet('192.168.50.0/24', '192.168.50.1-192.168.50.10') + srv_control.define_temporary_lease_db_backend(backend) + srv_control.open_control_channel() + srv_control.agent_control_channel() + srv_control.add_hooks('libdhcp_lease_cmds.so') + srv_control.build_and_send_config_files() + + srv_control.start_srv('DHCP', 'started') + + misc.test_procedure() + srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') + srv_msg.client_send_msg('DISCOVER') + + misc.pass_criteria() + srv_msg.send_wait_for_message('MUST', 'OFFER') + srv_msg.response_check_content('yiaddr', '192.168.50.1') + + misc.test_procedure() + srv_msg.client_copy_option('server_id') + srv_msg.client_does_include_with_value('requested_addr', '192.168.50.1') + srv_msg.client_sets_value('Client', 'chaddr', 'ff:01:02:03:ff:04') + srv_msg.client_does_include_with_value('relay_agent_information', '0106060106020603') + srv_msg.client_send_msg('REQUEST') + + misc.pass_criteria() + srv_msg.send_wait_for_message('MUST', 'ACK') + srv_msg.response_check_content('yiaddr', '192.168.50.1') + + # get the lease with lease4-get + cmd = {"command": "lease4-get", + "arguments": {"identifier-type": "hw-address", "identifier": "ff:01:02:03:ff:04", + "subnet-id": 1}} + + resp = srv_msg.send_ctrl_cmd(cmd) + assert resp["text"] == "IPv4 lease found." + + del resp["arguments"]["cltt"] # this value is dynamic + + # check the response + assert resp["arguments"] == {"fqdn-fwd": False, + "fqdn-rev": False, + "hostname": "", + "hw-address": "ff:01:02:03:ff:04", + "ip-address": "192.168.50.1", + "state": 0, + "subnet-id": 1, + "user-context": + {"ISC": {"relay-agent-info": "0x0106060106020603"}}, + "valid-lft": 4000} diff --git a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py index 01b06cc5..1e9407cd 100644 --- a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py @@ -6,18 +6,19 @@ import pytest import misc import srv_msg import srv_control +from forge_cfg import world -def ordered(obj): +def _ordered(obj): """ Helper function to sort JSON for ease of comparison. :param obj: json as dictionary :return: Sorted json dictionary """ if isinstance(obj, dict): - return sorted((k, ordered(v)) for k, v in obj.items()) + return sorted((k, _ordered(v)) for k, v in obj.items()) if isinstance(obj, list): - return sorted(ordered(x) for x in obj) + return sorted(_ordered(x) for x in obj) return obj @@ -73,7 +74,7 @@ def test_hook_v6_lease_user_context(backend, channel): resp = resp["arguments"] # drop unnecessary info for comparison # compare sorted JSON prepared on start with sorted returned one - assert ordered(user_context) == ordered(resp["user-context"]) + assert _ordered(user_context) == _ordered(resp["user-context"]) del resp["user-context"] # We already checked it del resp["cltt"] # this value is dynamic @@ -141,3 +142,103 @@ def test_hook_v6_lease_user_context_negative(channel): "user-context": "test"}} resp = srv_msg.send_ctrl_cmd(cmd, channel=channel, exp_result=1) assert resp["text"] == "Invalid user context '\"test\"' is not a JSON map." + + +@pytest.mark.v6 +@pytest.mark.kea_only +@pytest.mark.controlchannel +@pytest.mark.hook +@pytest.mark.lease_cmds +@pytest.mark.parametrize('backend', ['memfile', 'mysql', 'postgresql']) +def test_hook_v6_lease_extended_info(backend): + """ + Test storing extended info of acquired lease and retrieving it by lease6-get + Communication with Kea is made by relayed messages to trigger storing relay info in user-context + :param backend: database backends as test parameter + """ + misc.test_setup() + world.dhcp_cfg['store-extended-info'] = True + srv_control.config_srv_subnet('2001:db8:1::/64', '2001:db8:1::1-2001:db8:1::1') + srv_control.define_temporary_lease_db_backend(backend) + srv_control.open_control_channel() + srv_control.agent_control_channel() + srv_control.add_hooks('libdhcp_lease_cmds.so') + srv_control.build_and_send_config_files() + + srv_control.start_srv('DHCP', 'started') + + # Prepare Solicit message + misc.test_procedure() + srv_msg.client_sets_value('Client', 'DUID', '00:03:00:01:f6:f5:f4:f3:f2:01') + srv_msg.client_sets_value('Client', 'ia_id', 1234) + srv_msg.client_does_include('Client', 'client-id') + srv_msg.client_does_include('Client', 'IA-NA') + srv_msg.client_send_msg('SOLICIT') + + # Encapsulate the solicit in a relay forward message. + srv_msg.client_sets_value('RelayAgent', 'linkaddr', '2001:db8:1::1000') + srv_msg.client_sets_value('RelayAgent', 'ifaceid', 'port1234') + srv_msg.client_does_include('RelayAgent', 'interface-id') + srv_msg.create_relay_forward() + + # Send message and expect a relay reply. + misc.pass_criteria() + srv_msg.send_wait_for_message('MUST', 'RELAYREPLY') + + # Prepare Request message using options from Advertise + misc.test_procedure() + # Checking response for Relayed option and setting sender_type to 'Client' is required + # to copy options to correct place in Request message + srv_msg.response_check_option_content(9, 'Relayed', 'Message') + world.sender_type = "Client" + srv_msg.client_copy_option('IA_NA') + srv_msg.client_copy_option('server-id') + srv_msg.client_sets_value('Client', 'DUID', '00:03:00:01:f6:f5:f4:f3:f2:01') + srv_msg.client_does_include('Client', 'client-id') + srv_msg.client_send_msg('REQUEST') + + # Encapsulate the Request in a relay forward message. + srv_msg.client_sets_value('RelayAgent', 'ifaceid', 'port1234') + srv_msg.client_sets_value('RelayAgent', 'linkaddr', '2001:db8:1::1000') + srv_msg.client_does_include('RelayAgent', 'interface-id') + srv_msg.create_relay_forward() + + # Send message and expect a relay reply. + misc.pass_criteria() + srv_msg.send_wait_for_message('MUST', 'RELAYREPLY') + + # get the lease with lease6-get + cmd = {"command": "lease6-get", + "arguments": {"subnet-id": 1, + "ip-address": "2001:db8:1::1", + "duid": "00:03:00:01:f6:f5:f4:f3:f2:01", + "iaid": 1234}} + + resp = srv_msg.send_ctrl_cmd(cmd) + assert resp["text"] == "IPv6 lease found." + del resp["arguments"]["cltt"] # this value is dynamic + # check the response for user-context added by Kea server. + assert resp["arguments"] == {"duid": "00:03:00:01:f6:f5:f4:f3:f2:01", + "fqdn-fwd": False, + "fqdn-rev": False, + "hostname": "", + "hw-address": "f6:f5:f4:f3:f2:01", + "iaid": 1234, + "ip-address": "2001:db8:1::1", + "preferred-lft": 3000, + "state": 0, + "subnet-id": 1, + "type": "IA_NA", + "user-context": { + "ISC": { + "relays": [ + { + "hop": 0, + "link": "2001:db8:1::1000", + "options": "0x00120008706F727431323334", + "peer": "fe80::a00:27ff:fe5d:efc6" + } + ] + } + }, + "valid-lft": 4000} -- GitLab From 644507217c14d3f44ca594cdbc25a763b6bb1418 Mon Sep 17 00:00:00 2001 From: Marcin Godzina Date: Wed, 12 Jan 2022 12:14:54 +0000 Subject: [PATCH 4/7] Apply 1 suggestion(s) to 1 file(s) --- tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py index 1e9407cd..edca0c23 100644 --- a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py @@ -1,4 +1,4 @@ -"""Kea API user context tests for v4""" +"""Kea API user context tests for v6""" # pylint: disable=invalid-name,unused-argument import pytest -- GitLab From 0fa3cd2d21b8354a5ad80582779b1dfc85edbaef Mon Sep 17 00:00:00 2001 From: Marcin Godzina Date: Wed, 12 Jan 2022 14:08:28 +0100 Subject: [PATCH 5/7] added TODO --- tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py index edca0c23..906307ad 100644 --- a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py @@ -189,6 +189,7 @@ def test_hook_v6_lease_extended_info(backend): misc.test_procedure() # Checking response for Relayed option and setting sender_type to 'Client' is required # to copy options to correct place in Request message + # TODO Modify client_copy_option to copy options into relayed messages w\o world.sender_type. srv_msg.response_check_option_content(9, 'Relayed', 'Message') world.sender_type = "Client" srv_msg.client_copy_option('IA_NA') -- GitLab From 73a279633106c310cef32fd9612d6c6eaac624d1 Mon Sep 17 00:00:00 2001 From: Marcin Godzina Date: Fri, 14 Jan 2022 12:20:35 +0100 Subject: [PATCH 6/7] Corrected reviewer suggestions --- .../leases_cmds/test_lease_user_context.py | 17 ++++++++++++++ .../leases_cmds/test_lease_user_context.py | 22 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py index 3feb347f..013cd234 100644 --- a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py @@ -1,3 +1,20 @@ +# Copyright (C) 2013-2022 Internet Systems Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# Author: Marcin Godzina + """Kea API user context tests for v4""" # pylint: disable=invalid-name,unused-argument diff --git a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py index 906307ad..a73bf132 100644 --- a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py @@ -1,3 +1,20 @@ +# Copyright (C) 2013-2022 Internet Systems Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# Author: Marcin Godzina + """Kea API user context tests for v6""" # pylint: disable=invalid-name,unused-argument @@ -201,6 +218,7 @@ def test_hook_v6_lease_extended_info(backend): # Encapsulate the Request in a relay forward message. srv_msg.client_sets_value('RelayAgent', 'ifaceid', 'port1234') srv_msg.client_sets_value('RelayAgent', 'linkaddr', '2001:db8:1::1000') + srv_msg.client_sets_value('RelayAgent', 'peeraddr', 'fe80::1') srv_msg.client_does_include('RelayAgent', 'interface-id') srv_msg.create_relay_forward() @@ -237,8 +255,8 @@ def test_hook_v6_lease_extended_info(backend): "hop": 0, "link": "2001:db8:1::1000", "options": "0x00120008706F727431323334", - "peer": "fe80::a00:27ff:fe5d:efc6" - } + "peer": "fe80::1" + } ] } }, -- GitLab From 56d3baf326c44d0b45e0b34ea66447fa7a0e619d Mon Sep 17 00:00:00 2001 From: Marcin Godzina Date: Fri, 14 Jan 2022 13:01:11 +0100 Subject: [PATCH 7/7] Corrected reviewer suggestions, move _ordered() as sort_container() to multi_protocol_functions.py --- .../leases_cmds/test_lease_user_context.py | 18 +++--------------- .../leases_cmds/test_lease_user_context.py | 18 +++--------------- tests/protosupport/multi_protocol_functions.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py index 013cd234..3d9dccb5 100644 --- a/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv4/kea_only/leases_cmds/test_lease_user_context.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2022 Internet Systems Consortium. +# Copyright (C) 2022 Internet Systems Consortium. # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -24,19 +24,7 @@ import misc import srv_msg import srv_control from forge_cfg import world - - -def _ordered(obj): - """ - Helper function to sort JSON for ease of comparison. - :param obj: json as dictionary - :return: Sorted json dictionary - """ - if isinstance(obj, dict): - return sorted((k, _ordered(v)) for k, v in obj.items()) - if isinstance(obj, list): - return sorted(_ordered(x) for x in obj) - return obj +from protosupport.multi_protocol_functions import sort_container @pytest.mark.v4 @@ -86,7 +74,7 @@ def test_hook_v4_lease_user_context(backend, channel): resp = resp["arguments"] # drop unnecessary info for comparison # compare sorted JSON prepared on start with sorted returned one - assert _ordered(user_context) == _ordered(resp["user-context"]) + assert sort_container(user_context) == sort_container(resp["user-context"]) del resp["user-context"] # We already checked it del resp["cltt"] # this value is dynamic diff --git a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py index a73bf132..68731017 100644 --- a/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py +++ b/tests/dhcpv6/kea_only/leases_cmds/test_lease_user_context.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2022 Internet Systems Consortium. +# Copyright (C) 2022 Internet Systems Consortium. # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above @@ -24,19 +24,7 @@ import misc import srv_msg import srv_control from forge_cfg import world - - -def _ordered(obj): - """ - Helper function to sort JSON for ease of comparison. - :param obj: json as dictionary - :return: Sorted json dictionary - """ - if isinstance(obj, dict): - return sorted((k, _ordered(v)) for k, v in obj.items()) - if isinstance(obj, list): - return sorted(_ordered(x) for x in obj) - return obj +from protosupport.multi_protocol_functions import sort_container @pytest.mark.v6 @@ -91,7 +79,7 @@ def test_hook_v6_lease_user_context(backend, channel): resp = resp["arguments"] # drop unnecessary info for comparison # compare sorted JSON prepared on start with sorted returned one - assert _ordered(user_context) == _ordered(resp["user-context"]) + assert sort_container(user_context) == sort_container(resp["user-context"]) del resp["user-context"] # We already checked it del resp["cltt"] # this value is dynamic diff --git a/tests/protosupport/multi_protocol_functions.py b/tests/protosupport/multi_protocol_functions.py index 3bc69c99..9702cdde 100644 --- a/tests/protosupport/multi_protocol_functions.py +++ b/tests/protosupport/multi_protocol_functions.py @@ -146,6 +146,19 @@ def file_includes_line(condition, line): assert False, 'Downloaded file does NOT contain line: "%s"' % line +def sort_container(obj): + """ + Helper function to sort JSON for ease of comparison. + :param obj: json as dictionary or other list + :return: Sorted json dictionary or other list + """ + if isinstance(obj, dict): + return sorted((k, sort_container(v)) for k, v in obj.items()) + if isinstance(obj, list): + return sorted(sort_container(x) for x in obj) + return obj + + def add_variable(variable_name, variable_val, val_type): """ Define variable and add it to temporary list or to init_all.py file. -- GitLab