Skip to content

Commit

Permalink
[Fix] Add missing return cause after AddStatus (#15186)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>

Co-authored-by: Justin Wood <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Sep 11, 2023
1 parent 2ba6b06 commit 1623954
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(req.networkID.size());
Expand Down
18 changes: 18 additions & 0 deletions src/controller/python/test/test_scripts/network_commissioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1623954

Please sign in to comment.