18
18
from typing import Any
19
19
20
20
import chip .clusters as Clusters
21
+ from basic_composition_support import arls_populated
21
22
from conformance_support import ConformanceDecision
22
23
from global_attribute_ids import GlobalAttributeIds
23
24
from matter_testing_support import MatterBaseTest , async_test_body , default_matter_test_main
@@ -191,7 +192,7 @@ def _create_minimal_dt(self, device_type_id: int) -> dict[int, dict[int, Any]]:
191
192
endpoint_tlv [Clusters .Descriptor .id ] = attrs
192
193
return endpoint_tlv
193
194
194
- def add_macl (self , root_endpoint : dict [int , dict [int , Any ]]):
195
+ def add_macl (self , root_endpoint : dict [int , dict [int , Any ]], populate_arl : bool = False , populate_commissioning_arl : bool = False ):
195
196
ac = Clusters .AccessControl
196
197
root_endpoint [ac .id ][ac .Attributes .FeatureMap .attribute_id ] = ac .Bitmaps .Feature .kManagedDevice
197
198
root_endpoint [ac .id ][ac .Attributes .Arl .attribute_id ] = []
@@ -202,6 +203,14 @@ def add_macl(self, root_endpoint: dict[int, dict[int, Any]]):
202
203
root_endpoint [ac .id ][ac .Attributes .GeneratedCommandList .attribute_id ].append (
203
204
ac .Commands .ReviewFabricRestrictionsResponse .command_id )
204
205
206
+ generic_restriction = ac .Structs .AccessRestrictionStruct (
207
+ type = ac .Enums .AccessRestrictionTypeEnum .kAttributeAccessForbidden , id = 1 )
208
+ entry = ac .Structs .CommissioningAccessRestrictionEntryStruct (endpoint = 1 , cluster = 2 , restrictions = generic_restriction )
209
+ if populate_arl :
210
+ root_endpoint [ac .id ][ac .Attributes .Arl .attribute_id ] = [entry ]
211
+ if populate_commissioning_arl :
212
+ root_endpoint [ac .id ][ac .Attributes .CommissioningARL .attribute_id ] = [entry ]
213
+
205
214
@async_test_body
206
215
async def test_macl_handling (self ):
207
216
nim_id = self ._get_device_type_id ('network infrastructure manager' )
@@ -231,6 +240,46 @@ async def test_macl_handling(self):
231
240
232
241
# TODO: what happens if there is a NIM and a non-NIM endpoint?
233
242
243
+ @async_test_body
244
+ async def test_macl_restrictions (self ):
245
+
246
+ nim_id = self ._get_device_type_id ('network infrastructure manager' )
247
+ root_node_id = self ._get_device_type_id ('root node' )
248
+ on_off_id = self ._get_device_type_id ('On/Off Light' )
249
+
250
+ root = self ._create_minimal_dt (device_type_id = root_node_id )
251
+ nim = self ._create_minimal_dt (device_type_id = nim_id )
252
+ self .endpoints_tlv = {0 : root , 1 : nim }
253
+
254
+ # device with no macl
255
+ have_arl , have_carl = arls_populated (self .endpoints_tlv )
256
+ asserts .assert_false (have_arl , "Unexpected ARL found" )
257
+ asserts .assert_false (have_carl , "Unexpected CommissioningARL found" )
258
+
259
+ # device with unpopulated macl
260
+ self .add_macl (root )
261
+ have_arl , have_carl = arls_populated (self .endpoints_tlv )
262
+ asserts .assert_false (have_arl , "Unexpected ARL found" )
263
+ asserts .assert_false (have_carl , "Unexpected CommissioningARL found" )
264
+
265
+ # device with populated ARL
266
+ self .add_macl (root , populate_arl = True )
267
+ have_arl , have_carl = arls_populated (self .endpoints_tlv )
268
+ asserts .assert_true (have_arl , "Did not find expected ARL" )
269
+ asserts .assert_false (have_carl , "Unexpected CommissioningARL found" )
270
+
271
+ # device with populated commissioning ARL
272
+ self .add_macl (root , populate_commissioning_arl = True )
273
+ have_arl , have_carl = arls_populated (self .endpoints_tlv )
274
+ asserts .assert_false (have_arl , "Unexpected ARL found" )
275
+ asserts .assert_true (have_carl , "Did not find expected Commissioning ARL" )
276
+
277
+ # device with both
278
+ self .add_macl (root , populate_arl = True , populate_commissioning_arl = True )
279
+ have_arl , have_carl = arls_populated (self .endpoints_tlv )
280
+ asserts .assert_true (have_arl , "Did not find expected ARL" )
281
+ asserts .assert_true (have_carl , "Did not find expected Commissioning ARL" )
282
+
234
283
235
284
if __name__ == "__main__" :
236
285
default_matter_test_main ()
0 commit comments