Fix POST /queries returning 500 on JSON null name/query (#43031) - #45253
juan-fdz-hawa merged 1 commit into
Conversation
Fixes #43031 Make sure we reject nil Name or Query in NewQuery with a BadRequestError before Verify().
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
WalkthroughThis PR fixes an issue where 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/service/queries_test.go (1)
143-165: ⚡ Quick winAssert the specific bad-request error for nil required fields.
These new cases currently only assert “any error.” Tightening to
BadRequestError+ message will better lock the regression fix.Proposed test hardening
testCases := []struct { name string queryPayload fleet.QueryPayload shouldErr bool + errContains string }{ @@ { "Nil name", fleet.QueryPayload{ Query: ptr.String("select 1"), Logging: ptr.String("snapshot"), }, true, + "name and query fields are required", }, { "Nil query", fleet.QueryPayload{ Name: ptr.String("test query"), Logging: ptr.String("snapshot"), }, true, + "name and query fields are required", }, { "Nil name and query", fleet.QueryPayload{ Logging: ptr.String("snapshot"), }, true, + "name and query fields are required", }, } @@ if tt.shouldErr { assert.Error(t, err) assert.Nil(t, query) + if tt.errContains != "" { + assert.ErrorContains(t, err, tt.errContains) + } } else {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@server/service/queries_test.go` around lines 143 - 165, Update the table-driven tests in queries_test.go for the cases "Nil name", "Nil query", and "Nil name and query" to assert the exact bad-request type and message instead of any error: when invoking the handler/validator with fleet.QueryPayload missing Name or Query, assert the returned error is a BadRequestError (use the project's BadRequestError type/constructor) and that its error string contains the expected validation message (e.g., "name is required" for the Nil name case, "query is required" for the Nil query case, and an appropriate combined message for Nil name and query); locate the checks around the failing test cases in queries_test.go and replace the generic any-error assertions with these specific type-and-message assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@server/service/queries_test.go`:
- Around line 143-165: Update the table-driven tests in queries_test.go for the
cases "Nil name", "Nil query", and "Nil name and query" to assert the exact
bad-request type and message instead of any error: when invoking the
handler/validator with fleet.QueryPayload missing Name or Query, assert the
returned error is a BadRequestError (use the project's BadRequestError
type/constructor) and that its error string contains the expected validation
message (e.g., "name is required" for the Nil name case, "query is required" for
the Nil query case, and an appropriate combined message for Nil name and query);
locate the checks around the failing test cases in queries_test.go and replace
the generic any-error assertions with these specific type-and-message
assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0a481f83-8e26-44ee-8f2b-692a7f80adec
📒 Files selected for processing (4)
changes/43031-post-queries-null-name-or-query-500server/service/integration_core_test.goserver/service/queries.goserver/service/queries_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45253 +/- ##
==========================================
+ Coverage 66.81% 66.86% +0.05%
==========================================
Files 2724 2724
Lines 219027 219087 +60
Branches 10754 10754
==========================================
+ Hits 146342 146499 +157
+ Misses 59519 59423 -96
+ Partials 13166 13165 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Failures unrelated to changes |
Related issue: Fixes #43031
Make sure we reject nil Name or Query in NewQuery with a BadRequestError before Verify().
Checklist for submitter
If some of the following don't apply, delete the relevant line.
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Testing
Summary by CodeRabbit
Bug Fixes
Tests