From 5e1eff8a22b085d755ac377e7a02a600a4709207 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Wed, 11 Dec 2024 16:26:13 -0800 Subject: [PATCH 01/17] [Test] Creating TC_CADMIN_1_5 test module - Following test steps in Test Plan PR https://github.com/CHIP-Specifications/chip-test-plans/pull/4790 created TC_CADMIN_1_5 test module --- src/python_testing/TC_CADMIN_1_5.py | 212 ++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 src/python_testing/TC_CADMIN_1_5.py diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py new file mode 100644 index 00000000000000..2b3765043eab0e --- /dev/null +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -0,0 +1,212 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: +# run1: +# app: ${ALL_CLUSTERS_APP} +# app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json +# script-args: > +# --storage-path admin_storage.json +# --commissioning-method on-network +# --discriminator 1234 +# --passcode 20202021 +# --trace-to json:${TRACE_TEST_JSON}.json +# --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# --PICS src/app/tests/suites/certification/ci-pics-values +# factory-reset: true +# quiet: false +# === END CI TEST ARGUMENTS === + +import asyncio +import asyncio.exceptions as ae +import logging +import random +from time import sleep + +import chip.clusters as Clusters +from chip import ChipDeviceCtrl +from chip.ChipDeviceCtrl import CommissioningParameters +from chip.exceptions import ChipStackError +import chip.interaction_model +from chip.native import PyChipError +from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mdns_discovery import mdns_discovery +from mobly import asserts + + +class TC_CADMIN_1_5(MatterBaseTest): + async def get_txt_record(self): + discovery = mdns_discovery.MdnsDiscovery(verbose_logging=True) + comm_service = await discovery.get_commissionable_service( + discovery_timeout_sec=240, + log_output=False, + ) + return comm_service + + async def OpenCommissioningWindow(self, timeout: int, iteration: int=10000, discriminator: int=1234) -> CommissioningParameters: + try: + params = await self.th1.OpenCommissioningWindow( + nodeid=self.dut_node_id, timeout=timeout, iteration=iteration, discriminator=self.discriminator, option=1) + return params + + except Exception as e: + logging.exception('Error running OpenCommissioningWindow %s', e) + asserts.assert_true(False, 'Failed to open commissioning window') + + async def CommissionOnNetwork(self, setup_code: int): + ctx = asserts.assert_raises(ChipStackError) + try: + with ctx: + await self.th2.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=setup_code, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) + errcode = PyChipError.from_code(ctx.exception.err) + + except ae.CancelledError as e: + errcode = e.__cause__ + return errcode + + def steps_TC_CADMIN_1_5(self) -> list[TestStep]: + return [ + TestStep(1, "Commissioning, already done", is_commissioning=True), + TestStep(2, "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM"), + TestStep(3, "TH_CR1 finds DUT_CE advertising as a commissionable node on DNS-SD", "Verify that the DNS-SD advertisement TXT record shows CM=2"), + TestStep(4, "TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds", + "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), + TestStep(5, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM", "{resDutSuccess}"), + TestStep(6, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command", "{resDutSuccess}"), + TestStep(7, "TH_CR2 attempts to start a commissioning process with DUT_CE", + "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), + TestStep(8, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command.", + "Verify this command fails with the cluster specific status code of WindowNotOpen"), + TestStep(9, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(10, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(11, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(12, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short'", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(13, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long'", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(14, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", + "Verify DUT_CE opens its Commissioning window to allow a second commissioning"), + TestStep(15, "TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", + "Verify DUT_CE fails to open Commissioning window with status code 2 (Busy)"), + TestStep(16, "TH_CR2 starts a commissioning process with DUT_CE", + "Commissioning is successful"), + TestStep(17, "TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command", + "Verify DUT_CE fails to revoke giving status code 4 (WindowNotOpen) as there was no window open"), + ] + + def pics_TC_CADMIN_1_5(self) -> list[str]: + return ["CADMIN.S"] + + @async_test_body + async def test_TC_CADMIN_1_5(self): + self.step(1) + + # Establishing TH1 and TH2 + self.th1 = self.default_controller + self.discriminator = random.randint(0, 4095) + th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() + th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1) + self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) + + self.step(2) + # TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM + params = await self.OpenCommissioningWindow(timeout=180) + + self.step(3) + # TH_CR1 finds DUT_CE advertising as a commissionable node on DNS-SD + services = await self.get_txt_record() + if services.txt_record['CM'] != "2": + asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") + + self.step(4) + # TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds + sleep(190) + #await self.CommissionAttempt(setupPinCode, expectedErrCode=0x03) + await self.CommissionOnNetwork(params.setupPinCode) + + self.step(5) + # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM + params2 = await self.OpenCommissioningWindow(timeout=180) + + self.step(6) + # TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command + try: + revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) + except chip.interaction_model.InteractionModelError as e: + self.print_step("interaction model error", dir(e)) + + self.step(7) + # TH_CR2 attempts to start a commissioning process with DUT_CE + await self.CommissionOnNetwork(params2.setupPinCode) + + self.step(8) + # TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command. + try: + revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) + except chip.interaction_model.InteractionModelError as e: + asserts.assert_true(e.clusterStatus, 4, "Cluster status must be 4 to pass this step") + + self.step(9) + # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096 + await self.OpenCommissioningWindow(timeout=180, discriminator=4096) + + self.step(10) + # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999 + await self.OpenCommissioningWindow(timeout=180, iteration=999) + + self.step(11) + # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001 + await self.OpenCommissioningWindow(timeout=180, iteration=100001) + + self.step(12) + # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short' + await self.OpenCommissioningWindow(timeout=180, salt="too_short") + + self.step(13) + # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long' + await self.OpenCommissioningWindow(timeout=180, salt="'this pake salt very very very long'") + + self.step(14) + # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM + cluster = Clusters.GeneralCommissioning + attribute = cluster.Attributes.BasicCommissioningInfo + duration = await self.read_single_attribute_check_success(endpoint=0, cluster=cluster, attribute=attribute) + params2 = await self.OpenCommissioningWindow(timeout=duration.maxCumulativeFailsafeSeconds) + + self.step(15) + # TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM + params3 = await self.OpenCommissioningWindow(timeout=duration.maxCumulativeFailsafeSeconds) + + self.step(16) + # TH_CR2 starts a commissioning process with DUT_CE + await self.CommissionOnNetwork(params3.setupPinCode) + + self.step(17) + # TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command + revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) + + +if __name__ == "__main__": + default_matter_test_main() From e4cbed6989396dcd7e5c297e08703a7219b74ef1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 12 Dec 2024 00:31:58 +0000 Subject: [PATCH 02/17] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_5.py | 58 +++++++++++++++-------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 2b3765043eab0e..1afce12ec8c923 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -57,7 +57,7 @@ async def get_txt_record(self): ) return comm_service - async def OpenCommissioningWindow(self, timeout: int, iteration: int=10000, discriminator: int=1234) -> CommissioningParameters: + async def OpenCommissioningWindow(self, timeout: int, iteration: int = 10000, discriminator: int = 1234) -> CommissioningParameters: try: params = await self.th1.OpenCommissioningWindow( nodeid=self.dut_node_id, timeout=timeout, iteration=iteration, discriminator=self.discriminator, option=1) @@ -84,33 +84,35 @@ def steps_TC_CADMIN_1_5(self) -> list[TestStep]: return [ TestStep(1, "Commissioning, already done", is_commissioning=True), TestStep(2, "TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM"), - TestStep(3, "TH_CR1 finds DUT_CE advertising as a commissionable node on DNS-SD", "Verify that the DNS-SD advertisement TXT record shows CM=2"), - TestStep(4, "TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds", - "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), - TestStep(5, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM", "{resDutSuccess}"), + TestStep(3, "TH_CR1 finds DUT_CE advertising as a commissionable node on DNS-SD", + "Verify that the DNS-SD advertisement TXT record shows CM=2"), + TestStep(4, "TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds", + "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), + TestStep( + 5, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM", "{resDutSuccess}"), TestStep(6, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command", "{resDutSuccess}"), - TestStep(7, "TH_CR2 attempts to start a commissioning process with DUT_CE", - "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), - TestStep(8, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command.", - "Verify this command fails with the cluster specific status code of WindowNotOpen"), - TestStep(9, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096", - "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(10, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999", - "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(11, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001", - "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(12, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short'", - "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(13, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long'", - "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(14, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", - "Verify DUT_CE opens its Commissioning window to allow a second commissioning"), - TestStep(15, "TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", - "Verify DUT_CE fails to open Commissioning window with status code 2 (Busy)"), - TestStep(16, "TH_CR2 starts a commissioning process with DUT_CE", - "Commissioning is successful"), - TestStep(17, "TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command", - "Verify DUT_CE fails to revoke giving status code 4 (WindowNotOpen) as there was no window open"), + TestStep(7, "TH_CR2 attempts to start a commissioning process with DUT_CE", + "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), + TestStep(8, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command.", + "Verify this command fails with the cluster specific status code of WindowNotOpen"), + TestStep(9, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(10, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(11, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(12, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short'", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(13, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long'", + "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), + TestStep(14, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", + "Verify DUT_CE opens its Commissioning window to allow a second commissioning"), + TestStep(15, "TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", + "Verify DUT_CE fails to open Commissioning window with status code 2 (Busy)"), + TestStep(16, "TH_CR2 starts a commissioning process with DUT_CE", + "Commissioning is successful"), + TestStep(17, "TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command", + "Verify DUT_CE fails to revoke giving status code 4 (WindowNotOpen) as there was no window open"), ] def pics_TC_CADMIN_1_5(self) -> list[str]: @@ -140,7 +142,7 @@ async def test_TC_CADMIN_1_5(self): self.step(4) # TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds sleep(190) - #await self.CommissionAttempt(setupPinCode, expectedErrCode=0x03) + # await self.CommissionAttempt(setupPinCode, expectedErrCode=0x03) await self.CommissionOnNetwork(params.setupPinCode) self.step(5) From 631d21678cce52e2d532465364c65a07087d1452 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 12 Dec 2024 00:32:01 +0000 Subject: [PATCH 03/17] Restyled by isort --- src/python_testing/TC_CADMIN_1_5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 1afce12ec8c923..2fe2038f4c4a70 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -38,10 +38,10 @@ from time import sleep import chip.clusters as Clusters +import chip.interaction_model from chip import ChipDeviceCtrl from chip.ChipDeviceCtrl import CommissioningParameters from chip.exceptions import ChipStackError -import chip.interaction_model from chip.native import PyChipError from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mdns_discovery import mdns_discovery From 6acf333cbf14b35c9c6e5733b2747183ca72f3d3 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 12 Dec 2024 08:45:13 -0800 Subject: [PATCH 04/17] Updated TC_CADMIN_1_5 test module: - Updating to resolve some commissioning flow errors. --- src/python_testing/TC_CADMIN_1_5.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 2fe2038f4c4a70..cd2809d1edde0d 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -60,22 +60,23 @@ async def get_txt_record(self): async def OpenCommissioningWindow(self, timeout: int, iteration: int = 10000, discriminator: int = 1234) -> CommissioningParameters: try: params = await self.th1.OpenCommissioningWindow( - nodeid=self.dut_node_id, timeout=timeout, iteration=iteration, discriminator=self.discriminator, option=1) + nodeid=self.dut_node_id, timeout=timeout, iteration=iteration, discriminator=discriminator, option=1) return params except Exception as e: logging.exception('Error running OpenCommissioningWindow %s', e) - asserts.assert_true(False, 'Failed to open commissioning window') + asserts.assert_equal(e.code, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, 'Failed to open commissioning window due to unexpected error') - async def CommissionOnNetwork(self, setup_code: int): + async def CommissionOnNetwork(self, setup_code: int, discriminator: int = 1234): ctx = asserts.assert_raises(ChipStackError) try: with ctx: await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=setup_code, - filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=self.discriminator) + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=discriminator) errcode = PyChipError.from_code(ctx.exception.err) + # Timeout error occurs during step 7 for TH2 due to commissioning window being closed already except ae.CancelledError as e: errcode = e.__cause__ return errcode @@ -88,8 +89,8 @@ def steps_TC_CADMIN_1_5(self) -> list[TestStep]: "Verify that the DNS-SD advertisement TXT record shows CM=2"), TestStep(4, "TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds", "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), - TestStep( - 5, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM", "{resDutSuccess}"), + TestStep(5, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM", + "{resDutSuccess}"), TestStep(6, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command", "{resDutSuccess}"), TestStep(7, "TH_CR2 attempts to start a commissioning process with DUT_CE", "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), @@ -124,7 +125,6 @@ async def test_TC_CADMIN_1_5(self): # Establishing TH1 and TH2 self.th1 = self.default_controller - self.discriminator = random.randint(0, 4095) th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1) self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) @@ -142,7 +142,6 @@ async def test_TC_CADMIN_1_5(self): self.step(4) # TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds sleep(190) - # await self.CommissionAttempt(setupPinCode, expectedErrCode=0x03) await self.CommissionOnNetwork(params.setupPinCode) self.step(5) @@ -151,11 +150,9 @@ async def test_TC_CADMIN_1_5(self): self.step(6) # TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command - try: - revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() - await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) - except chip.interaction_model.InteractionModelError as e: - self.print_step("interaction model error", dir(e)) + revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) + sleep(1) self.step(7) # TH_CR2 attempts to start a commissioning process with DUT_CE @@ -167,8 +164,9 @@ async def test_TC_CADMIN_1_5(self): revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) except chip.interaction_model.InteractionModelError as e: - asserts.assert_true(e.clusterStatus, 4, "Cluster status must be 4 to pass this step") - + asserts.assert_true(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, + "Cluster status must be 4 to pass this step as window should be reported as not open") + self.step(9) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096 await self.OpenCommissioningWindow(timeout=180, discriminator=4096) From 1778ecd2c3062ecaa5e8980c477f76adaab82c41 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 12 Dec 2024 16:47:54 +0000 Subject: [PATCH 05/17] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_5.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index cd2809d1edde0d..5a612e847d75cf 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -65,7 +65,8 @@ async def OpenCommissioningWindow(self, timeout: int, iteration: int = 10000, di except Exception as e: logging.exception('Error running OpenCommissioningWindow %s', e) - asserts.assert_equal(e.code, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, 'Failed to open commissioning window due to unexpected error') + asserts.assert_equal(e.code, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, + 'Failed to open commissioning window due to unexpected error') async def CommissionOnNetwork(self, setup_code: int, discriminator: int = 1234): ctx = asserts.assert_raises(ChipStackError) @@ -89,8 +90,8 @@ def steps_TC_CADMIN_1_5(self) -> list[TestStep]: "Verify that the DNS-SD advertisement TXT record shows CM=2"), TestStep(4, "TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds", "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), - TestStep(5, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM", - "{resDutSuccess}"), + TestStep(5, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM", + "{resDutSuccess}"), TestStep(6, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command", "{resDutSuccess}"), TestStep(7, "TH_CR2 attempts to start a commissioning process with DUT_CE", "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), @@ -164,9 +165,9 @@ async def test_TC_CADMIN_1_5(self): revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) except chip.interaction_model.InteractionModelError as e: - asserts.assert_true(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, + asserts.assert_true(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, "Cluster status must be 4 to pass this step as window should be reported as not open") - + self.step(9) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096 await self.OpenCommissioningWindow(timeout=180, discriminator=4096) From d002260f8ab40b035942ed4cd971fe53368a8018 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 12 Dec 2024 09:04:52 -0800 Subject: [PATCH 06/17] Updating TC_CADMIN_1_5 test module: - Resolving linting errors --- src/python_testing/TC_CADMIN_1_5.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 5a612e847d75cf..8f5a16ea302236 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -31,10 +31,8 @@ # quiet: false # === END CI TEST ARGUMENTS === -import asyncio import asyncio.exceptions as ae import logging -import random from time import sleep import chip.clusters as Clusters From f80951c2796e25b55bf789b1bcf1bfa964e29ff8 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 12 Dec 2024 09:06:49 -0800 Subject: [PATCH 07/17] Removing Test_TC_CADMIN_1_5 yaml: - Removing as will be no longer needed once python module is functioning --- .../certification/Test_TC_CADMIN_1_5.yaml | 614 ------------------ 1 file changed, 614 deletions(-) delete mode 100644 src/app/tests/suites/certification/Test_TC_CADMIN_1_5.yaml diff --git a/src/app/tests/suites/certification/Test_TC_CADMIN_1_5.yaml b/src/app/tests/suites/certification/Test_TC_CADMIN_1_5.yaml deleted file mode 100644 index 8efb3b86885c5e..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_CADMIN_1_5.yaml +++ /dev/null @@ -1,614 +0,0 @@ -# Copyright (c) 2023 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -name: - 24.1.5. [TC-CADMIN-1.5] Commissioning window handling timeout and revocation - using ECM [DUT_CE - Commissionee] - -PICS: - - CADMIN.S - -config: - nodeId: 0x12344321 - timeout: 300 - nodeIdForDuplicateCommissioning: - type: node_id - defaultValue: 0x11 - nodeId2: - type: node_id - defaultValue: 0xCAFE - nodeId3: - type: node_id - defaultValue: 0xC00FEE - endpoint: 0 - waitAfterCommissioning: - type: int16u - defaultValue: 5000 - discriminator: - type: int16u - defaultValue: 3840 - payload: - type: char_string - defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically - PakeVerifier: - type: octet_string - defaultValue: "hex:b96170aae803346884724fe9a3b287c30330c2a660375d17bb205a8cf1aecb350457f8ab79ee253ab6a8e46bb09e543ae422736de501e3db37d441fe344920d09548e4c18240630c4ff4913c53513839b7c07fcc0627a1b8573a149fcd1fa466cf" - IncorrectPakeVerifier: - type: octet_string - defaultValue: "hex:06c756dffcd722653452a12dcd945d8c54da2b0f3cbd1b4dc3f1adb223aeb26b047cd24c96866f979b1d83ec50e2b4ae30cdf2fdb32bd8a211b837dc94edcd56f4d14377191076bfc59d99b7dd3053efd6f02c4434f2bdd27a" - PIXIT.CADMIN.CwDuration: - type: int16u - defaultValue: 180 - -tests: - - label: "Precondition: Reset Devices to factory defaults" - PICS: PICS_SDK_CI_ONLY - cluster: "SystemCommands" - command: "FactoryReset" - - - label: "Precondition: Reset Devices to factory defaults" - verification: | - Reset Devices to factory defaults - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP - arguments: - values: - - name: "message" - value: "Factory Reset the DUT and enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 1a: TH_CR1 starts a commissioning process with DUT_CE" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId - - name: "payload" - value: payload - - - label: "Step 1b: TH_CR1 commissioned with DUT_CE" - cluster: "DelayCommands" - command: "WaitForCommissionee" - PICS: CADMIN.S - arguments: - values: - - name: "nodeId" - value: nodeId - - - label: - "Step 2: TH_CR1 opens a new commissioning window on DUT_CE using ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: PakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: - "Step 2: TH_CR1 opens a commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - verification: | - On TH_CR1 send the below command - - ./chip-tool pairing open-commissioning-window 1 1 PIXIT.CADMIN.CwDuration 1000 3841 - - Verify the Open commisioning window on the DUT_CE(all-cluster-app) Log: - - [1660904553.796857][3537:3537] CHIP:DMG: Received command for Endpoint=0 Cluster=0x0000_003C Command=0x0000_0000 - [1660904553.796951][3537:3537] CHIP:ZCL: Received command to open commissioning window - [1660904553.797255][3537:3537] CHIP:IN: SecureSession[0xaaab142ef7f0]: Allocated Type:1 LSID:34523 - - Verify the Manual pairing code on the TH_CR1(chip-tool) Log: - - [1635864513.699433][3850:3855] CHIP:DMG: ICR moving to [CommandSen] - [1635864513.699489][3850:3855] CHIP:CTL: Manual pairing code: [36177160937] - [1635864513.699566][3850:3855] CHIP:CTL: SetupQRCode: [MT:00000CQM00YZN476420] - [1635864513.699636][3850:3855] CHIP:EM: Sending Standalone Ack for MessageCounter:2599714227 on exchange 60688i - [1635864513.699685][3850:3855] CHIP:IN: Prepared plaintext message 0xffff8a7cd960 to 0x0000000000000000 of type - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "Step 3: DNS-SD records shows DUT_CE advertising. Verify that the - DNS-SD advertisement shows CM=2" - PICS: CADMIN.S.C00.Rsp - cluster: "DiscoveryCommands" - command: "FindCommissionable" - response: - values: - - name: "commissioningMode" - value: 2 - - - label: "Step 4a: Wait for PIXIT.CADMIN.CwDuration + 10 seconds" - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: ( PIXIT.CADMIN.CwDuration + 10 ) * 1000 - - - label: "Step 4b: TH_CR2 starts a commissioning process with DUT_CE" - identity: "beta" - cluster: "CommissionerCommands" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - command: "PairWithCode" - arguments: - values: - - name: "nodeId" - value: nodeId2 - - name: "payload" - value: payload - response: - error: FAILURE - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: "Step 4b: TH_CR2 starts a commissioning process with DUT_CE" - verification: | - On TH_CR2 send the below command - Below is the example when using chip tool as controller (considering 36177160937 as the manual code generated by 1st controller) - - ./chip-tool pairing code 0xCAFE 36177160937 --commissioner-name beta - - Verify the below message in the TH_CR2(chip-tool) Log: - - [1663841939.843550][13897:13897] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0) - [1663841939.843617][13897:13897] CHIP:DL: Inet Layer shutdown - [1663841939.843673][13897:13897] CHIP:DL: BLE Layer shutdown - [1663841939.843727][13897:13897] CHIP:DL: System Layer shutdown - [1663841939.844009][13897:13897] CHIP:TOO: Run command failure: ../../examples/chip-tool/commands/pairing/PairingCommand.cpp:151: CHIP Error 0x00000003: Incorrect state - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "Ste 5: TH_CR1 opens a new commissioning window on DUT_CE using ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: PakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: - "Step 5: TH_CR1 opens a new commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - verification: | - On TH_CR1 send the below command - - ./chip-tool pairing open-commissioning-window 1 1 PIXIT.CADMIN.CwDuration 2000 3840 - - Verify the Open commisioning window on the DUT_CE(all-cluster-app) Log: - - [1660904553.796857][3537:3537] CHIP:DMG: Received command for Endpoint=0 Cluster=0x0000_003C Command=0x0000_0000 - [1660904553.796951][3537:3537] CHIP:ZCL: Received command to open commissioning window - [1660904553.797255][3537:3537] CHIP:IN: SecureSession[0xaaab142ef7f0]: Allocated Type:1 LSID:34523 - - Verify the Manual pairing code on the TH_CR1(chip-tool) Log: - - [1635864513.699433][3850:3855] CHIP:DMG: ICR moving to [CommandSen] - [1635864513.699489][3850:3855] CHIP:CTL: Manual pairing code: [36177160937] - [1635864513.699566][3850:3855] CHIP:CTL: SetupQRCode: [MT:00000CQM00YZN476420] - [1635864513.699636][3850:3855] CHIP:EM: Sending Standalone Ack for MessageCounter:2599714227 on exchange 60688i - [1635864513.699685][3850:3855] CHIP:IN: Prepared plaintext message 0xffff8a7cd960 to 0x0000000000000000 of type 0x10 - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Waiting after opening commissioning window" - PICS: PICS_SDK_CI_ONLY && CADMIN.S.C00.Rsp - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: waitAfterCommissioning - - - label: "Step 6: TH_CR1 revokes the commissioning window on DUT_CE" - cluster: "Administrator Commissioning" - command: "RevokeCommissioning" - PICS: CADMIN.S.C02.Rsp - timedInteractionTimeoutMs: 10000 - - - label: "Step 7: TH_CR2 starts a commissioning process with DUT_CE" - identity: "beta" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S && PICS_SDK_CI_ONLY - arguments: - values: - - name: "nodeId" - value: nodeId2 - - name: "payload" - value: payload - response: - error: FAILURE - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: "Step 7: TH_CR2 starts a commissioning process with DUT_CE" - verification: | - On TH_CR2 send the below command - Below is the example when using chip tool as controller (considering 36177160937 as the manual code generated by 1st controller) - - ./chip-tool pairing code 0xCAFE 36177160937 --commissioner-name beta - - Verify the below message in the TH_CR2(chip-tool) Log: - - Device commissioning completed with successoning step 'Cleanup' - [1657186359.584743][3509:3514] CHIP:TOO: Device commissioning completed with success - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 8: TH_CR1 revokes the commissioning window on DUT_CE" - cluster: "Administrator Commissioning" - command: "RevokeCommissioning" - PICS: CADMIN.S.C02.Rsp - timedInteractionTimeoutMs: 10000 - response: - error: FAILURE - - - label: - "Step 9a: TH_CR1 writes the mandatory attribute NodeLabel of DUT_CE" - cluster: "Basic Information" - command: "writeAttribute" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - arguments: - value: "chiptest" - - - label: "Step 9b: TH_CR1 read the mandatory attribute NodeLabel of DUT_CE" - cluster: "Basic Information" - command: "readAttribute" - attribute: "NodeLabel" - PICS: BINFO.S.A0005 - response: - value: "chiptest" - - - label: - "Step 10: TH_CR1 opens a new commissioning window on DUT_CE using - wrong PakeVerifier value using ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: IncorrectPakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - response: - error: FAILURE - clusterError: 3 - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: - "Step 10: TH_CR1 opens a commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - verification: | - On TH_CR1 send the below command - Below is example command by considering the "\x06\xc7\x56\xdf\xfc\xd7\x22\x65\x34\x52\xa1\x2d\xcd\x94\x5d\x8c\x54\xda\x2b\x0f\x3c\xbd\x1b\x4d\xc3\xf1\xad\xb2\x23\xae\xb2\x6b\x04\x7c\xd2\x4c\x96\x86\x6f\x97\x9b\x1d\x83\xec\x50\xe2\xb4\xae\x30\xcd\xf2\xfd\xb3\x2b\xd8\xa2\x11\xb8\x37\xdc\x94\xed\xcd\x56\xf4\xd1\x43\x77\x19\x10\x76\xbf\xc5\x9d\x99\xb7\xdd\x30\x53\xef\xd6\xf0\x2c\x44\x34\xf2\xbd " as a wrong PakeVerifier value - - - ./chip-tool administratorcommissioning open-commissioning-window PIXIT.CADMIN.CwDuration \x06\xc7\x56\xdf\xfc\xd7\x22\x65\x34\x52\xa1\x2d\xcd\x94\x5d\x8c\x54\xda\x2b\x0f\x3c\xbd\x1b\x4d\xc3\xf1\xad\xb2\x23\xae\xb2\x6b\x04\x7c\xd2\x4c\x96\x86\x6f\x97\x9b\x1d\x83\xec\x50\xe2\xb4\xae\x30\xcd\xf2\xfd\xb3\x2b\xd8\xa2\x11\xb8\x37\xdc\x94\xed\xcd\x56\xf4\xd1\x43\x77\x19\x10\x76\xbf\xc5\x9d\x99\xb7\xdd\x30\x53\xef\xd6\xf0\x2c\x44\x34\xf2\xbd 3841 1000 16 0x12344321 0 --timedInteractionTimeoutMs 1000 - - Verify the status on the TH_CR1(chip-tool) Log: - - [1656434435.691038][3836:3842] CHIP:DMG: { - [1656434435.691119][3836:3842] CHIP:DMG: EndpointId = 0x0, - [1656434435.691287][3836:3842] CHIP:DMG: ClusterId = 0x3c, - [1656434435.691377][3836:3842] CHIP:DMG: CommandId = 0x0, - [1656434435.691456][3836:3842] CHIP:DMG: }, - [1656434435.691548][3836:3842] CHIP:DMG: - [1656434435.691620][3836:3842] CHIP:DMG: StatusIB = - [1656434435.691707][3836:3842] CHIP:DMG: { - [1656434435.691788][3836:3842] CHIP:DMG: status = 0x01 (FAILURE), - [1656434435.691874][3836:3842] CHIP:DMG: cluster-status = 0x3, - [1656434435.691954][3836:3842] CHIP:DMG: }, - [1656434435.692041][3836:3842] CHIP:DMG: - [1656434435.692112][3836:3842] CHIP:DMG: }, - [1656434435.692191][3836:3842] CHIP:DMG: - [1656434435.692257][3836:3842] CHIP:DMG: }, - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "Step 11: TH_CR1 opens a new commissioning window on DUT_CE using ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: PakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - - - label: "Waiting after opening commissioning window" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - cluster: "DelayCommands" - command: "WaitForMs" - arguments: - values: - - name: "ms" - value: waitAfterCommissioning - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: - "Step 11: TH_CR1 opens a commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - verification: | - On TH_CR1 send the below command - - ./chip-tool pairing open-commissioning-window 1 1 PIXIT.CADMIN.CwDuration 1000 3841 - - Verify the Open commisioning window on the DUT_CE(all-cluster-app) Log: - - [1660904553.796857][3537:3537] CHIP:DMG: Received command for Endpoint=0 Cluster=0x0000_003C Command=0x0000_0000 - [1660904553.796951][3537:3537] CHIP:ZCL: Received command to open commissioning window - [1660904553.797255][3537:3537] CHIP:IN: SecureSession[0xaaab142ef7f0]: Allocated Type:1 LSID:34523 - - Verify the Manual pairing code on the TH_CR1(chip-tool) Log: - - [1635864513.699433][3850:3855] CHIP:DMG: ICR moving to [CommandSen] - [1635864513.699489][3850:3855] CHIP:CTL: Manual pairing code: [36177160937] - [1635864513.699566][3850:3855] CHIP:CTL: SetupQRCode: [MT:00000CQM00YZN476420] - [1635864513.699636][3850:3855] CHIP:EM: Sending Standalone Ack for MessageCounter:2599714227 on exchange 60688i - [1635864513.699685][3850:3855] CHIP:IN: Prepared plaintext message 0xffff8a7cd960 to 0x0000000000000000 of type - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "Step 12: TH_CR1 opens another commissioning window on DUT_CE using - ECM" - cluster: "Administrator Commissioning" - command: "OpenCommissioningWindow" - PICS: CADMIN.S.C00.Rsp && PICS_SDK_CI_ONLY - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "CommissioningTimeout" - value: PIXIT.CADMIN.CwDuration - - name: "PAKEPasscodeVerifier" - value: PakeVerifier - - name: "Discriminator" - value: discriminator - - name: "Iterations" - value: 1000 - - name: "Salt" - value: "SPAKE2P Key Salt" - response: - error: FAILURE - clusterError: 2 - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: - "Step 13: TH_CR1 opens a commissioning window on DUT_CE using a - commissioning timeout of PIXIT.CADMIN.CwDuration seconds using ECM" - verification: | - On TH_CR1 send the below command - - ./chip-tool pairing open-commissioning-window 1 1 200 1000 3840 - - Verify that the DUT_CE is rejecting the opening of second commissioning session with the response status 0x01 failure - - [1656405166.756822][5933:5938] CHIP:DMG: { - [1656405166.756927][5933:5938] CHIP:DMG: EndpointId = 0x0, - [1656405166.757033][5933:5938] CHIP:DMG: ClusterId = 0x3c, - [1656405166.757120][5933:5938] CHIP:DMG: CommandId = 0x0, - [1656405166.757222][5933:5938] CHIP:DMG: }, - [1656405166.757333][5933:5938] CHIP:DMG: - [1656405166.757452][5933:5938] CHIP:DMG: StatusIB = - [1656405166.757557][5933:5938] CHIP:DMG: { - [1656405166.757641][5933:5938] CHIP:DMG: status = 0x01 (FAILURE), - [1656405166.757745][5933:5938] CHIP:DMG: cluster-status = 0x2, - [1656405166.757846][5933:5938] CHIP:DMG: }, - [1656405166.757929][5933:5938] CHIP:DMG: - [1656405166.758014][5933:5938] CHIP:DMG: }, - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Step 13a: TH_CR2 starts a commissioning process with DUT_CE" - PICS: CADMIN.S && PICS_SDK_CI_ONLY - identity: "beta" - cluster: "CommissionerCommands" - command: "PairWithCode" - arguments: - values: - - name: "nodeId" - value: nodeId2 - - name: "payload" - value: payload - - - label: "Step 13b: DUT_CE is commissioned by TH_CR2" - identity: "beta" - cluster: "DelayCommands" - command: "WaitForCommissionee" - PICS: CADMIN.S && PICS_SDK_CI_ONLY - arguments: - values: - - name: "nodeId" - value: nodeId2 - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: "Step 13: TH_CR2 starts a commissioning process with DUT_CE" - verification: | - On TH_CR2 send the below command - Below is the example when using chip tool as controller (considering 36177160937 as the manual code generated by 1st controller) - - ./chip-tool pairing code 0xCAFE 36177160937 --commissioner-name beta - - Verify the below message in the TH_CR2(chip-tool) Log: - Device commissioning completed with success - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: - "TH2 reads CurrentFabricIndex attribute and save it for future use." - identity: "beta" - command: "readAttribute" - cluster: "Operational Credentials" - attribute: "CurrentFabricIndex" - response: - saveAs: TH2FabricIndex - - - label: - "Step 14: TH_CR1 tries to revoke the commissioning window on DUT_CE - using RevokeCommissioning command" - cluster: "Administrator Commissioning" - command: "RevokeCommissioning" - PICS: CADMIN.S.C02.Rsp - timedInteractionTimeoutMs: 10000 - response: - error: FAILURE - clusterError: 4 - - - label: "Step 15: TH_CR3 starts a commissioning process with DUT_CE" - identity: "gamma" - cluster: "CommissionerCommands" - command: "PairWithCode" - PICS: CADMIN.S && PICS_SDK_CI_ONLY - arguments: - values: - - name: "nodeId" - value: nodeId3 - - name: "payload" - value: payload - response: - error: FAILURE - - #Issue https://github.com/project-chip/connectedhomeip/issues/26127 - - label: "Step 15: TH_CR2 starts a commissioning process with DUT_CE" - verification: | - On TH_CR2 send the below command - Below is the example when using chip tool as controller (considering 36177160937 as the manual code generated by 1st controller) - - ./chip-tool pairing code 0xCAFE 36177160937 --commissioner-name beta - - verify you got the following message in the TH_CR3(chip-tool) log - CHIP:SC: PASESession timed out while waiting for a response from the peer. Expected message type was 33 - CHIP:TOO: Secure Pairing Failed - CHIP:TOO: Pairing Failure: ../../third_party/connectedhomeip/src/protocols/secure_channel/PASESession.cpp:324: CHIP Error 0x00000032: Timeout - cluster: "LogCommands" - command: "UserPrompt" - PICS: PICS_SKIP_SAMPLE_APP && CADMIN.S.C00.Rsp - arguments: - values: - - name: "message" - value: "Enter 'y' after success" - - name: "expectedValue" - value: "y" - - - label: "Remove TH2 FabricIndex" - PICS: OPCREDS.S.C0a.Rsp && CADMIN.S - identity: "beta" - cluster: "Operational Credentials" - command: "RemoveFabric" - timedInteractionTimeoutMs: 10000 - arguments: - values: - - name: "FabricIndex" - value: TH2FabricIndex From 06e603380257fe7823014e02e3f2933d991c53b1 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 12 Dec 2024 21:30:26 -0800 Subject: [PATCH 08/17] Updated TC_CADMIN_1_5 test module: - Changed to using self.SendCommand() for OpenCommissioningWindow in order to use salt and PakeVerifier for commissioning flow. --- src/python_testing/TC_CADMIN_1_5.py | 86 +++++++++++++++++++---------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 8f5a16ea302236..fc39e83fe4e001 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -55,18 +55,7 @@ async def get_txt_record(self): ) return comm_service - async def OpenCommissioningWindow(self, timeout: int, iteration: int = 10000, discriminator: int = 1234) -> CommissioningParameters: - try: - params = await self.th1.OpenCommissioningWindow( - nodeid=self.dut_node_id, timeout=timeout, iteration=iteration, discriminator=discriminator, option=1) - return params - - except Exception as e: - logging.exception('Error running OpenCommissioningWindow %s', e) - asserts.assert_equal(e.code, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, - 'Failed to open commissioning window due to unexpected error') - - async def CommissionOnNetwork(self, setup_code: int, discriminator: int = 1234): + async def CommissionOnNetwork(self, setup_code: int, discriminator: int): ctx = asserts.assert_raises(ChipStackError) try: with ctx: @@ -109,8 +98,7 @@ def steps_TC_CADMIN_1_5(self) -> list[TestStep]: "Verify DUT_CE opens its Commissioning window to allow a second commissioning"), TestStep(15, "TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", "Verify DUT_CE fails to open Commissioning window with status code 2 (Busy)"), - TestStep(16, "TH_CR2 starts a commissioning process with DUT_CE", - "Commissioning is successful"), + TestStep(16, "TH_CR2 starts a commissioning process with DUT_CE", "Commissioning is successful"), TestStep(17, "TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command", "Verify DUT_CE fails to revoke giving status code 4 (WindowNotOpen) as there was no window open"), ] @@ -130,7 +118,7 @@ async def test_TC_CADMIN_1_5(self): self.step(2) # TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM - params = await self.OpenCommissioningWindow(timeout=180) + params = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=180, node_id=self.dut_node_id) self.step(3) # TH_CR1 finds DUT_CE advertising as a commissionable node on DNS-SD @@ -141,11 +129,11 @@ async def test_TC_CADMIN_1_5(self): self.step(4) # TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds sleep(190) - await self.CommissionOnNetwork(params.setupPinCode) + await self.CommissionOnNetwork(setup_code=params.commissioningParameters.setupPinCode, discriminator=params.randomDiscriminator) self.step(5) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM - params2 = await self.OpenCommissioningWindow(timeout=180) + params2 = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=180, node_id=self.dut_node_id) self.step(6) # TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command @@ -155,7 +143,7 @@ async def test_TC_CADMIN_1_5(self): self.step(7) # TH_CR2 attempts to start a commissioning process with DUT_CE - await self.CommissionOnNetwork(params2.setupPinCode) + await self.CommissionOnNetwork(setup_code=params2.commissioningParameters.setupPinCode, discriminator=params2.randomDiscriminator) self.step(8) # TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command. @@ -166,46 +154,86 @@ async def test_TC_CADMIN_1_5(self): asserts.assert_true(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, "Cluster status must be 4 to pass this step as window should be reported as not open") + EcmPakeVerifier = b"hex:d0e8a02db8629e9d172dfd40719c89204ff395651a6a2612839a71469880ec2404687d05cf0642b91242c712b5405b6905070c2a4bd80bdc8437ae5a2aded0cf3de91318d16f0ce9450d1c802cc01f39b8761de87cc7eeeb7f52b51308353da49a" self.step(9) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096 - await self.OpenCommissioningWindow(timeout=180, discriminator=4096) + try: + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=10000, discriminator=4096, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) + except chip.interaction_model.InteractionModelError as e: + logging.exception('Error running OpenCommissioningWindow %s', e) + self.print_step("interaction model error dir", dir(e)) + self.print_step("interaction model error status", e.status) + asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(10) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999 - await self.OpenCommissioningWindow(timeout=180, iteration=999) + try: + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=999, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) + except chip.interaction_model.InteractionModelError as e: + asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(11) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001 - await self.OpenCommissioningWindow(timeout=180, iteration=100001) + try: + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=100001, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) + except chip.interaction_model.InteractionModelError as e: + asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(12) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short' - await self.OpenCommissioningWindow(timeout=180, salt="too_short") + try: + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"too_short") + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) + except chip.interaction_model.InteractionModelError as e: + asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(13) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long' - await self.OpenCommissioningWindow(timeout=180, salt="'this pake salt very very very long'") + try: + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"'this pake salt very very very long'") + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) + except chip.interaction_model.InteractionModelError as e: + asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(14) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM cluster = Clusters.GeneralCommissioning attribute = cluster.Attributes.BasicCommissioningInfo duration = await self.read_single_attribute_check_success(endpoint=0, cluster=cluster, attribute=attribute) - params2 = await self.OpenCommissioningWindow(timeout=duration.maxCumulativeFailsafeSeconds) + params3 = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=duration.maxCumulativeFailsafeSeconds, node_id=self.dut_node_id) self.step(15) # TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM - params3 = await self.OpenCommissioningWindow(timeout=duration.maxCumulativeFailsafeSeconds) + try: + await self.open_commissioning_window(dev_ctrl=self.th1, timeout=duration.maxCumulativeFailsafeSeconds, node_id=self.dut_node_id) + except chip.exceptions.ChipStackError as e: + # Converting error code to useable format to do assert with + code = int(((e.msg.split(":"))[2]), 16) + asserts.assert_equal(code, Clusters.AdministratorCommissioning.Enums.StatusCode.kBusy, + f'Failed to open commissioning window due to an unexpected error code of {e.code}') self.step(16) # TH_CR2 starts a commissioning process with DUT_CE - await self.CommissionOnNetwork(params3.setupPinCode) + await self.th2.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=params3.commissioningParameters.setupPinCode, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params3.randomDiscriminator) self.step(17) # TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command - revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() - await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) - + try: + revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) + except chip.interaction_model.InteractionModelError as e: + asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') if __name__ == "__main__": default_matter_test_main() From 16a099e7916f051ccb92774f97c399f1dd2e3c39 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 13 Dec 2024 05:32:59 +0000 Subject: [PATCH 09/17] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_5.py | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index fc39e83fe4e001..a3e294e4ea0063 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -158,50 +158,55 @@ async def test_TC_CADMIN_1_5(self): self.step(9) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096 try: - cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=10000, discriminator=4096, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( + iterations=10000, discriminator=4096, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) except chip.interaction_model.InteractionModelError as e: logging.exception('Error running OpenCommissioningWindow %s', e) self.print_step("interaction model error dir", dir(e)) self.print_step("interaction model error status", e.status) asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, - f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(10) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999 try: - cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=999, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( + iterations=999, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) except chip.interaction_model.InteractionModelError as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, - f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(11) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001 try: - cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=100001, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( + iterations=100001, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) except chip.interaction_model.InteractionModelError as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, - f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(12) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short' try: - cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"too_short") + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( + iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"too_short") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) except chip.interaction_model.InteractionModelError as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, - f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(13) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long' try: - cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow(iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"'this pake salt very very very long'") + cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( + iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"'this pake salt very very very long'") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) except chip.interaction_model.InteractionModelError as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, - f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(14) # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM @@ -218,7 +223,7 @@ async def test_TC_CADMIN_1_5(self): # Converting error code to useable format to do assert with code = int(((e.msg.split(":"))[2]), 16) asserts.assert_equal(code, Clusters.AdministratorCommissioning.Enums.StatusCode.kBusy, - f'Failed to open commissioning window due to an unexpected error code of {e.code}') + f'Failed to open commissioning window due to an unexpected error code of {e.code}') self.step(16) # TH_CR2 starts a commissioning process with DUT_CE @@ -233,7 +238,8 @@ async def test_TC_CADMIN_1_5(self): await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) except chip.interaction_model.InteractionModelError as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, - f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + if __name__ == "__main__": default_matter_test_main() From 0bc2b1d41f753facffb6c068e6ed753e989901f7 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Thu, 12 Dec 2024 22:15:32 -0800 Subject: [PATCH 10/17] Updating TC_CADMIN_1_5 test module: - Resolving linting errors --- src/python_testing/TC_CADMIN_1_5.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index a3e294e4ea0063..2efec56518f6d1 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -28,7 +28,7 @@ # --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto # --PICS src/app/tests/suites/certification/ci-pics-values # factory-reset: true -# quiet: false +# quiet: true # === END CI TEST ARGUMENTS === import asyncio.exceptions as ae @@ -38,7 +38,6 @@ import chip.clusters as Clusters import chip.interaction_model from chip import ChipDeviceCtrl -from chip.ChipDeviceCtrl import CommissioningParameters from chip.exceptions import ChipStackError from chip.native import PyChipError from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main @@ -109,7 +108,6 @@ def pics_TC_CADMIN_1_5(self) -> list[str]: @async_test_body async def test_TC_CADMIN_1_5(self): self.step(1) - # Establishing TH1 and TH2 self.th1 = self.default_controller th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() @@ -117,36 +115,29 @@ async def test_TC_CADMIN_1_5(self): self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) self.step(2) - # TH_CR1 opens a commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM params = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=180, node_id=self.dut_node_id) self.step(3) - # TH_CR1 finds DUT_CE advertising as a commissionable node on DNS-SD services = await self.get_txt_record() if services.txt_record['CM'] != "2": asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") self.step(4) - # TH_CR2 attempts to start a commissioning process with DUT_CE after 190 seconds sleep(190) await self.CommissionOnNetwork(setup_code=params.commissioningParameters.setupPinCode, discriminator=params.randomDiscriminator) self.step(5) - # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM params2 = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=180, node_id=self.dut_node_id) self.step(6) - # TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) sleep(1) self.step(7) - # TH_CR2 attempts to start a commissioning process with DUT_CE await self.CommissionOnNetwork(setup_code=params2.commissioningParameters.setupPinCode, discriminator=params2.randomDiscriminator) self.step(8) - # TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command. try: revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) @@ -154,22 +145,18 @@ async def test_TC_CADMIN_1_5(self): asserts.assert_true(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, "Cluster status must be 4 to pass this step as window should be reported as not open") - EcmPakeVerifier = b"hex:d0e8a02db8629e9d172dfd40719c89204ff395651a6a2612839a71469880ec2404687d05cf0642b91242c712b5405b6905070c2a4bd80bdc8437ae5a2aded0cf3de91318d16f0ce9450d1c802cc01f39b8761de87cc7eeeb7f52b51308353da49a" self.step(9) - # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096 + EcmPakeVerifier = b"hex:d0e8a02db8629e9d172dfd40719c89204ff395651a6a2612839a71469880ec2404687d05cf0642b91242c712b5405b6905070c2a4bd80bdc8437ae5a2aded0cf3de91318d16f0ce9450d1c802cc01f39b8761de87cc7eeeb7f52b51308353da49a" try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=10000, discriminator=4096, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) except chip.interaction_model.InteractionModelError as e: logging.exception('Error running OpenCommissioningWindow %s', e) - self.print_step("interaction model error dir", dir(e)) - self.print_step("interaction model error status", e.status) asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(10) - # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999 try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=999, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") @@ -179,7 +166,6 @@ async def test_TC_CADMIN_1_5(self): f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(11) - # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001 try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=100001, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") @@ -189,7 +175,6 @@ async def test_TC_CADMIN_1_5(self): f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(12) - # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short' try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"too_short") @@ -199,7 +184,6 @@ async def test_TC_CADMIN_1_5(self): f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(13) - # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long' try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"'this pake salt very very very long'") @@ -209,14 +193,12 @@ async def test_TC_CADMIN_1_5(self): f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') self.step(14) - # TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM cluster = Clusters.GeneralCommissioning attribute = cluster.Attributes.BasicCommissioningInfo duration = await self.read_single_attribute_check_success(endpoint=0, cluster=cluster, attribute=attribute) params3 = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=duration.maxCumulativeFailsafeSeconds, node_id=self.dut_node_id) self.step(15) - # TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM try: await self.open_commissioning_window(dev_ctrl=self.th1, timeout=duration.maxCumulativeFailsafeSeconds, node_id=self.dut_node_id) except chip.exceptions.ChipStackError as e: @@ -226,13 +208,11 @@ async def test_TC_CADMIN_1_5(self): f'Failed to open commissioning window due to an unexpected error code of {e.code}') self.step(16) - # TH_CR2 starts a commissioning process with DUT_CE await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=params3.commissioningParameters.setupPinCode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params3.randomDiscriminator) self.step(17) - # TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command try: revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) From db6e21250a0bda89ff7cf0457ac034e40e3f701a Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 13 Dec 2024 13:45:02 -0800 Subject: [PATCH 11/17] Updating TC_CADMIN_1_5 test module: - Removing test step 9 --- src/python_testing/TC_CADMIN_1_5.py | 42 +++++++++++------------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 2efec56518f6d1..b632acd6db1854 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -83,22 +83,20 @@ def steps_TC_CADMIN_1_5(self) -> list[TestStep]: "TH_CR2 should fail to commission the DUT since the window should be closed. This may be a failure to find the commissionable node or a failure to establish a PASE connection."), TestStep(8, "TH_CR1 revokes the commissioning window on DUT_CE using RevokeCommissioning command.", "Verify this command fails with the cluster specific status code of WindowNotOpen"), - TestStep(9, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with a discriminator of 4096", + TestStep(9, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999", "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(10, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 999", + TestStep(10, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001", "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(11, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the iterations set to 100001", + TestStep(11, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short'", "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(12, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'too_short'", + TestStep(12, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long'", "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(13, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of 180 seconds using ECM with the salt set to 'this pake salt very very very long'", - "Verify DUT_CE fails to open Commissioning window with status code 3 (PakeParameterError)"), - TestStep(14, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", + TestStep(13, "TH_CR1 opens a new commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", "Verify DUT_CE opens its Commissioning window to allow a second commissioning"), - TestStep(15, "TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", + TestStep(14, "TH_CR1 opens another commissioning window on DUT_CE using a commissioning timeout of {PIXIT_CWDURATION} seconds using ECM", "Verify DUT_CE fails to open Commissioning window with status code 2 (Busy)"), - TestStep(16, "TH_CR2 starts a commissioning process with DUT_CE", "Commissioning is successful"), - TestStep(17, "TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command", + TestStep(15, "TH_CR2 starts a commissioning process with DUT_CE", "Commissioning is successful"), + TestStep(16, "TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command", "Verify DUT_CE fails to revoke giving status code 4 (WindowNotOpen) as there was no window open"), ] @@ -147,16 +145,6 @@ async def test_TC_CADMIN_1_5(self): self.step(9) EcmPakeVerifier = b"hex:d0e8a02db8629e9d172dfd40719c89204ff395651a6a2612839a71469880ec2404687d05cf0642b91242c712b5405b6905070c2a4bd80bdc8437ae5a2aded0cf3de91318d16f0ce9450d1c802cc01f39b8761de87cc7eeeb7f52b51308353da49a" - try: - cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( - iterations=10000, discriminator=4096, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") - await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) - except chip.interaction_model.InteractionModelError as e: - logging.exception('Error running OpenCommissioningWindow %s', e) - asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, - f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') - - self.step(10) try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=999, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") @@ -165,7 +153,7 @@ async def test_TC_CADMIN_1_5(self): asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') - self.step(11) + self.step(10) try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=100001, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") @@ -174,7 +162,7 @@ async def test_TC_CADMIN_1_5(self): asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') - self.step(12) + self.step(11) try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"too_short") @@ -183,7 +171,7 @@ async def test_TC_CADMIN_1_5(self): asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') - self.step(13) + self.step(12) try: cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"'this pake salt very very very long'") @@ -192,13 +180,13 @@ async def test_TC_CADMIN_1_5(self): asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') - self.step(14) + self.step(13) cluster = Clusters.GeneralCommissioning attribute = cluster.Attributes.BasicCommissioningInfo duration = await self.read_single_attribute_check_success(endpoint=0, cluster=cluster, attribute=attribute) params3 = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=duration.maxCumulativeFailsafeSeconds, node_id=self.dut_node_id) - self.step(15) + self.step(14) try: await self.open_commissioning_window(dev_ctrl=self.th1, timeout=duration.maxCumulativeFailsafeSeconds, node_id=self.dut_node_id) except chip.exceptions.ChipStackError as e: @@ -207,12 +195,12 @@ async def test_TC_CADMIN_1_5(self): asserts.assert_equal(code, Clusters.AdministratorCommissioning.Enums.StatusCode.kBusy, f'Failed to open commissioning window due to an unexpected error code of {e.code}') - self.step(16) + self.step(15) await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=params3.commissioningParameters.setupPinCode, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params3.randomDiscriminator) - self.step(17) + self.step(16) try: revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) From cbd12a67d118eb5a6ffd4e44a6e5c158fd31e65a Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 13 Dec 2024 16:03:36 -0800 Subject: [PATCH 12/17] Updating TC_CADMIN_1_5 test module: - Resolving linting error --- src/python_testing/TC_CADMIN_1_5.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index b632acd6db1854..f7d9bd3d75dffc 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -32,7 +32,6 @@ # === END CI TEST ARGUMENTS === import asyncio.exceptions as ae -import logging from time import sleep import chip.clusters as Clusters From 62005e1143d23b619f99aebdfa2d59cae94b26b0 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 3 Jan 2025 04:00:37 -0800 Subject: [PATCH 13/17] Updating TC_CADMIN_1_5 test module: - Removed test commissioner from establishment of TH2 - Added new step to remove TH2 fabric for final step of this test module - Changed CommissionOnNetwork local function name to SnakeCase - Added comment to indicate that the SnakeCase local function expects an error to occur for steps 4 and 7 - Updated SnakeCase function to include expected_error to include error code expected to be noticed during commissioning attempts during test step 7 --- src/python_testing/TC_CADMIN_1_5.py | 58 ++++++++++++++++++----------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index f7d9bd3d75dffc..2b93bd78a1ce8a 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -34,10 +34,10 @@ import asyncio.exceptions as ae from time import sleep -import chip.clusters as Clusters -import chip.interaction_model from chip import ChipDeviceCtrl +import chip.clusters as Clusters from chip.exceptions import ChipStackError +from chip.interaction_model import InteractionModelError as IME from chip.native import PyChipError from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mdns_discovery import mdns_discovery @@ -53,19 +53,26 @@ async def get_txt_record(self): ) return comm_service - async def CommissionOnNetwork(self, setup_code: int, discriminator: int): - ctx = asserts.assert_raises(ChipStackError) - try: - with ctx: + async def SnakeCase(self, setup_code: int, discriminator: int, expected_error: int=0): + # This is expected to error as steps 4 and 7 expects timeout issue or pase connection error to occur due to commissioning window being closed already + if expected_error == 50: + try: await self.th2.CommissionOnNetwork( nodeId=self.dut_node_id, setupPinCode=setup_code, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=discriminator) - errcode = PyChipError.from_code(ctx.exception.err) - # Timeout error occurs during step 7 for TH2 due to commissioning window being closed already - except ae.CancelledError as e: - errcode = e.__cause__ - return errcode + except ChipStackError as e: + asserts.assert_true(int(e.code) == expected_error, + 'Unexpected error code returned from Commissioning Attempt') + + else: + try: + await self.th2.CommissionOnNetwork( + nodeId=self.dut_node_id, setupPinCode=setup_code, + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=discriminator) + + except ae.CancelledError as e: + errcode = e.__cause__ def steps_TC_CADMIN_1_5(self) -> list[TestStep]: return [ @@ -97,6 +104,8 @@ def steps_TC_CADMIN_1_5(self) -> list[TestStep]: TestStep(15, "TH_CR2 starts a commissioning process with DUT_CE", "Commissioning is successful"), TestStep(16, "TH_CR1 tries to revoke the commissioning window on DUT_CE using RevokeCommissioning command", "Verify DUT_CE fails to revoke giving status code 4 (WindowNotOpen) as there was no window open"), + TestStep(17, "TH_CR1 sends the RemoveFabric command to the DUT to remove TH_CR2 fabric", + "TH_CR1 removes TH_CR2 fabric"), ] def pics_TC_CADMIN_1_5(self) -> list[str]: @@ -109,7 +118,7 @@ async def test_TC_CADMIN_1_5(self): self.th1 = self.default_controller th2_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() th2_fabric_admin = th2_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.th1.fabricId + 1) - self.th2 = th2_fabric_admin.NewController(nodeId=2, useTestCommissioner=True) + self.th2 = th2_fabric_admin.NewController(nodeId=2) self.step(2) params = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=180, node_id=self.dut_node_id) @@ -118,10 +127,10 @@ async def test_TC_CADMIN_1_5(self): services = await self.get_txt_record() if services.txt_record['CM'] != "2": asserts.fail(f"Expected cm record value not found, instead value found was {str(services.txt_record['CM'])}") + sleep(190) self.step(4) - sleep(190) - await self.CommissionOnNetwork(setup_code=params.commissioningParameters.setupPinCode, discriminator=params.randomDiscriminator) + await self.SnakeCase(setup_code=params.commissioningParameters.setupPinCode, discriminator=params.randomDiscriminator) self.step(5) params2 = await self.open_commissioning_window(dev_ctrl=self.th1, timeout=180, node_id=self.dut_node_id) @@ -132,13 +141,13 @@ async def test_TC_CADMIN_1_5(self): sleep(1) self.step(7) - await self.CommissionOnNetwork(setup_code=params2.commissioningParameters.setupPinCode, discriminator=params2.randomDiscriminator) + await self.SnakeCase(setup_code=params2.commissioningParameters.setupPinCode, discriminator=params2.randomDiscriminator, expected_error=0x00000032) self.step(8) try: revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) - except chip.interaction_model.InteractionModelError as e: + except IME as e: asserts.assert_true(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, "Cluster status must be 4 to pass this step as window should be reported as not open") @@ -148,7 +157,7 @@ async def test_TC_CADMIN_1_5(self): cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=999, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) - except chip.interaction_model.InteractionModelError as e: + except IME as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') @@ -157,7 +166,7 @@ async def test_TC_CADMIN_1_5(self): cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=100001, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"SPAKE2P_Key_Salt") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) - except chip.interaction_model.InteractionModelError as e: + except IME as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') @@ -166,7 +175,7 @@ async def test_TC_CADMIN_1_5(self): cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"too_short") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) - except chip.interaction_model.InteractionModelError as e: + except IME as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') @@ -175,7 +184,7 @@ async def test_TC_CADMIN_1_5(self): cmd = Clusters.AdministratorCommissioning.Commands.OpenCommissioningWindow( iterations=10000, discriminator=3045, PAKEPasscodeVerifier=EcmPakeVerifier, commissioningTimeout=180, salt=b"'this pake salt very very very long'") await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=cmd, timedRequestTimeoutMs=2000000) - except chip.interaction_model.InteractionModelError as e: + except IME as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kPAKEParameterError, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') @@ -188,7 +197,7 @@ async def test_TC_CADMIN_1_5(self): self.step(14) try: await self.open_commissioning_window(dev_ctrl=self.th1, timeout=duration.maxCumulativeFailsafeSeconds, node_id=self.dut_node_id) - except chip.exceptions.ChipStackError as e: + except ChipStackError as e: # Converting error code to useable format to do assert with code = int(((e.msg.split(":"))[2]), 16) asserts.assert_equal(code, Clusters.AdministratorCommissioning.Enums.StatusCode.kBusy, @@ -203,10 +212,15 @@ async def test_TC_CADMIN_1_5(self): try: revokeCmd = Clusters.AdministratorCommissioning.Commands.RevokeCommissioning() await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=revokeCmd, timedRequestTimeoutMs=6000) - except chip.interaction_model.InteractionModelError as e: + except IME as e: asserts.assert_equal(e.clusterStatus, Clusters.AdministratorCommissioning.Enums.StatusCode.kWindowNotOpen, f'Failed to open commissioning window due to an unexpected error code of {e.clusterStatus}') + self.step(17) + TH2_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=self.th2, endpoint=0, cluster=Clusters.OperationalCredentials, attribute=Clusters.OperationalCredentials.Attributes.CurrentFabricIndex) + removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(TH2_fabric_index) + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) + if __name__ == "__main__": default_matter_test_main() From e12ad2844220d4e97da02c3fed9a69f88c057d5d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 3 Jan 2025 12:04:23 +0000 Subject: [PATCH 14/17] Restyled by autopep8 --- src/python_testing/TC_CADMIN_1_5.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 2b93bd78a1ce8a..04ce4aced9b619 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -53,7 +53,7 @@ async def get_txt_record(self): ) return comm_service - async def SnakeCase(self, setup_code: int, discriminator: int, expected_error: int=0): + async def SnakeCase(self, setup_code: int, discriminator: int, expected_error: int = 0): # This is expected to error as steps 4 and 7 expects timeout issue or pase connection error to occur due to commissioning window being closed already if expected_error == 50: try: @@ -63,7 +63,7 @@ async def SnakeCase(self, setup_code: int, discriminator: int, expected_error: i except ChipStackError as e: asserts.assert_true(int(e.code) == expected_error, - 'Unexpected error code returned from Commissioning Attempt') + 'Unexpected error code returned from Commissioning Attempt') else: try: From f20a42fb59b27fdf0491223e759a8d8409d85df9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 3 Jan 2025 12:04:26 +0000 Subject: [PATCH 15/17] Restyled by isort --- src/python_testing/TC_CADMIN_1_5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 04ce4aced9b619..e3ef1271df05f5 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -34,8 +34,8 @@ import asyncio.exceptions as ae from time import sleep -from chip import ChipDeviceCtrl import chip.clusters as Clusters +from chip import ChipDeviceCtrl from chip.exceptions import ChipStackError from chip.interaction_model import InteractionModelError as IME from chip.native import PyChipError From 9519673e056c130b5ec6f4165fa741035729d3a9 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 3 Jan 2025 13:22:59 -0800 Subject: [PATCH 16/17] Update TC_CADMIN_1_5 test module: - Resolving linting errors --- src/python_testing/TC_CADMIN_1_5.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index e3ef1271df05f5..9cd19a43b78074 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -38,7 +38,6 @@ from chip import ChipDeviceCtrl from chip.exceptions import ChipStackError from chip.interaction_model import InteractionModelError as IME -from chip.native import PyChipError from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main from mdns_discovery import mdns_discovery from mobly import asserts @@ -72,7 +71,8 @@ async def SnakeCase(self, setup_code: int, discriminator: int, expected_error: i filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=discriminator) except ae.CancelledError as e: - errcode = e.__cause__ + # This is expected to fail due to timeout, however there is no code to validate here, so just passing since the correct exception was raised to get to this point + pass def steps_TC_CADMIN_1_5(self) -> list[TestStep]: return [ From 8e2b85001c95ce4cebd17307ede6ff16bbb93667 Mon Sep 17 00:00:00 2001 From: Jake Ororke Date: Fri, 3 Jan 2025 15:04:46 -0800 Subject: [PATCH 17/17] Updating TC_CADMIN_1_5 test module: - Resolving further noticed linting errors --- src/python_testing/TC_CADMIN_1_5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python_testing/TC_CADMIN_1_5.py b/src/python_testing/TC_CADMIN_1_5.py index 9cd19a43b78074..7174a7f3ecc68e 100644 --- a/src/python_testing/TC_CADMIN_1_5.py +++ b/src/python_testing/TC_CADMIN_1_5.py @@ -70,7 +70,7 @@ async def SnakeCase(self, setup_code: int, discriminator: int, expected_error: i nodeId=self.dut_node_id, setupPinCode=setup_code, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=discriminator) - except ae.CancelledError as e: + except ae.CancelledError: # This is expected to fail due to timeout, however there is no code to validate here, so just passing since the correct exception was raised to get to this point pass