From 70f96791136c128f1967c0021f62abf24a812b98 Mon Sep 17 00:00:00 2001 From: Matej Sychra Date: Sun, 8 May 2022 17:04:14 +0200 Subject: [PATCH] firmware update validation fix (major!) after refactoring --- _envi.json | 26 ++++++++++++++++++++++---- lib/thinx/deployment.js | 22 +++++++++++++--------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/_envi.json b/_envi.json index 81bab9755..3ee9e9336 100644 --- a/_envi.json +++ b/_envi.json @@ -1,12 +1,11 @@ { - "note": "This is a sample THiNX mock data specification (supported features)", - "oid": "4f1122fa074af4dabab76a5205474882c82de33f50ecd962d25d3628cd0603be", + "oid": "07cef9718edaad79b3974251bb5ef4aedca58703142e8c4c48c20f96cda4979c", "udid": "d6ff2bb0-df34-11e7-b351-eb37822aa172", "mac": "11:11:11:11:11:11", "version": "1.7.2", "sid": "7038e0500a8690a8bf70d8470f46365458798011e8f46ff012f12cbcf898b2f4", "ak_failing": "adee16a3d627fc775a8a5e325cf67e57c58b38b6ab9deeef5cb4a47dcded5b7e", - "ak": "adee16a3d627fc775a8a5e325cf67e57c58b38b6ab9deeef5cb4a47dcded5b7e", + "ak": "a6d548c60da8307394d19894a246c9e9eec6c841b8ad54968e047ce0a1687b94", "build_id": "b1fb3850-de84-11e7-87b3-2d28e305da6d", "email": "cimrman@thinx.cloud", "test_info": { @@ -18,12 +17,31 @@ }, "goals": [], "username": "cimrman", - "owner": "4f1122fa074af4dabab76a5205474882c82de33f50ecd962d25d3628cd0603be", + "owner": "07cef9718edaad79b3974251bb5ef4aedca58703142e8c4c48c20f96cda4979c", "email": "cimrman@thinx.cloud", "transformers": [{ "ufid": "vt:b688d51871191b9f645678b10ce70ec23704ef5c549019b8beeaec9939401755", "alias": "Empty", "body": "var transformer = function(status, device) { return status };" }] + }, + "test_avatar": "", + "dynamic": { + "first_name": "Dynamic", + "last_name": "User", + "email": "dynamic@example.com", + "username": "dynamic", + "udid": "d6ff2bb0-df34-11e7-b351-eb37822aa174", + "owner": "bab692f8c9c78cf64f579406bdf6c6cd2c4d00b3c0c8390387d051495dd95247", + "transformers": [{ + "ufid": "vt:b688d51871191b9f645678b10ce70ec23704ef5c549019b8beeaec9939401756", + "alias": "Empty", + "body": "var transformer = function(status, device) { return status };" + }] + }, + "dynamic2": { + "owner": "40e8a98eee1855695bea07f83726fc474ad5681b003610fc38d9ff8b891e9b42", + "email": "dynamic2@example.com" } + } diff --git a/lib/thinx/deployment.js b/lib/thinx/deployment.js index 1553058f1..93a19c005 100644 --- a/lib/thinx/deployment.js +++ b/lib/thinx/deployment.js @@ -48,9 +48,9 @@ module.exports = class Deployment { // check if any build exists for this device if (!fs.existsSync(path)) { // lgtm [js/path-injection] console.log("☣️ [error] LFE path does not exist."); - return false; + return false; } - + var envpath = path + "/build.json"; if (fs.existsSync(envpath)) { // lgtm [js/path-injection] return JSON.parse(fs.readFileSync(envpath)); // lgtm [js/path-injection] @@ -326,10 +326,12 @@ module.exports = class Deployment { var dpath = this.pathForDevice(owner, udid); var fpath = dpath + "/" + build_id + "/" + build_id + ".zip"; let data = null; - try { - fs.readFileSync(fpath); - } catch (e) { - console.log("[error] caught exception", e, "while reading artifact at", fpath); + if (fs.existsSync(fpath)) { + try { + fs.readFileSync(fpath); + } catch (e) { + console.log("[error] caught exception", e, "while reading artifact at", fpath); + } } return data; // lgtm [js/path-injection] } @@ -357,6 +359,8 @@ module.exports = class Deployment { console.log("☣️ [error] [validateHasUpdateAvailable] Device does not support updates."); return false; } + + return true; } hasUpdateAvailable(device) { @@ -376,8 +380,8 @@ module.exports = class Deployment { if (outdated) { console.log("ℹ️ [info] Device has:", deviceVersion, ", update available to:", available_version); return true; - } - + } + // Device version same, but environment may change if (semver.eq(deviceVersion, available_version)) { // versions equal, update may happen @@ -397,7 +401,7 @@ module.exports = class Deployment { } else { console.log("ℹ️ [info] Device version is newer than available."); } - + return outdated; } }; \ No newline at end of file