|
| 1 | +# |
| 2 | +# Copyright (c) 2024 Project CHIP Authors |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +import logging |
| 19 | + |
| 20 | +import chip.clusters as Clusters |
| 21 | +from chip import ChipDeviceCtrl |
| 22 | +from chip.interaction_model import Status |
| 23 | +from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main |
| 24 | +from mobly import asserts |
| 25 | + |
| 26 | + |
| 27 | +class TC_ACE_1_5(MatterBaseTest): |
| 28 | + |
| 29 | + async def read_currentfabricindex(self, th: ChipDeviceCtrl) -> int: |
| 30 | + cluster = Clusters.Objects.OperationalCredentials |
| 31 | + attribute = Clusters.OperationalCredentials.Attributes.CurrentFabricIndex |
| 32 | + current_fabric_index = await self.read_single_attribute_check_success(dev_ctrl=th, endpoint=0, cluster=cluster, attribute=attribute) |
| 33 | + return current_fabric_index |
| 34 | + |
| 35 | + async def write_acl(self, acl: Clusters.AccessControl, th: ChipDeviceCtrl): |
| 36 | + result = await th.WriteAttribute(self.dut_node_id, [(0, Clusters.AccessControl.Attributes.Acl(acl))]) |
| 37 | + asserts.assert_equal(result[0].Status, Status.Success, "ACL write failed") |
| 38 | + |
| 39 | + @async_test_body |
| 40 | + async def test_TC_ACE_1_5(self): |
| 41 | + self.print_step(1, "Comissioning, already done") |
| 42 | + self.th1 = self.default_controller |
| 43 | + |
| 44 | + # TODO: move into base class and adjust tests (#31521) |
| 45 | + new_certificate_authority = self.certificate_authority_manager.NewCertificateAuthority() |
| 46 | + new_fabric_admin = new_certificate_authority.NewFabricAdmin(vendorId=0xFFF1, fabricId=self.matter_test_config.fabric_id + 1) |
| 47 | + |
| 48 | + TH1_nodeid = self.matter_test_config.controller_node_id |
| 49 | + TH2_nodeid = self.matter_test_config.controller_node_id + 2 |
| 50 | + |
| 51 | + self.th2 = new_fabric_admin.NewController(nodeId=TH2_nodeid, |
| 52 | + paaTrustStorePath=str(self.matter_test_config.paa_trust_store_path)) |
| 53 | + |
| 54 | + params = self.openCommissioningWindow(self.th1, self.dut_node_id) |
| 55 | + self.print_step(2, "TH1 opens the commissioning window on the DUT") |
| 56 | + |
| 57 | + errcode = self.th2.CommissionOnNetwork( |
| 58 | + nodeId=self.dut_node_id, setupPinCode=params.commissioningParameters.setupPinCode, |
| 59 | + filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=params.randomDiscriminator) |
| 60 | + logging.info('Commissioning complete done. Successful? {}, errorcode = {}'.format(errcode.is_success, errcode)) |
| 61 | + self.print_step(3, "TH2 commissions DUT using admin node ID N2") |
| 62 | + |
| 63 | + self.print_step(4, "TH2 reads its fabric index from the Operational Credentials cluster CurrentFabricIndex attribute") |
| 64 | + th2FabricIndex = await self.read_currentfabricindex(self.th2) |
| 65 | + |
| 66 | + self.print_step( |
| 67 | + 5, "TH1 writes DUT Endpoint 0 ACL cluster ACL attribute, value is list of ACLEntryStruct containing 2 elements") |
| 68 | + admin_acl = Clusters.AccessControl.Structs.AccessControlEntryStruct( |
| 69 | + privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kAdminister, |
| 70 | + authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase, |
| 71 | + subjects=[TH1_nodeid], |
| 72 | + targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.AccessControl.id)]) |
| 73 | + descriptor_view = Clusters.AccessControl.Structs.AccessControlEntryStruct( |
| 74 | + privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView, |
| 75 | + authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase, |
| 76 | + subjects=[], |
| 77 | + targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.Descriptor.id)]) |
| 78 | + acl = [admin_acl, descriptor_view] |
| 79 | + await self.write_acl(acl, self.th1) |
| 80 | + |
| 81 | + self.print_step( |
| 82 | + 6, "TH2 writes DUT Endpoint 0 ACL cluster ACL attribute, value is list of ACLEntryStruct containing 2 elements") |
| 83 | + admin_acl = Clusters.AccessControl.Structs.AccessControlEntryStruct( |
| 84 | + fabricIndex=th2FabricIndex, |
| 85 | + privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kAdminister, |
| 86 | + authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase, |
| 87 | + subjects=[TH2_nodeid], |
| 88 | + targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.AccessControl.id)]) |
| 89 | + descriptor_view = Clusters.AccessControl.Structs.AccessControlEntryStruct( |
| 90 | + fabricIndex=th2FabricIndex, |
| 91 | + privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kView, |
| 92 | + authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase, |
| 93 | + subjects=[], |
| 94 | + targets=[Clusters.AccessControl.Structs.AccessControlTargetStruct(endpoint=0, cluster=Clusters.BasicInformation.id)]) |
| 95 | + acl = [admin_acl, descriptor_view] |
| 96 | + await self.write_acl(acl, self.th2) |
| 97 | + |
| 98 | + self.print_step(7, "TH1 reads DUT Endpoint 0 Descriptor cluster DeviceTypeList attribute") |
| 99 | + await self.read_single_attribute_check_success( |
| 100 | + dev_ctrl=self.th1, endpoint=0, |
| 101 | + cluster=Clusters.Objects.Descriptor, |
| 102 | + attribute=Clusters.Descriptor.Attributes.DeviceTypeList) |
| 103 | + |
| 104 | + self.print_step(8, "TH1 reads DUT Endpoint 0 Basic Information cluster VendorID attribute") |
| 105 | + await self.read_single_attribute_expect_error( |
| 106 | + dev_ctrl=self.th1, endpoint=0, |
| 107 | + cluster=Clusters.Objects.BasicInformation, |
| 108 | + attribute=Clusters.BasicInformation.Attributes.VendorID, |
| 109 | + error=Status.UnsupportedAccess) |
| 110 | + |
| 111 | + self.print_step(9, "TH2 reads DUT Endpoint 0 Descriptor cluster DeviceTypeList attribute") |
| 112 | + await self.read_single_attribute_expect_error( |
| 113 | + dev_ctrl=self.th2, endpoint=0, |
| 114 | + cluster=Clusters.Objects.Descriptor, |
| 115 | + attribute=Clusters.Descriptor.Attributes.DeviceTypeList, |
| 116 | + error=Status.UnsupportedAccess) |
| 117 | + |
| 118 | + self.print_step(10, "TH2 reads DUT Endpoint 0 Basic Information cluster VendorID attribute") |
| 119 | + await self.read_single_attribute_check_success( |
| 120 | + dev_ctrl=self.th2, endpoint=0, |
| 121 | + cluster=Clusters.Objects.BasicInformation, |
| 122 | + attribute=Clusters.BasicInformation.Attributes.VendorID) |
| 123 | + |
| 124 | + self.print_step(11, "TH1 resets the ACLs to default value by writing DUT EP0") |
| 125 | + full_acl = Clusters.AccessControl.Structs.AccessControlEntryStruct( |
| 126 | + privilege=Clusters.AccessControl.Enums.AccessControlEntryPrivilegeEnum.kAdminister, |
| 127 | + authMode=Clusters.AccessControl.Enums.AccessControlEntryAuthModeEnum.kCase, |
| 128 | + subjects=[TH1_nodeid], |
| 129 | + targets=[]) |
| 130 | + |
| 131 | + acl = [full_acl] |
| 132 | + await self.write_acl(acl, self.th1) |
| 133 | + |
| 134 | + self.print_step( |
| 135 | + 12, "TH1 removes the TH2 fabric by sending the RemoveFabric command to the DUT with the FabricIndex set to th2FabricIndex") |
| 136 | + removeFabricCmd = Clusters.OperationalCredentials.Commands.RemoveFabric(th2FabricIndex) |
| 137 | + await self.th1.SendCommand(nodeid=self.dut_node_id, endpoint=0, payload=removeFabricCmd) |
| 138 | + |
| 139 | + |
| 140 | +if __name__ == "__main__": |
| 141 | + default_matter_test_main() |
0 commit comments