diff --git a/lib/gui/app/models/store.js b/lib/gui/app/models/store.js index f4fc0fd0..24d34f66 100644 --- a/lib/gui/app/models/store.js +++ b/lib/gui/app/models/store.js @@ -24,6 +24,7 @@ const constraints = require('../../../shared/drive-constraints') const supportedFormats = require('../../../shared/supported-formats') const errors = require('../../../shared/errors') const fileExtensions = require('../../../shared/file-extensions') +const utils = require('../../../shared/utils') const settings = require('./settings') /** @@ -250,6 +251,20 @@ const storeReducer = (state = DEFAULT_STATE, action) => { }) } + if (action.data.percentage !== undefined) { + if (!utils.isValidPercentage(action.data.percentage)) { + throw errors.createError({ + title: `Invalid state percentage: ${action.data.percentage}` + }) + } + + if (!_.isNumber(action.data.eta)) { + throw errors.createError({ + title: `Invalid state eta: ${action.data.eta}` + }) + } + } + return state.set('flashState', Immutable.fromJS(action.data)) } diff --git a/tests/gui/models/flash-state.spec.js b/tests/gui/models/flash-state.spec.js index 6973cdb4..2650e75d 100644 --- a/tests/gui/models/flash-state.spec.js +++ b/tests/gui/models/flash-state.spec.js @@ -126,22 +126,6 @@ describe('Model: flashState', function () { }).to.not.throw('Missing flash fields: percentage') }) - it('should throw if percentage is missing', function () { - flashState.setFlashingFlag() - m.chai.expect(function () { - flashState.setProgressState({ - flashing: 2, - verifying: 0, - successful: 0, - failed: 0, - type: 'write', - eta: 15, - speed: 100000000000, - totalSpeed: 200000000000 - }) - }).to.throw('Missing flash fields: percentage') - }) - it('should throw if percentage is not a number', function () { flashState.setFlashingFlag() m.chai.expect(function () { @@ -193,22 +177,6 @@ describe('Model: flashState', function () { }).to.throw('Invalid state percentage: -1') }) - it('should throw if eta is missing', function () { - flashState.setFlashingFlag() - m.chai.expect(function () { - flashState.setProgressState({ - flashing: 2, - verifying: 0, - successful: 0, - failed: 0, - type: 'write', - percentage: 50, - speed: 100000000000, - totalSpeed: 200000000000 - }) - }).to.throw('Missing flash fields: eta') - }) - it('should not throw if eta is equal to zero', function () { flashState.setFlashingFlag() m.chai.expect(function () {