From 1623954f257f279d218a3c0351656f376d1b3ea3 Mon Sep 17 00:00:00 2001 From: Song GUO Date: Wed, 16 Feb 2022 12:09:44 +0800 Subject: [PATCH] [Fix] Add missing return cause after AddStatus (#15186) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Fix] Add missing return cause after AddStatus * Add negative tests * Update src/controller/python/test/test_scripts/network_commissioning.py Co-authored-by: Damian Królik <66667989+Damian-Nordic@users.noreply.github.com> Co-authored-by: Justin Wood Co-authored-by: Damian Królik <66667989+Damian-Nordic@users.noreply.github.com> --- .../network-commissioning.cpp | 1 + .../test/test_scripts/network_commissioning.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index 615951ecc3693b..7b2abd3467d040 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -279,6 +279,7 @@ void Instance::HandleConnectNetwork(HandlerContext & ctx, const Commands::Connec if (req.networkID.size() > DeviceLayer::NetworkCommissioning::kMaxNetworkIDLen) { ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Protocols::InteractionModel::Status::InvalidValue); + return; } mConnectingNetworkIDLen = static_cast(req.networkID.size()); diff --git a/src/controller/python/test/test_scripts/network_commissioning.py b/src/controller/python/test/test_scripts/network_commissioning.py index 25fd4c89f2db4d..39a6d875aec9ca 100644 --- a/src/controller/python/test/test_scripts/network_commissioning.py +++ b/src/controller/python/test/test_scripts/network_commissioning.py @@ -70,6 +70,22 @@ async def readLastNetworkingStateAttributes(self, endpointId): logger.info(f"Got values: {values}") return values + async def test_negative(self, endpointId): + logger.info( + f"Running negative test cases for NetworkCommissioning cluster on endpoint {endpointId}") + + try: + logger.info( + f"1. Send ConnectNetwork command with a illegal network id") + req = Clusters.NetworkCommissioning.Commands.ConnectNetwork( + networkID=b'0' * 254, breadcrumb=0) + res = await self._devCtrl.SendCommand(nodeid=self._nodeid, endpoint=endpointId, payload=req) + raise AssertionError(f"Failure expected but got response {res}") + except chip.interaction_model.InteractionModelError as ex: + logger.info(f"Received {ex} from server.") + + logger.info(f"Finished negative test cases.") + async def test_wifi(self, endpointId): logger.info(f"Get basic information of the endpoint") res = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[ @@ -290,10 +306,12 @@ async def run(self): if clus.featureMap == WIFI_NETWORK_FEATURE_MAP: logger.info( f"Endpoint {endpoint} is configured as WiFi network, run WiFi commissioning test.") + await self.test_negative(endpoint) await self.test_wifi(endpoint) elif clus.featureMap == THREAD_NETWORK_FEATURE_MAP: logger.info( f"Endpoint {endpoint} is configured as Thread network, run Thread commissioning test.") + await self.test_negative(endpoint) await self.test_thread(endpoint) else: logger.info(