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 000000000..468fe5c07 Binary files /dev/null and b/test/__fixtures__/third_party_ota/valid/bundle_app_1719510886367.zip differ