Skip to content

Perform Base64 decode before JSON validation in create payloads#1074

Draft
ks-temporal wants to merge 1 commit into
temporalio:mainfrom
ks-temporal:ks/order-of-base64-and-json-parse
Draft

Perform Base64 decode before JSON validation in create payloads#1074
ks-temporal wants to merge 1 commit into
temporalio:mainfrom
ks-temporal:ks/order-of-base64-and-json-parse

Conversation

@ks-temporal
Copy link
Copy Markdown

What changed?

Previously, the Base64 decoding was done after JSON validation. This prevented
setting --input option with Base64 of JSON value. Base64 decoding is now done
before any JSON validation, if encoding indicates json.

Why changed?

The --input-base64 boolean flag indicates that the input is in base64. From help:

--input-base64     Assume inputs are base64-encoded and attempt to decode them.

If the flag is present, then input is not in JSON, and must be supplied as base64
encoded value. If no input-meta is supplied to change the encoding, or is set as
json/plain or similar, then previously, it attempted to validate input as JSON before
base64 decode, which failed.

Checklist

Stability

  • Breaking changes are marked with 💥 in the PR title and release notes
  • Changes to JSON output (-o json / -o jsonl) are treated as breaking changes

Design

  • This feature does not depend on Cloud-only APIs or behavior (it works against an OSS server)
  • New commands follow temporal <noun> <verb> structure (e.g. temporal workflow start)
  • New flags are named after the API concept, not the implementation mechanism (good: --search-attribute, bad: --index-field)
  • New flags don't duplicate an existing flag that serves the same purpose
  • New flags do not have short aliases without strong justification
  • Experimental features are marked with (Experimental) in commands.yaml

Help text (see style guide at the top of commands.yaml)

  • All flags shown in help text and examples are implemented and functional
  • Summaries use sentence case and have no trailing period
  • Long descriptions end with a period and include at least one example invocation
  • Examples use long flags (--namespace, not -n), one flag per line
  • Placeholder values use YourXxx form (YourWorkflowId, YourNamespace)

Behavior

  • Results go to stdout; errors and warnings go to stderr
  • Error messages are lowercase with no trailing punctuation

Tests

  • Added functional test(s) (SharedServerSuite)
  • Added unit test(s) (func TestXxx) where applicable

Manual tests

Setup

Start server, and worker from samples-go for standalone_activity/helloworld

temporal server start-dev --headless
cd samples-go
go run standalone-activity/helloworld/worker/main.go

Happy path

The following test should not work previously, but should work after the fix in this PR.

$ echo -e -n "\"Temporal\"" | base64
IlRlbXBvcmFsIg==

$ temporal activity execute \
    --type Activity \
    --task-queue standalone-activity-helloworld \
    --activity-id YourActivityId \
    --start-to-close-timeout 10s \
    --input IlRlbXBvcmFsIg== \
    --input-base64

Without the fix:

Error: input #1 is not valid JSON

With the fix:

Running execution:
  ActivityId  YourActivityId
  RunId       ...
  Namespace   default
Results:
  Status  COMPLETED
  Result  "Hello Temporal!"

Previously, the Base64 decoding was done after JSON validation.
This prevented setting --input option with Base64 of JSON value.
Base64 decoding is now done before any JSON validation, if
encoding indicates json.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant