From f74bf131aa06fb3a61b947cded5ab54353de5bd9 Mon Sep 17 00:00:00 2001 From: James Snow Date: Mon, 14 Feb 2022 16:32:04 -0600 Subject: [PATCH] Fix bug introduced by linting cleanup related to encrypted payloads. (#56) Previously the challenge value of an invoke request payload was inlined into the request body and the request's challenge field was compared against the response. This however was not possible when the payload was encrypted and led to a KeyError trying to access it. The challenge value has been moved into its own variable for comparison in both encrypted and non-encrypted payloads. This is a temporary fix while we rework the cli portion dealing with invoking/running skills is reworked to be more flexible. --- webex_skills/cli/skill.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/webex_skills/cli/skill.py b/webex_skills/cli/skill.py index 23f2f88..84628f3 100644 --- a/webex_skills/cli/skill.py +++ b/webex_skills/cli/skill.py @@ -97,8 +97,9 @@ def invoke_skill( 'developerDeviceId': device_id, } + challenge = os.urandom(32).hex() req = { - 'challenge': os.urandom(32).hex(), + 'challenge': challenge, 'text': query, 'context': default_context, 'params': default_params, @@ -124,14 +125,15 @@ def invoke_skill( typer.secho('Unable to deserialize JSON response') json_resp = {} - if not json_resp.get('challenge') == req['challenge']: + if not json_resp.get('challenge') == challenge: typer.secho('Skill did not respond with expected challenge value', fg=typer.colors.RED, err=True) typer.secho(pformat(json_resp, indent=2, width=120), fg=typer.colors.GREEN) query = typer.prompt('>>', prompt_suffix=' ') + challenge = os.urandom(32).hex() req = { - 'challenge': os.urandom(32).hex(), + 'challenge': challenge, 'text': query, 'context': default_context, 'params': json_resp.get('params', default_params),