fix(cmd): reject malformed subscribe filters - #4036
Conversation
extractFilterMap used strings.Split on "=", so a valid filter value containing "=" (foo=bar=baz) split into three parts and was silently dropped. Malformed values were printed and skipped, after which runSubscribe still called f.Write() - writing func.yaml without the requested filter and exiting 0. Use strings.SplitN to preserve values containing "=", return an error for a missing "=" or an empty key, and propagate it through updateOrAddSubscription to runSubscribe so the command fails before anything is written. Adds table-driven unit tests for extractFilterMap and end-to-end tests asserting cmd.Execute() returns an error and leaves func.yaml untouched.
|
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: axhatggg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @axhatggg! It looks like this is your first PR to knative/func 🎉 |
|
Hi @axhatggg. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Fixes #3941
Why
func subscribe --filteraccepted malformed values, printed "Invalid pair:",and continued — then wrote func.yaml anyway and exited 0. A user who typos a
filter in a script gets a silent misconfiguration: the function subscribes more
broadly than intended, and it only surfaces much later.
Separately,
strings.Splitwas used whereSplitNis needed, so legitimatefilter values containing "=" (e.g.
foo=bar=baz) were also discarded.What changed
strings.SplitN(filter, "=", 2)so filter values containing "=" are preservedextractFilterMapreturns an error for a missing "=" or an empty keyupdateOrAddSubscriptiontorunSubscribe, so thecommand fails before
f.Write()rather than afterTesting
TestExtractFilterMap— table-driven, 8 cases: valid filters, values containing"=", empty values, missing "=", and empty keys
TestSubscribeRejectsMalformedFilter— assertscmd.Execute()returns an errorand that func.yaml is left untouched
TestSubscribeAllowsFilterValueContainingEquals— assertsfoo=bar=bazround-tripsmake testandmake checkpass locally (Go 1.26.7, Linux)