From fc5a97b8fcf17574c8160dbb5407b173767ae9b0 Mon Sep 17 00:00:00 2001 From: keeramis Date: Thu, 27 Jun 2024 10:55:24 -0700 Subject: [PATCH] Remove --open option from the `disable` command --- src/cli/device-protection.js | 18 +++++-------- src/cmd/device-protection.js | 19 +++----------- src/cmd/device-protection.test.js | 24 ------------------ .../valid/bundle_app_1719510886367.zip | Bin 0 -> 3063 bytes 4 files changed, 9 insertions(+), 52 deletions(-) create mode 100644 test/__fixtures__/third_party_ota/valid/bundle_app_1719510886367.zip diff --git a/src/cli/device-protection.js b/src/cli/device-protection.js index 9b487be2e..209fb7232 100644 --- a/src/cli/device-protection.js +++ b/src/cli/device-protection.js @@ -12,21 +12,15 @@ module.exports = ({ commandProcessor, root }) => { }); commandProcessor.createCommand(deviceProtection, 'disable', 'Disables device protection', { - options: { - 'open': { - boolean: true, - description: 'Turns a protected device into an open device' - } - }, - handler: (args) => { + + handler: () => { const DeviceProtectionCommands = require('../cmd/device-protection'); - return new DeviceProtectionCommands().disableProtection(args); + return new DeviceProtectionCommands().disableProtection(); }, examples: { - '$0 $command': 'Puts a protected device into service mode', - '$0 $command --open': 'Turns a protected device into an open device' + '$0 $command': 'Puts a Protected Device to Service Mode', }, - epilogue: 'A protected device in service mode allows any command to be performed on it that can be performed on an open device like flashing firmware or serial monitor.' + epilogue: 'A Protected Device in Service Mode allows any command to be performed on it that can be performed on an open device like flashing firmware or serial monitor.' }); commandProcessor.createCommand(deviceProtection, 'enable', 'Enables device protection', { @@ -40,7 +34,7 @@ module.exports = ({ commandProcessor, root }) => { return new DeviceProtectionCommands().enableProtection(args); }, examples: { - '$0 $command': 'Turns an open device into a protected device' + '$0 $command': 'Turns an Open Device into a Protected Device' } }); diff --git a/src/cmd/device-protection.js b/src/cmd/device-protection.js index e274f5379..c9140ea86 100644 --- a/src/cmd/device-protection.js +++ b/src/cmd/device-protection.js @@ -88,7 +88,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase { * @returns {Promise} * @throws {Error} - Throws an error if any of the async operations fail. */ - async disableProtection({ open } = {}) { + async disableProtection() { let addToOutput = []; await this.ui.showBusySpinnerUntilResolved('Disabling device protection', this._withDevice(true, async () => { @@ -97,7 +97,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase { let s = await this._getDeviceProtection(); if (!s.protected && !s.overridden) { - addToOutput.push(`${deviceStr} is not a protected device.${os.EOL}`); + addToOutput.push(`${deviceStr} is not a Protected Device.${os.EOL}`); return; } @@ -121,21 +121,8 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase { await this.device.unprotectDevice({ action: 'confirm', serverSignature, serverPublicKeyFingerprint }); - if (!open) { - addToOutput.push(`${deviceStr} is now in service mode.${os.EOL}A protected device stays in service mode for a total of 20 reboots or 24 hours.${os.EOL}`); - return; - } - - const localBootloaderPath = await this._downloadBootloader(); - await this._flashBootloader(localBootloaderPath); - addToOutput.push(`${deviceStr} is now an open device.${os.EOL}`); + addToOutput.push(`${deviceStr} is now in Service Mode.${os.EOL}A Protected Device stays in Service Mode for a total of 20 reboots or 24 hours.${os.EOL}`); - const success = await this._markAsDevelopmentDevice(true); - addToOutput.push(success ? - // TODO: Improve these lines - `Device placed in development mode to maintain current settings.${os.EOL}` : - `Failed to mark device as development device. Device protection may be enabled on next cloud connection.${os.EOL}` - ); } catch (error) { throw new Error(`Failed to disable device protection: ${error.message}${os.EOL}`); } diff --git a/src/cmd/device-protection.test.js b/src/cmd/device-protection.test.js index 25104ead1..5f88660fc 100644 --- a/src/cmd/device-protection.test.js +++ b/src/cmd/device-protection.test.js @@ -71,30 +71,6 @@ describe('DeviceProtectionCommands', () => { expect(deviceProtectionCommands.api.unprotectDevice).to.have.been.calledTwice; }); - it('should disable protection on the device and turns to an open device', async () => { - sinon.stub(deviceProtectionCommands, '_getDeviceProtection') - .onFirstCall().resolves({ protected: true, overridden: false }) - .onSecondCall().resolves({ protected: true, overridden: false }); - sinon.stub(deviceProtectionCommands, '_getDeviceString').resolves('[123456789abcdef] (Product 12345)'); - deviceProtectionCommands.device = { - unprotectDevice: sinon.stub().resolves({ protected: true, deviceNonce: '11111', deviceSignature: '22222', devicePublicKeyFingerprint: '33333' }) - }; - deviceProtectionCommands.api = { - unprotectDevice: sinon.stub().resolves({ server_nonce: '44444', server_signature: '55555', server_public_key_fingerprint: '66666' }) - }; - sinon.stub(deviceProtectionCommands, '_downloadBootloader').resolves(); - sinon.stub(deviceProtectionCommands, '_flashBootloader').resolves(); - sinon.stub(deviceProtectionCommands,'_markAsDevelopmentDevice').resolves(true); - - - await deviceProtectionCommands.disableProtection({ open: true }); - - expect(deviceProtectionCommands._getDeviceProtection).to.have.been.calledOnce; - expect(deviceProtectionCommands.device.unprotectDevice).to.have.been.calledTwice; - expect(deviceProtectionCommands.api.unprotectDevice).to.have.been.calledTwice; - expect(deviceProtectionCommands._markAsDevelopmentDevice).to.have.been.calledOnce; - }); - it('handles already open devices', async () => { sinon.stub(deviceProtectionCommands, '_getDeviceProtection') .onFirstCall().resolves({ protected: false, overridden: false }); diff --git a/test/__fixtures__/third_party_ota/valid/bundle_app_1719510886367.zip b/test/__fixtures__/third_party_ota/valid/bundle_app_1719510886367.zip new file mode 100644 index 0000000000000000000000000000000000000000..468fe5c0783c98faedd86bc513488fb266ec9ee2 GIT binary patch literal 3063 zcma)8c{CK-A0L#RL?MzXg_mV4Z!iqmDn=x#S;`(7qRiNtJfxu*$wMJqLiVhQF=QEQ zmW*X=ku6JQn=!`n|F_#8dvVv_Jv9Vh*WL_E^O6%DIK9U(u-Qb*rKBR!7AcwI8B z4lv+3fQnZPRRvbd>4+`?%<3sa9$v4Z@t$BU002HC{6(d;?TMt5&iD06%Jr%(sR=Y{ z3#Tq^FnFO^(7(DRT=inKwoEiFxn>AESv=cl*A>x_B81nLA;{OtU9{m(?QrdTFU3c71s`KxNvmL(ybD`u zD7T?Hh1r!T=IP>g<#8~J*M|=j?%&lFH#Ef6KiNa1;GzNs)U*(1$crI@1h2G!WVlef zfX73d6sGS0T)c)O!Rjv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