diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index adf04727976032..996b8a6178a57c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -549,6 +549,7 @@ jobs: scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_FAN_3_5.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_2_1.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_1.py' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_3.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDManagementCluster.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_2.py' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_4.py' diff --git a/src/app/tests/suites/certification/Test_TC_ICDM_3_3.yaml b/src/app/tests/suites/certification/Test_TC_ICDM_3_3.yaml deleted file mode 100644 index dcf55057b7b9a9..00000000000000 --- a/src/app/tests/suites/certification/Test_TC_ICDM_3_3.yaml +++ /dev/null @@ -1,267 +0,0 @@ -# Copyright (c) 2024 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. -# Auto-generated scripts for harness use only, please review before automation. The endpoints and cluster names are currently set to default - -name: 217.2.4. [TC-ICDM-3.3] Verify UnregisterClient command with DUT as Server - -PICS: - - ICDM.S - - ICDM.S.C00.Rsp - - ICDM.S.C02.Rsp - -config: - nodeId: 0x12344321 - cluster: "Basic Information" - endpoint: 0 - -tests: - - label: "Preconditions" - verification: | - 1.Commission DUT to TH (can be skipped if done in a preceding test). - 2a.TH reads from the DUT the RegisteredClients attribute. - 2b.If list of registered clients is not empty, unregister existing client(s) - 2c.TH reads from the DUT the RegisteredClients attribute. Verify that the DUT response contains empty list of registered clients. - disabled: true - - - label: - "Step 1: TH sends UnregisterClient command with the CheckInNodeID - (CheckInNodeID1)." - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 1 1 0 - - [1702437560.584692][2341:2343] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x8b - [1702437560.584811][2341:2343] CHIP:TOO: Error: IM Error 0x0000058B: General error: 0x8b (NOT_FOUND) - disabled: true - - - label: - "Step 2a: TH sends RegisterClient command. - CheckInNodeID: - registering clients node ID (CheckInNodeID2) - MonitoredSubject: - monitored subject ID (MonitorSubID2) - Key: shared secret between the - client and the ICD (Key2)" - PICS: ICDM.S.C00.Rsp - verification: | - ./chip-tool icdmanagement register-client 2 2 hex:1234567890abcdef1234567890abcdef 1 0 - On TH(chip-tool) verify that DUT responds with status code as success - - [1702437824.926527][2361:2363] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0001 - [1702437824.926625][2361:2363] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Command 0x0000_0001 - [1702437824.926835][2361:2363] CHIP:TOO: RegisterClientResponse: { - [1702437824.926901][2361:2363] CHIP:TOO: ICDCounter: 2124479668 - [1702437824.926955][2361:2363] CHIP:TOO: } - disabled: true - - - label: "Step 2b: TH reads from the DUT the RegisteredClients attribute." - PICS: ICDM.S.A0003 - verification: | - ./chip-tool icdmanagement read registered-clients 1 0 - - On TH(Chip-tool), Verify that the DUT response contains a list of 1 registered client of given CheckInNodeID, MonitoredSubject, and Key - - [1702437846.906320][2364:2366] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Attribute 0x0000_0003 DataVersion: 2633987690 - [1702437846.906504][2364:2366] CHIP:TOO: RegisteredClients: 2 entries - [1702437846.906687][2364:2366] CHIP:TOO: [1]: { - [1702437846.906746][2364:2366] CHIP:TOO: CheckInNodeID: 112233 - [1702437846.906800][2364:2366] CHIP:TOO: MonitoredSubject: 112233 - [1702437846.906880][2364:2366] CHIP:TOO: FabricIndex: 1 - [1702437846.906934][2364:2366] CHIP:TOO: } - [1702437846.907003][2364:2366] CHIP:TOO: [2]: { - [1702437846.907059][2364:2366] CHIP:TOO: CheckInNodeID: 2 - [1702437846.907108][2364:2366] CHIP:TOO: MonitoredSubject: 2 - [1702437846.907160][2364:2366] CHIP:TOO: FabricIndex: 1 - [1702437846.907211][2364:2366] CHIP:TOO: } - disabled: true - - - label: - "Step 3: TH sends UnregisterClient command with the CheckInNodeID - (CheckInNodeID3)." - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 3 1 0 - - [1702437560.584692][2341:2343] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x8b - [1702437560.584811][2341:2343] CHIP:TOO: Error: IM Error 0x0000058B: General error: 0x8b (NOT_FOUND) - disabled: true - - - label: - "Step 4a: Setup the TH such that is has administrator privileges for - the ICDM cluster." - verification: | - chip-tool default has admin privilege - disabled: true - - - label: - "Step 4b: TH sends UnregisterClient command with the CheckInNodeID - (CheckInNodeID2)." - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 2 1 0 - - [1702438116.143490][2387:2389] CHIP:DMG: InvokeResponseMessage = - [1702438116.143590][2387:2389] CHIP:DMG: { - [1702438116.143648][2387:2389] CHIP:DMG: suppressResponse = false, - [1702438116.143877][2387:2389] CHIP:DMG: InvokeResponseIBs = - [1702438116.144238][2387:2389] CHIP:DMG: [ - [1702438116.144308][2387:2389] CHIP:DMG: InvokeResponseIB = - [1702438116.144414][2387:2389] CHIP:DMG: { - [1702438116.144476][2387:2389] CHIP:DMG: CommandStatusIB = - [1702438116.144575][2387:2389] CHIP:DMG: { - [1702438116.144646][2387:2389] CHIP:DMG: CommandPathIB = - [1702438116.144723][2387:2389] CHIP:DMG: { - [1702438116.144825][2387:2389] CHIP:DMG: EndpointId = 0x0, - [1702438116.144911][2387:2389] CHIP:DMG: ClusterId = 0x46, - [1702438116.144993][2387:2389] CHIP:DMG: CommandId = 0x2, - [1702438116.145097][2387:2389] CHIP:DMG: }, - [1702438116.145186][2387:2389] CHIP:DMG: - [1702438116.145278][2387:2389] CHIP:DMG: StatusIB = - [1702438116.145357][2387:2389] CHIP:DMG: { - [1702438116.145457][2387:2389] CHIP:DMG: status = 0x00 (SUCCESS), - [1702438116.145538][2387:2389] CHIP:DMG: }, - [1702438116.145616][2387:2389] CHIP:DMG: - [1702438116.145683][2387:2389] CHIP:DMG: }, - [1702438116.145782][2387:2389] CHIP:DMG: - [1702438116.145846][2387:2389] CHIP:DMG: }, - [1702438116.145917][2387:2389] CHIP:DMG: - [1702438116.146004][2387:2389] CHIP:DMG: ], - [1702438116.146078][2387:2389] CHIP:DMG: - [1702438116.146155][2387:2389] CHIP:DMG: InteractionModelRevision = 11 - [1702438116.146213][2387:2389] CHIP:DMG: }, - [1702438116.146382][2387:2389] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x0 - disabled: true - - - label: "Step 4c: TH reads from the DUT the RegisteredClients attribute." - PICS: ICDM.S.A0003 - verification: | - ./chip-tool icdmanagement read registered-clients 1 0 - - [1702438139.915311][2390:2392] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Attribute 0x0000_0003 DataVersion: 2633987690 - [1702438139.915462][2390:2392] CHIP:TOO: RegisteredClients: 1 entries - [1702438139.915616][2390:2392] CHIP:TOO: [1]: { - [1702438139.915667][2390:2392] CHIP:TOO: CheckInNodeID: 112233 - [1702438139.915708][2390:2392] CHIP:TOO: MonitoredSubject: 112233 - [1702438139.915774][2390:2392] CHIP:TOO: FabricIndex: 1 - [1702438139.915818][2390:2392] CHIP:TOO: } - disabled: true - - - label: - "Step 4d: Clear the THs administrator privileges for the ICDM cluster." - verification: | - ./chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 4, "authMode": 2, "subjects": [112233], "targets": null } ]' 1 0 - disabled: true - - - label: - "Step 5a: TH sends RegisterClient command. - CheckInNodeID: - registering clients node ID (CheckInNodeID5) - MonitoredSubject: - monitored subject ID (MonitorSubID5) - Key: shared secret between the - client and the ICD (Key5) - VerificationKey: verification key - (VerificationKey5)" - PICS: ICDM.S.C00.Rsp - verification: | - ./chip-tool icdmanagement register-client 5 5 hex:5555567890abcdef5555567890abcdef 1 0 --VerificationKey hex:abcdef1234567890abcdef1234567890 - On TH(chip-tool) verify that DUT responds with status code as success - - [1702437824.926527][2361:2363] CHIP:DMG: Received Command Response Data, Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0001 - [1702437824.926625][2361:2363] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Command 0x0000_0001 - [1702437824.926835][2361:2363] CHIP:TOO: RegisterClientResponse: { - [1702437824.926901][2361:2363] CHIP:TOO: ICDCounter: 2124479668 - [1702437824.926955][2361:2363] CHIP:TOO: } - disabled: true - - - label: "Step 5b: TH reads from the DUT the RegisteredClients attribute." - PICS: ICDM.S.A0003 - verification: | - ./chip-tool icdmanagement read registered-clients 1 0 - - On TH(Chip-tool), Verify that the DUT response contains a list of 1 registered client of given CheckInNodeID, MonitoredSubject, and Key - - [1702438233.117193][2401:2403] CHIP:TOO: Endpoint: 0 Cluster: 0x0000_0046 Attribute 0x0000_0003 DataVersion: 2633987690 - [1702438233.117356][2401:2403] CHIP:TOO: RegisteredClients: 2 entries - [1702438233.117510][2401:2403] CHIP:TOO: [1]: { - [1702438233.117559][2401:2403] CHIP:TOO: CheckInNodeID: 112233 - [1702438233.117603][2401:2403] CHIP:TOO: MonitoredSubject: 112233 - [1702438233.117669][2401:2403] CHIP:TOO: FabricIndex: 1 - [1702438233.117713][2401:2403] CHIP:TOO: } - [1702438233.117772][2401:2403] CHIP:TOO: [2]: { - [1702438233.117816][2401:2403] CHIP:TOO: CheckInNodeID: 5 - [1702438233.117859][2401:2403] CHIP:TOO: MonitoredSubject: 5 - [1702438233.117902][2401:2403] CHIP:TOO: FabricIndex: 1 - [1702438233.117944][2401:2403] CHIP:TOO: } - disabled: true - - - label: - "Step 6: TH sends UnregisterClient command with the CheckInNodeID from - Step 5a and an invalid VerificationKey. - CheckInNodeID: registering - clients node ID (CheckInNodeID5) - VerificationKey: invalid - verification key (VerificationKey6)" - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 5 1 0 --VerificationKey hex:abcdef1234567890 - - [1703268222.346310][2758:2760] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x1 - [1703268222.346412][2758:2760] CHIP:TOO: Error: IM Error 0x00000501: General error: 0x01 (FAILURE) - disabled: true - - - label: - "Step 7: TH sends UnregisterClient command with the CheckInNodeID from - Step 5a and different VerificationKey. - CheckInNodeID: registering - clients node ID (CheckInNodeID5) - VerificationKey: valid verification - key (VerificationKey7)" - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 5 1 0 --VerificationKey hex:abcdef1234567890abcdef1234500000 - - [1703268200.542869][2755:2757] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x1 - [1703268200.543007][2755:2757] CHIP:TOO: Error: IM Error 0x00000501: General error: 0x01 (FAILURE) - disabled: true - - - label: - "Step 8: TH sends UnregisterClient command with the CheckInNodeID and - VerificationKey from Step 5a. - CheckInNodeID: registering clients - node ID (CheckInNodeID5) - VerificationKey: verification key - (VerificationKey5)" - PICS: ICDM.S.C02.Rsp - verification: | - ./chip-tool icdmanagement unregister-client 5 1 0 --VerificationKey hex:abcdef1234567890abcdef1234567890 - - [1702438116.143490][2387:2389] CHIP:DMG: InvokeResponseMessage = - [1702438116.143590][2387:2389] CHIP:DMG: { - [1702438116.143648][2387:2389] CHIP:DMG: suppressResponse = false, - [1702438116.143877][2387:2389] CHIP:DMG: InvokeResponseIBs = - [1702438116.144238][2387:2389] CHIP:DMG: [ - [1702438116.144308][2387:2389] CHIP:DMG: InvokeResponseIB = - [1702438116.144414][2387:2389] CHIP:DMG: { - [1702438116.144476][2387:2389] CHIP:DMG: CommandStatusIB = - [1702438116.144575][2387:2389] CHIP:DMG: { - [1702438116.144646][2387:2389] CHIP:DMG: CommandPathIB = - [1702438116.144723][2387:2389] CHIP:DMG: { - [1702438116.144825][2387:2389] CHIP:DMG: EndpointId = 0x0, - [1702438116.144911][2387:2389] CHIP:DMG: ClusterId = 0x46, - [1702438116.144993][2387:2389] CHIP:DMG: CommandId = 0x2, - [1702438116.145097][2387:2389] CHIP:DMG: }, - [1702438116.145186][2387:2389] CHIP:DMG: - [1702438116.145278][2387:2389] CHIP:DMG: StatusIB = - [1702438116.145357][2387:2389] CHIP:DMG: { - [1702438116.145457][2387:2389] CHIP:DMG: status = 0x00 (SUCCESS), - [1702438116.145538][2387:2389] CHIP:DMG: }, - [1702438116.145616][2387:2389] CHIP:DMG: - [1702438116.145683][2387:2389] CHIP:DMG: }, - [1702438116.145782][2387:2389] CHIP:DMG: - [1702438116.145846][2387:2389] CHIP:DMG: }, - [1702438116.145917][2387:2389] CHIP:DMG: - [1702438116.146004][2387:2389] CHIP:DMG: ], - [1702438116.146078][2387:2389] CHIP:DMG: - [1702438116.146155][2387:2389] CHIP:DMG: InteractionModelRevision = 11 - [1702438116.146213][2387:2389] CHIP:DMG: }, - [1702438116.146382][2387:2389] CHIP:DMG: Received Command Response Status for Endpoint=0 Cluster=0x0000_0046 Command=0x0000_0002 Status=0x0 - disabled: true diff --git a/src/app/tests/suites/manualTests.json b/src/app/tests/suites/manualTests.json index 7b99318fe6c9fd..bbb86f7092b715 100644 --- a/src/app/tests/suites/manualTests.json +++ b/src/app/tests/suites/manualTests.json @@ -119,7 +119,6 @@ "Identify": ["Test_TC_I_3_2"], "IcdManagement": [ "Test_TC_ICDM_3_2", - "Test_TC_ICDM_3_3", "Test_TC_ICDM_4_1", "Test_TC_ICDM_5_1" ], diff --git a/src/python_testing/TC_ICDM_3_3.py b/src/python_testing/TC_ICDM_3_3.py new file mode 100644 index 00000000000000..cb8d1bd7bcbbcd --- /dev/null +++ b/src/python_testing/TC_ICDM_3_3.py @@ -0,0 +1,380 @@ + +# +# Copyright (c) 2023 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. +# + +# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments +# for details about the block below. +# +# === BEGIN CI TEST ARGUMENTS === +# test-runner-runs: run1 +# test-runner-run/run1/app: ${LIT_ICD_APP} +# test-runner-run/run1/factoryreset: True +# test-runner-run/run1/quiet: True +# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json +# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto +# === END CI TEST ARGUMENTS === + +import logging +from dataclasses import dataclass + +import chip.clusters as Clusters +from chip.interaction_model import InteractionModelError, Status +from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main +from mobly import asserts + +logger = logging.getLogger(__name__) + +kRootEndpointId = 0 + +cluster = Clusters.Objects.IcdManagement +commands = cluster.Commands +ClientTypeEnum = cluster.Enums.ClientTypeEnum + + +@dataclass +class Client: + checkInNodeID: int + subjectId: int + key: bytes + clientType: ClientTypeEnum + + +# +# Test Input Data +# +kIncorrectKey = b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1a" +kInvalidKey = b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e1g" + +client1 = Client( + checkInNodeID=1, + subjectId=1, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +client2 = Client( + checkInNodeID=2, + subjectId=2, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +client3 = Client( + checkInNodeID=3, + subjectId=3, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +client4 = Client( + checkInNodeID=4, + subjectId=4, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +# Client 5 skipped in the Test Plan steps +client6 = Client( + checkInNodeID=6, + subjectId=6, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + +# Client 7 skipped in the Test Plan steps +client8 = Client( + checkInNodeID=8, + subjectId=8, + key=b"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + clientType=ClientTypeEnum.kEphemeral +) + + +class TC_ICDM_3_3(MatterBaseTest): + + # + # Class Helper functions + # + async def _read_icdm_attribute_expect_success(self, attribute): + return await self.read_single_attribute_check_success(endpoint=kRootEndpointId, cluster=cluster, attribute=attribute) + + async def _send_single_icdm_command(self, command): + return await self.send_single_cmd(command, endpoint=kRootEndpointId) + # + # Test Harness Helpers + # + + def desc_TC_ICDM_3_3(self) -> str: + """Returns a description of this test""" + return "[TC-ICDM-3.3] Register/Unregister Clients with DUT as Server" + + def steps_TC_ICDM_3_3(self) -> list[TestStep]: + steps = [ + TestStep(0, "Commissioning, already done", is_commissioning=True), + TestStep("1a", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("1b", "TH sends UnregisterClient command with CheckInNodeID1, where CheckInNodeID1 can be any random node ID."), + TestStep("2a", "TH sends RegisterClient command."), + TestStep("2b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep(3, "TH sends UnregisterClient command with the CheckInNodeID3."), + TestStep("4a", "TH sends UnregisterClient command with the CheckInNodeID2."), + TestStep("4b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("5a", "TH sends RegisterClient command."), + TestStep("5b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("5c", "TH sends UnregisterClient command with the CheckInNodeID4 as in Step 5a and an invalid VerificationKey5."), + TestStep("5d", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("6a", "TH sends RegisterClient command."), + TestStep("6b", "TH reads from the DUT the RegisteredClients attribute."), + TestStep("6c", "TH sends UnregisterClient command with the CheckInNodeID6 as in Step 6a and a wrong VerificationKey7."), + TestStep("6d", "TH reads from the DUT the RegisteredClients attribute."), + TestStep(7, "Set the TH to Manage privilege for ICDM cluster."), + TestStep("8a", "TH sends RegisterClient command."), + TestStep("8b", "TH sends UnregisterClient command with the CheckInNodeID8 from Step 8a and an invalid VerificationKey9."), + TestStep("8c", "TH sends UnregisterClient command with the CheckInNodeID8 from Step 8a and a valid wrong VerificationKey10."), + TestStep("8d", "TH sends UnregisterClient command with the CheckInNodeID8 and VerificationKey8 from Step 8a."), + ] + return steps + + def pics_TC_ICDM_3_3(self) -> list[str]: + """ This function returns a list of PICS for this test case that must be True for the test to be run""" + pics = [ + "ICDM.S", + "ICDM.S.F00" + ] + return pics + + # + # ICDM 3.3 Test Body + # + + @async_test_body + async def test_TC_ICDM_3_3(self): + + cluster = Clusters.Objects.IcdManagement + attributes = cluster.Attributes + + # Pre-Condition: Commissioning + self.step(0) + + self.step("1a") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + + for client in registeredClients: + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + # Try / Case for the Test Plan post condition + try: + self.step("1b") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client1.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.NotFound, "Unexpected error returned") + pass + + self.step("2a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client2.checkInNodeID, monitoredSubject=client2.subjectId, key=client2.key, clientType=client2.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("2b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + # Validate list size + asserts.assert_equal(len(registeredClients), 1, + "The expected length of RegisteredClients is 1. List has the wrong size.") + + # Validate entry values + asserts.assert_equal( + registeredClients[0].checkInNodeID, client2.checkInNodeID, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].monitoredSubject, client2.subjectId, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].clientType, client2.clientType, "The read attribute does not match the registered value.") + + self.step(3) + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client3.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.NotFound, "Unexpected error returned") + + self.step("4a") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client2.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("4b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + asserts.assert_equal(len(registeredClients), 0, + "The RegisteredClients list must be empty. List has the wrong size.") + + self.step("5a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client4.checkInNodeID, monitoredSubject=client4.subjectId, key=client4.key, clientType=client4.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("5b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + # Validate list size + asserts.assert_equal(len(registeredClients), 1, + "The expected length of RegisteredClients is 1. List has the wrong size.") + + # Validate entry values + asserts.assert_equal( + registeredClients[0].checkInNodeID, client4.checkInNodeID, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].monitoredSubject, client4.subjectId, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].clientType, client4.clientType, "The read attribute does not match the registered value.") + + self.step("5c") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client4.checkInNodeID, verificationKey=kInvalidKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("5d") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + asserts.assert_equal(len(registeredClients), 0, + "The RegisteredClients list must be empty. List has the wrong size.") + + self.step("6a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client6.checkInNodeID, monitoredSubject=client6.subjectId, key=client6.key, clientType=client6.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("6b") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + # Validate list size + asserts.assert_equal(len(registeredClients), 1, + "The expected length of RegisteredClients is 1. List has the wrong size.") + + # Validate entry values + asserts.assert_equal( + registeredClients[0].checkInNodeID, client6.checkInNodeID, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].monitoredSubject, client6.subjectId, "The read attribute does not match the registered value.") + asserts.assert_equal( + registeredClients[0].clientType, client6.clientType, "The read attribute does not match the registered value.") + + self.step("6c") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client6.checkInNodeID, verificationKey=kIncorrectKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("6d") + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + asserts.assert_equal(len(registeredClients), 0, + "The RegisteredClients list must be empty. List has the wrong size.") + self.step(7) + ac = Clusters.AccessControl + previousAcl = await self.read_single_attribute_check_success(cluster=ac, attribute=ac.Attributes.Acl) + newAcls = [] + + # Set Admin permissions on Access Control cluster + newAclEntry = ac.Structs.AccessControlEntryStruct(privilege=ac.Enums.AccessControlEntryPrivilegeEnum.kAdminister, + authMode=ac.Enums.AccessControlEntryAuthModeEnum.kCase, + subjects=previousAcl[0].subjects, targets=[ac.Structs.AccessControlTargetStruct( + cluster=Clusters.AccessControl.id)], fabricIndex=previousAcl[0].fabricIndex + ) + newAcls.append(newAclEntry) + + # Set Manage permissions on ICD Management cluster + newAclEntry = ac.Structs.AccessControlEntryStruct(privilege=ac.Enums.AccessControlEntryPrivilegeEnum.kManage, + authMode=ac.Enums.AccessControlEntryAuthModeEnum.kCase, + subjects=previousAcl[0].subjects, targets=[ac.Structs.AccessControlTargetStruct( + cluster=Clusters.IcdManagement.id)], fabricIndex=previousAcl[0].fabricIndex + ) + newAcls.append(newAclEntry) + + try: + await self.default_controller.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, ac.Attributes.Acl(newAcls))]) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("8a") + try: + await self._send_single_icdm_command(commands.RegisterClient(checkInNodeID=client8.checkInNodeID, monitoredSubject=client8.subjectId, key=client8.key, clientType=client8.clientType)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + self.step("8b") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client8.checkInNodeID, verificationKey=kInvalidKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Failure, "Unexpected error returned") + + self.step("8c") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client8.checkInNodeID, verificationKey=kIncorrectKey)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Failure, "Unexpected error returned") + self.step("8d") + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client8.checkInNodeID, verificationKey=client8.key)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + # Post-Condition steps + finally: + # Reset ACLs + try: + await self.default_controller.WriteAttribute(nodeid=self.dut_node_id, attributes=[(0, ac.Attributes.Acl(previousAcl))]) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + # Clear all RegisteredClients + registeredClients = await self._read_icdm_attribute_expect_success( + attributes.RegisteredClients) + + for client in registeredClients: + try: + await self._send_single_icdm_command(commands.UnregisterClient(checkInNodeID=client.checkInNodeID)) + except InteractionModelError as e: + asserts.assert_equal( + e.status, Status.Success, "Unexpected error returned") + + +if __name__ == "__main__": + default_matter_test_main()