diff --git a/src/core/injectExecuteCommand.js b/src/core/injectExecuteCommand.js index ee275ba53..cd84af32d 100644 --- a/src/core/injectExecuteCommand.js +++ b/src/core/injectExecuteCommand.js @@ -12,6 +12,7 @@ governing permissions and limitations under the License. import { isFunction, isObject } from "../utils/index.js"; import { CONFIGURE, SET_DEBUG } from "../constants/coreCommands.js"; +import { objectOf, boolean } from "../utils/validation/index.js"; export default ({ logger, @@ -44,7 +45,18 @@ export default ({ ); } if (commandName === SET_DEBUG) { - executor = () => setDebugCommand(options); + executor = () => { + const optionsValidator = objectOf({ + enabled: boolean().required(), + }).noUnknownFields(); + + const validatedOptions = validateCommandOptions({ + command: { commandName: SET_DEBUG, optionsValidator }, + options, + }); + + setDebugCommand(validatedOptions); + }; } else { executor = () => { return configurePromise.then( diff --git a/test/unit/specs/core/injectExecuteCommand.spec.js b/test/unit/specs/core/injectExecuteCommand.spec.js index 78a37ae67..2a60ffcbe 100644 --- a/test/unit/specs/core/injectExecuteCommand.spec.js +++ b/test/unit/specs/core/injectExecuteCommand.spec.js @@ -215,11 +215,16 @@ describe("injectExecuteCommand", () => { .createSpy() .and.returnValue(Promise.resolve(componentRegistry)); const setDebugCommand = jasmine.createSpy(); + const validateCommandOptions = jasmine + .createSpy() + .and.returnValue({ enabled: true }); + const executeCommand = injectExecuteCommand({ logger, configureCommand, setDebugCommand, handleError, + validateCommandOptions, }); return Promise.all([ @@ -227,7 +232,7 @@ describe("injectExecuteCommand", () => { executeCommand("setDebug", { baz: "qux" }), ]).then(([configureResult, setDebugResult]) => { expect(configureCommand).toHaveBeenCalledWith({ foo: "bar" }); - expect(setDebugCommand).toHaveBeenCalledWith({ baz: "qux" }); + expect(setDebugCommand).toHaveBeenCalledWith({ enabled: true }); expect(configureResult).toEqual({}); expect(setDebugResult).toEqual({}); });