From b48ae06ed6e475d17c05631588846b9178a3c81f Mon Sep 17 00:00:00 2001 From: Julien Vanier Date: Thu, 27 Jun 2024 14:57:14 -0400 Subject: [PATCH] Fix structure of the module info --- src/lib/flash-helper.js | 9 ++++---- src/lib/flash-helper.test.js | 40 +++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/lib/flash-helper.js b/src/lib/flash-helper.js index 42b3adc1f..2ea58c0bc 100644 --- a/src/lib/flash-helper.js +++ b/src/lib/flash-helper.js @@ -380,10 +380,11 @@ async function validateModulesForProtection({ modules, device }) { } for (const module of modules) { - const oldSystem = module.moduleFunction === ModuleInfo.FunctionType.SYSTEM_PART && - module.moduleVersion < PROTECTED_MINIMUM_SYSTEM_VERSION; - const oldBootloader = module.moduleFunction === ModuleInfo.FunctionType.BOOTLOADER && - module.moduleIndex === 0 && module.moduleVersion < PROTECTED_MINIMUM_BOOTLOADER_VERSION; + const { moduleFunction, moduleIndex, moduleVersion } = module.prefixInfo; + const oldSystem = moduleFunction === ModuleInfo.FunctionType.SYSTEM_PART && + moduleVersion < PROTECTED_MINIMUM_SYSTEM_VERSION; + const oldBootloader = moduleFunction === ModuleInfo.FunctionType.BOOTLOADER && + moduleIndex === 0 && moduleVersion < PROTECTED_MINIMUM_BOOTLOADER_VERSION; if (oldSystem || oldBootloader) { throw new Error(`Cannot downgrade Device OS below version ${PROTECTED_MINIMUM_VERSION} on a Protected Device`); diff --git a/src/lib/flash-helper.test.js b/src/lib/flash-helper.test.js index d8145301d..d4cc644de 100644 --- a/src/lib/flash-helper.test.js +++ b/src/lib/flash-helper.test.js @@ -664,27 +664,35 @@ describe('flash-helper', () => { describe('validateModulesForProtection', () => { let device; const modulesOldBootloader = [{ - moduleFunction: ModuleInfo.FunctionType.BOOTLOADER, - platformId: 12, - moduleIndex: 0, - moduleVersion: 1200, + prefixInfo: { + moduleFunction: ModuleInfo.FunctionType.BOOTLOADER, + platformId: 12, + moduleIndex: 0, + moduleVersion: 1200 + } }]; const modulesOldSystem = [{ - moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART, - platformId: 12, - moduleIndex: 0, - moduleVersion: 5800, + prefixInfo: { + moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART, + platformId: 12, + moduleIndex: 0, + moduleVersion: 5800 + } }]; const modulesNew = [{ - moduleFunction: ModuleInfo.FunctionType.BOOTLOADER, - platformId: 12, - moduleIndex: 0, - moduleVersion: 3000, + prefixInfo: { + moduleFunction: ModuleInfo.FunctionType.BOOTLOADER, + platformId: 12, + moduleIndex: 0, + moduleVersion: 3000 + } }, { - moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART, - platformId: 12, - moduleIndex: 0, - moduleVersion: 6000, + prefixInfo: { + moduleFunction: ModuleInfo.FunctionType.SYSTEM_PART, + platformId: 12, + moduleIndex: 0, + moduleVersion: 6000 + } }]; beforeEach(() => {