Skip to content

Commit

Permalink
Don't regard update information without a valid URL (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners committed Jul 22, 2024
1 parent a61c4b0 commit 82335a9
Show file tree
Hide file tree
Showing 7 changed files with 89 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"].strip().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
19 changes: 19 additions & 0 deletions tests/server/ota/fixtures/4442-67-197888.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"modelVersion": {
"vid": 4442,
"pid": 67,
"softwareVersion": 197888,
"softwareVersionString": "3.5.0",
"cdVersionNumber": 1,
"firmwareInformation": "",
"softwareVersionValid": true,
"otaUrl": "",
"otaFileSize": "0",
"otaChecksum": "",
"otaChecksumType": 0,
"minApplicableSoftwareVersion": 0,
"maxApplicableSoftwareVersion": 197888,
"releaseNotesUrl": "",
"creator": "cosmos1sggrrmw05e6alve8umwdaszade5qxyt53kthud"
}
}
19 changes: 19 additions & 0 deletions tests/server/ota/fixtures/4442-67-197910.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"modelVersion": {
"vid": 4442,
"pid": 67,
"softwareVersion": 197910,
"softwareVersionString": "3.5.22",
"cdVersionNumber": 1,
"firmwareInformation": "",
"softwareVersionValid": true,
"otaUrl": "",
"otaFileSize": "0",
"otaChecksum": "",
"otaChecksumType": 0,
"minApplicableSoftwareVersion": 0,
"maxApplicableSoftwareVersion": 197910,
"releaseNotesUrl": "",
"creator": "cosmos1sggrrmw05e6alve8umwdaszade5qxyt53kthud"
}
}
19 changes: 19 additions & 0 deletions tests/server/ota/fixtures/4442-67-198340.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"modelVersion": {
"vid": 4442,
"pid": 67,
"softwareVersion": 198340,
"softwareVersionString": "3.6.196",
"cdVersionNumber": 1,
"firmwareInformation": "",
"softwareVersionValid": true,
"otaUrl": "https://nl67-firmware.s3.amazonaws.com/3.6.196_r8.matter",
"otaFileSize": "755976",
"otaChecksum": "46pqTh87M5fNhvR/zzt1M0RNQcVa8bApOCat7aKQ3KA=",
"otaChecksumType": 1,
"minApplicableSoftwareVersion": 198317,
"maxApplicableSoftwareVersion": 198340,
"releaseNotesUrl": "",
"creator": "cosmos1sggrrmw05e6alve8umwdaszade5qxyt53kthud"
}
}
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 82335a9

Please sign in to comment.