fix(websub): handle empty channels map in mapWebSubAPIModelToAPI#2009
fix(websub): handle empty channels map in mapWebSubAPIModelToAPI#2009SAY-5 wants to merge 1 commit into
Conversation
Fixes wso2#1995 mapWebSubChannelsModelToAPI returned a nil *map for empty/nil input and the caller in mapWebSubAPIModelToAPI then dereferenced that nil pointer when assigning to api.WebSubAPI.Channels (a value-type map). Any Get, List, or Update return path panicked for a WebSub API stored with an empty channels map. Return the value-type map directly so the result is always usable, and drop the now-unneeded pointer indirection at the call site.
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummaryThis PR fixes a runtime panic that occurred during Get, List, and Update operations on WebSub APIs that were stored with empty or nil channel maps. Root CauseThe mapping helper Changes Madeplatform-api/src/internal/service/websub_api.go:
platform-api/src/internal/service/websub_api_test.go:
Impact
WalkthroughThis pull request fixes a nil-pointer dereference in the WebSub API channel mapping layer. The Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Purpose
Resolves #1995.
mapWebSubChannelsModelToAPIreturned a nil*mapfor empty or nil input, and the caller inmapWebSubAPIModelToAPIthen dereferenced that nil pointer when assigning toapi.WebSubAPI.Channels(a value-type map). AnyGet,List, orUpdatereturn path panicked for a WebSub API stored with an empty channels map. The bug was originally noted in #1992 (review comment).Goals
Make the conversion safe for empty/nil channel inputs and have it always produce a usable (non-nil) map suitable for direct assignment to the value-type
Channelsfield.Approach
mapWebSubChannelsModelToAPInow returnsmap[string]api.WebSubChanneldirectly instead of*map[string]api.WebSubChannel. For empty/nil input it returns an empty (non-nil) map. The call site inmapWebSubAPIModelToAPIdrops the*indirection.User stories
N/A (defect fix).
Documentation
N/A — internal helper behavior, no user-facing API change.
Automation tests
TestWebSubAPI_MapModelToAPI_EmptyChannelsDoesNotPanicexercisesmapWebSubAPIModelToAPIwith a nil channel map and an empty channel map, asserting it does not panic and that the resultingChannelsmap is non-nil and empty. On main both subtests fail with "runtime error: invalid memory address or nil pointer dereference"; with this fix they pass.TestWebSubAPI_MapChannelsModelToAPI_NeverReturnsNilpins the helper contract that nil and empty inputs both yield a non-nil map.TestWebSubAPI_*tests inplatform-api/src/internal/service/websub_api_test.gocontinue to pass.Security checks
Samples
N/A.
Related PRs
Test environment
platform-api-pr-check.yml), macOS arm64 locally.