Skip to content

Commit

Permalink
Fix bug introduced by linting cleanup related to encrypted payloads. (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
snow0x2d0 committed Feb 14, 2022
1 parent fdceccb commit f74bf13
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions webex_skills/cli/skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down

0 comments on commit f74bf13

Please sign in to comment.