Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose commissionerNodeId as a variable for yaml #24197

Merged
merged 15 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/chip-tool/templates/tests/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ private:

void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override
{

// Allow yaml to access the current commissioner node id.
// Default to 0 (undefined node id) so we know if this isn't
// set correctly.
// Reset on every step in case it changed.
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);
(void) commissionerNodeId;

bool shouldContinue = false;

switch (mTestIndex - 1)
Expand Down Expand Up @@ -75,6 +83,7 @@ private:
// Allow yaml to access the current commissioner node id.
cecille marked this conversation as resolved.
Show resolved Hide resolved
// Default to 0 (undefined node id) so we know if this isn't
// set correctly.
// Reset on every step in case it changed.
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);
(void) commissionerNodeId;
switch (testIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,16 @@ class TestCommandBridge : public CHIPCommandBridge,
return CHIP_NO_ERROR;
}

MTRBaseDevice * _Nullable GetDevice(const char * _Nullable identity) { return mConnectedDevices[identity]; }
MTRBaseDevice * _Nullable GetDevice(const char * _Nullable identity)
{
MTRDeviceController * controller = GetCommissioner(identity);

SetIdentity(identity);
if (controller != nil && controller.controllerNodeId != nil) {
mCommissionerNodeId.SetValue([controller.controllerNodeId unsignedLongLongValue]);
}
return mConnectedDevices[identity];
}

// PairingDeleted and PairingComplete need to be public so our pairing
// delegate can call them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class {{filename}}: public TestCommandBridge
// Allow yaml to access the current commissioner node id.
cecille marked this conversation as resolved.
Show resolved Hide resolved
// Default to 0 (undefined node id) so we know if this isn't
// set correctly.
// Reset on every step in case it changed.
chip::NodeId commissionerNodeId = mCommissionerNodeId.ValueOr(0);

/////////// TestCommand Interface /////////
Expand Down Expand Up @@ -142,6 +143,7 @@ class {{filename}}: public TestCommandBridge
return {{command}}("{{identity}}", value);
{{else}}
MTRBaseDevice * device = GetDevice("{{identity}}");
commissionerNodeId = mCommissionerNodeId.ValueOr(0);
__auto_type * cluster = [[MTRBaseCluster{{>cluster}} alloc] initWithDevice:device endpointID:@({{endpoint}}) queue:mCallbackQueue];
VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE);

Expand Down
1 change: 1 addition & 0 deletions examples/placeholder/linux/include/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class TestCommand : public TestRunner,
protected:
chip::app::ConcreteCommandPath mCommandPath;
chip::app::ConcreteAttributePath mAttributePath;
chip::Optional<chip::NodeId> mCommissionerNodeId;
chip::Optional<chip::EndpointId> mEndpointId;
void SetIdentity(const char * name){};

Expand Down
235 changes: 235 additions & 0 deletions src/app/tests/suites/TestCommissionerNodeId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
# Copyright (c) 2022 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: Test Commissioner Node ID

config:
nodeId: 0x12344321
endpoint: 0
cluster: "Access Control"
payload:
type: char_string
defaultValue: "MT:-24J0AFN00KA0648G00" # This value needs to be generated automatically

tests:
- label: "Wait for the commissioned device to be retrieved for alpha"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Open Commissioning Window from alpha"
cluster: "AdministratorCommissioning"
command: "OpenBasicCommissioningWindow"
timedInteractionTimeoutMs: 10000
arguments:
values:
- name: "CommissioningTimeout"
value: 180

- label: "Commission from beta"
identity: "beta"
cluster: "CommissionerCommands"
command: "PairWithCode"
arguments:
values:
- name: "nodeId"
value: nodeId
- name: "payload"
value: payload

- label: "Wait for the commissioned device to be retrieved for beta"
identity: "beta"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Open Commissioning Window from alpha"
cluster: "AdministratorCommissioning"
command: "OpenBasicCommissioningWindow"
timedInteractionTimeoutMs: 10000
arguments:
values:
- name: "CommissioningTimeout"
value: 180

- label: "Commission from gamma"
identity: "gamma"
cluster: "CommissionerCommands"
command: "PairWithCode"
arguments:
values:
- name: "nodeId"
value: nodeId
- name: "payload"
value: payload

- label: "Wait for the commissioned device to be retrieved for gamma"
identity: "gamma"
cluster: "DelayCommands"
command: "WaitForCommissionee"
arguments:
values:
- name: "nodeId"
value: nodeId

- label: "Read the fabric ID from the alpha fabric"
identity: "alpha"
cluster: "Operational Credentials"
command: "readAttribute"
attribute: "CurrentFabricIndex"
response:
saveAs: alphaIndex

- label: "Read the fabric ID from the beta fabric"
identity: "beta"
cluster: "Operational Credentials"
command: "readAttribute"
attribute: "CurrentFabricIndex"
response:
saveAs: betaIndex

- label: "Read the fabric ID from the gamma fabric"
identity: "gamma"
cluster: "Operational Credentials"
command: "readAttribute"
attribute: "CurrentFabricIndex"
response:
saveAs: gammaIndex

- label: "Read the ACL from alpha and check commissioner node id"
identity: "alpha"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: alphaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from beta and check commissioner node id"
identity: "beta"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: betaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from gamma and check commissioner node id"
identity: "gamma"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: gammaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Write the ACL using the commissioner node id value"
identity: "beta"
command: "writeAttribute"
attribute: "ACL"
arguments:
value: [
{
FabricIndex: betaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Write the ACL using the commissioner node id value"
identity: "gamma"
command: "writeAttribute"
attribute: "ACL"
arguments:
value: [
{
FabricIndex: betaIndex,
cecille marked this conversation as resolved.
Show resolved Hide resolved
cecille marked this conversation as resolved.
Show resolved Hide resolved
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from beta and check commissioner node id"
identity: "beta"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: betaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Read the ACL from gamma and check commissioner node id"
identity: "gamma"
command: "readAttribute"
attribute: "ACL"
response:
value: [
{
FabricIndex: gammaIndex,
Privilege: 5, # administer
AuthMode: 2, # case
Subjects: [commissionerNodeId],
Targets: null,
},
]

- label: "Remove beta fabric"
cluster: "Operational Credentials"
command: "RemoveFabric"
arguments:
values:
- name: "FabricIndex"
value: betaIndex

- label: "Remove gamma fabric"
cluster: "Operational Credentials"
command: "RemoveFabric"
arguments:
values:
- name: "FabricIndex"
value: gammaIndex
1 change: 1 addition & 0 deletions src/app/tests/suites/ciTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
"TestAccessControlConstraints",
"TestLevelControlWithOnOffDependency",
"TestCommissioningWindow",
"TestCommissionerNodeId",
"TestClientMonitoringCluster"
],
"MultiAdmin": ["TestMultiAdmin"],
Expand Down
Loading