Skip to content

Commit

Permalink
Don't regard update information without a valid URL
Browse files Browse the repository at this point in the history
Skip updates which don't have an URL. We can't update such a node, so
simply pretend as if they don't exist in the version info.
  • Loading branch information
agners committed Jul 22, 2024
1 parent a61c4b0 commit 6eda1f5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ async def _check_node_update(
node_logger.info("No new update found.")
return None, None

if "otaUrl" not in update:
if "otaUrl" not in update or update["otaUrl"].trim().length == 0:
raise UpdateCheckError("Update found, but no OTA URL provided.")

node_logger.info(
Expand Down
3 changes: 3 additions & 0 deletions matter_server/server/ota/dcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ async def _check_update_version(
if version_candidate["softwareVersionValid"] is False:
return None

if version_candidate["otaUrl"].strip() == "":
return None

# Check minApplicableSoftwareVersion/maxApplicableSoftwareVersion
min_sw_version = version_candidate["minApplicableSoftwareVersion"]
max_sw_version = version_candidate["maxApplicableSoftwareVersion"]
Expand Down
12 changes: 12 additions & 0 deletions tests/server/ota/fixtures/4442-67.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"modelVersions": {
"vid": 4442,
"pid": 67,
"softwareVersions": [
197120,
197888,
197910,
198340
]
}
}
16 changes: 16 additions & 0 deletions tests/server/ota/test_dcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,19 @@ async def test_check_updates_specific_version(aioresponse):
result = await check_for_update(MagicMock(), 4447, 8194, 1000, 1011)

assert result == data["modelVersion"]


async def test_check_no_update_if_url_empty(aioresponse):
"""Test the case checks if latest version gets picked version."""
# Call the function with a current software version of 1000 and request 1011 as update
data = _load_fixture("4442-67.json")
aioresponse.get(url="/dcl/model/versions/4442/67", payload=data)
data = _load_fixture("4442-67-197888.json")
aioresponse.get(url="/dcl/model/versions/4442/67/197888", payload=data)
data = _load_fixture("4442-67-197910.json")
aioresponse.get(url="/dcl/model/versions/4442/67/197910", payload=data)
data = _load_fixture("4442-67-198340.json")
aioresponse.get(url="/dcl/model/versions/4442/67/198340", payload=data)
result = await check_for_update(MagicMock(), 4442, 67, 197120)

assert result is None

0 comments on commit 6eda1f5

Please sign in to comment.