Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #278 +/- ##
=======================================
Coverage 98.27% 98.27%
=======================================
Files 80 80
Lines 9481 9507 +26
=======================================
+ Hits 9317 9343 +26
Misses 139 139
Partials 25 25
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
two lines missing coverage... you can do it :) |
Fixed in d002a64. The guards now emit a |
|
Coverage is a big drop-off; need to bring it up! The libs are something I am anal about coverage on. |
|
@daveshanley Coverage improved in 069d2e1:
The remaining uncovered lines are the bodies of guards 2 and 3 ( |
|
Thanks for sticking with this, the fix now returns an error correctly and the full test suite passes at
Thanks again — a small cleanup and we should be in good shape :) |
Replace bare type assertion with comma-ok pattern to prevent panic when query parameter object key is absent or value is not a map.
The nil/type guards prevented the panic but also silently accepted requests where a content-wrapped object parameter could not be decoded into a map. Now each guard emits a QueryParameterCannotBeDecoded validation error before breaking, so the request correctly fails validation instead of passing silently. Add QueryParameterCannotBeDecoded error constructor (modeled after HeaderParameterCannotBeDecoded) and update the test to assert on the returned error. Add a positive test for valid JSON object parameters. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
… paths Add unit test for QueryParameterCannotBeDecoded error constructor in errors/ package (21 lines, 0% -> 100% per-package coverage). Add integration tests for query parameter object validation: - JSON content-wrapped with invalid property type (schema error path) - Form-encoded valid and invalid objects (non-content-wrapped path) - XML content type (second encodedObj==nil guard path) These bring patch coverage from 19% to ~78% and restore the errors/ package from 98.0% to 98.9%. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
A nil map read is safe, so a missing key and a non-map value are the same failure as a nil decoded object. Keep one checked type assertion and one QueryParameterCannotBeDecoded path. Document QueryParameterCannotBeDecoded. The valid JSON and form cases, plus the invalid schema and unsupported content cases, still cover the changed lines. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
069d2e1 to
ebf97b2
Compare
Done. The decode check is one type assertion. A nil map read is safe, and a missing key or a non-map value takes the same The valid JSON and form cases are still there, and so are the invalid schema and unsupported content cases. Locally, |
Problem
In
parameters/query_parameters.go, thehelpers.Objectcase uses a bare type assertion:This panics when:
encodedObjis nil (e.g. content-wrapped parameter with a non-JSON media type skips map initialization)params[p].Nameis absent fromencodedObj(map lookup returns nil, bare assertion on nil panics)map[string]interface{}Fix
Replace the bare type assertion with a three-step comma-ok pattern:
This follows the existing control flow: when the value cannot be decoded, we
break skipValues(the same pattern used for JSON unmarshal failures a few lines above).Test
Added
TestQueryParamObjectMissingKey_NoPanicwhich declares an object query parameter with atext/plaincontent wrapper. This forces thecontentWrappedpath without JSON decoding, leavingencodedObjnil. Before the fix, this test panics. After the fix, it completes without error.