Repository navigation
fix(taskstate): reject unknown task state values on unmarshal and REST status param - #404
Conversation
nahapetyan-serob
left a comment
There was a problem hiding this comment.
Thanks for tracking this down.
| // TestTaskStateUnmarshalJSON is a regression test for task state validation: unknown task | ||
| // state values must be rejected during JSON unmarshaling instead of being | ||
| // silently accepted as an opaque enum value. |
There was a problem hiding this comment.
After the changes, we would need to add couple of cases where current invalid cases just default to TaskStateUnspecified. The test speaks pretty clear for itself, so no comment needed.
| if val == "" { | ||
| return a2a.TaskStateUnspecified, nil | ||
| } |
There was a problem hiding this comment.
This check will become redundant, as Unmarshal needs to default "" to TaskStateUnspecified. Comment bellow is redundant.
| // TestREST_ListTasks_InvalidStatus is a regression test for task state validation: an | ||
| // invalid status query parameter must be rejected with HTTP 400 instead of | ||
| // being silently passed through as an opaque TaskState. | ||
| func TestREST_ListTasks_InvalidStatus(t *testing.T) { |
There was a problem hiding this comment.
this test won't be necessary as invalid status should be defaulted to TaskStateUnspecified
3b6fc34 to
829db31
Compare
|
Reworked to your reading of §4.1.3 — unknown values now map to Point by point:
|
| {name: "working", json: `"TASK_STATE_WORKING"`, want: TaskStateWorking}, | ||
|
|
||
| {name: "empty string", json: `""`, want: TaskStateUnspecified}, | ||
| {name: "empty string as unspecified", json: `"TASK_STATE_UNSPECIFIED"`, want: TaskStateUnspecified}, |
There was a problem hiding this comment.
let's rename to just unspecified
| } | ||
| } | ||
|
|
||
| func TestREST_ListTasks_UnknownStatusDefaultsToUnspecified(t *testing.T) { |
There was a problem hiding this comment.
let's rename to TestREST_ListTasks_StatusMapping as it doesn't only cover the Unknown case.
`TaskState.UnmarshalJSON` accepted any string as an opaque enum value, so an unknown token survived decoding and reached the handler as a state outside any known set. The REST `status` query parameter had the same gap: it was converted with a bare `a2a.TaskState(...)` cast that bypassed decoding entirely. Per review, unknown values now map to `TaskStateUnspecified` rather than being rejected, which is what the spec defines that value for: "the task is in an unknown or indeterminate state" (§4.1.3). `TaskStateFromString` holds the mapping and is used by both `UnmarshalJSON` and the REST handler, so a known token resolves to its state and everything else — including the empty string and lowercase variants — resolves to `TaskStateUnspecified`. This also makes the earlier REST-side validation redundant: the handler no longer needs its own parse step, since the status parameter goes through the same mapping. Tests: table-driven coverage for every known token plus empty, unknown, lowercase, and truncated values, and a REST test asserting the status parameter reaches the handler as `TaskStateUnspecified` for unknown input while known input still resolves. Signed-off-by: meraklbz <[email protected]>
829db31 to
9c8df98
Compare
|
All three are in as 9c8df98.
|
🤖 I have created a release *beep* *boop* --- ## [2.7.0](v2.6.0...v2.7.0) (2026-10-21) ### Features * add input mode validation ([#456](#456)) ([8c814be](8c814be)) * extension point for snapshot materialization logic ([#449](#449)) ([4899045](4899045)) * reject requests with unsupported A2A-Version ([#457](#457)) ([4226e74](4226e74)) * use application/a2a+json with Accept-based negotiation ([#465](#465)) ([a8caf47](a8caf47)) ### Bug Fixes * **a2a:** serialize task status timestamps in UTC ([#452](#452)) ([b657f33](b657f33)) * decode application/a2a+json error responses in the REST client ([#448](#448)) ([3e1aa7f](3e1aa7f)) * **errordetails:** handle nil Value in Typed.MarshalJSON ([#474](#474)) ([73c49ac](73c49ac)) * **grpc:** forward next_page_token in push config list responses ([#455](#455)) ([7210014](7210014)) * **grpc:** keep caller metadata when attaching service params ([#476](#476)) ([f01e895](f01e895)) * honor a2a+json Content Type when Accept is */* or missing ([#468](#468)) ([2169266](2169266)) * reject trailing data after the JSON body ([#453](#453)) ([e85760e](e85760e)) * **rest:** map non-A2A HTTP error responses by status code ([#471](#471)) ([4baba5f](4baba5f)) * return plain error when streaming fails before the first event ([#463](#463)) ([cf62533](cf62533)) * **taskstate:** reject unknown task state values on unmarshal and REST status param ([#404](#404)) ([534a60f](534a60f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
What changed
1. Reject unknown TaskState values on unmarshal
Problem:
TaskState.UnmarshalJSONaccepted any string as an opaque enum value, so malformed or unknown states (e.g."BOGUS_STATE", lowercase values) passed validation silently.Fix (a2a/core.go, a2a/json_test.go):
TASK_STATE_UNSPECIFIED); anything else returnsinvalid task state %q.TestTaskStateUnmarshalJSONcovering all valid states and invalid inputs.2. Validate the REST ListTasks
statusquery parameterProblem:
handleListTasksbuilt the request froma2a.TaskState(query.Get("status"))with no validation, so an invalid status reached the handler instead of producing a client error.Fix (a2asrv/rest.go, a2asrv/rest_test.go):
parseTaskStateOpt, which reusesTaskState's own validation (quoted unmarshal) and rejects unknown values with HTTP 400.TestREST_ListTasks_InvalidStatus; updatedTestREST_ListTasks_Successto useTASK_STATE_WORKINGinstead of the previously silently-acceptedrunning.Testing
go test ./a2asrv/... ./internal/... ./a2agrpc/... ./a2apb/... ./a2acompat/... ./a2a/ ./a2aclient/...).TestTaskStateUnmarshalJSONandTestREST_ListTasks_InvalidStatuspass.Behavior change: unknown task state values are now rejected during JSON unmarshaling and in the REST
statusquery parameter.BEGIN_COMMIT_OVERRIDE
fix(taskstate): reject unknown task state values on unmarshal and REST status param (#404)
END_COMMIT_OVERRIDE